1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-09 09:26:54 +00:00
kyverno/pkg/utils/controller/metadata.go
Charles-Edouard Brétéché d256735399
feat: add controller utils tools (#4639)
Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
2022-09-18 10:12:29 +01:00

34 lines
772 B
Go

package controller
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
func SetLabel(obj metav1.Object, key, value string) map[string]string {
labels := obj.GetLabels()
if labels == nil {
labels = map[string]string{}
}
labels[key] = value
obj.SetLabels(labels)
return labels
}
func SetAnnotation(obj metav1.Object, key, value string) {
annotations := obj.GetAnnotations()
if annotations == nil {
annotations = map[string]string{}
}
annotations[key] = value
obj.SetAnnotations(annotations)
}
func SetOwner(obj metav1.Object, apiVersion, kind, name string, uid types.UID) {
obj.SetOwnerReferences([]metav1.OwnerReference{{
APIVersion: apiVersion,
Kind: kind,
Name: name,
UID: uid,
}})
}