constellation/operators/constellation-node-operator/internal/patch/labels.go
Thomas Tendyck bd63aa3c6b add license headers
sed -i '1i/*\nCopyright (c) Edgeless Systems GmbH\n\nSPDX-License-Identifier: AGPL-3.0-only\n*/\n' `grep -rL --include='*.go' 'DO NOT EDIT'`
gofumpt -w .
2022-09-05 09:17:25 +02:00

25 lines
655 B
Go

/*
Copyright (c) Edgeless Systems GmbH
SPDX-License-Identifier: AGPL-3.0-only
*/
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{})
}