2023-02-22 18:49:09 +08:00
|
|
|
package generate
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/kyverno/kyverno/pkg/background/common"
|
|
|
|
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
|
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
|
|
)
|
|
|
|
|
2023-06-07 21:50:47 +08:00
|
|
|
func updateSourceLabel(client dclient.Interface, source *unstructured.Unstructured) error {
|
2023-02-22 18:49:09 +08:00
|
|
|
labels := source.GetLabels()
|
|
|
|
if labels == nil {
|
|
|
|
labels = make(map[string]string)
|
|
|
|
}
|
|
|
|
|
2023-06-07 21:50:47 +08:00
|
|
|
common.TagSource(labels, source)
|
2023-02-22 18:49:09 +08:00
|
|
|
source.SetLabels(labels)
|
|
|
|
_, err := client.UpdateResource(context.TODO(), source.GetAPIVersion(), source.GetKind(), source.GetNamespace(), source, false)
|
|
|
|
return err
|
|
|
|
}
|
2023-06-07 21:50:47 +08:00
|
|
|
|
|
|
|
func addSourceLabels(source *unstructured.Unstructured) {
|
|
|
|
labels := source.GetLabels()
|
|
|
|
if labels == nil {
|
|
|
|
labels = make(map[string]string, 4)
|
|
|
|
}
|
|
|
|
|
|
|
|
labels[common.GenerateSourceGroupLabel] = source.GroupVersionKind().Group
|
|
|
|
labels[common.GenerateSourceVersionLabel] = source.GroupVersionKind().Version
|
|
|
|
labels[common.GenerateSourceKindLabel] = source.GetKind()
|
|
|
|
labels[common.GenerateSourceNSLabel] = source.GetNamespace()
|
|
|
|
labels[common.GenerateSourceNameLabel] = source.GetName()
|
|
|
|
source.SetLabels(labels)
|
|
|
|
}
|