mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
3932581f2a
Signed-off-by: Malte Poll <mp@edgeless.systems>
19 lines
572 B
Go
19 lines
572 B
Go
package patch
|
|
|
|
import (
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
)
|
|
|
|
// SetLabels creates a patch for a client.Object by merging labels with existing labels.
|
|
func SetLabels(original, patched client.Object, labels map[string]string) client.Patch {
|
|
mergedLabels := patched.GetLabels()
|
|
if mergedLabels == nil {
|
|
mergedLabels = make(map[string]string, len(labels))
|
|
}
|
|
for labelKey, labelValue := range labels {
|
|
mergedLabels[labelKey] = labelValue
|
|
}
|
|
patched.SetLabels(mergedLabels)
|
|
return client.StrategicMergeFrom(original, client.MergeFromWithOptimisticLock{})
|
|
}
|