mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 16:06:56 +00:00
* add source labels to targets Signed-off-by: ShutingZhao <shuting@nirmata.com> * handle multiple triggers/targets for the same clone source Signed-off-by: ShutingZhao <shuting@nirmata.com> * add source labels to targets Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix test Signed-off-by: ShutingZhao <shuting@nirmata.com> * remove unused code Signed-off-by: ShutingZhao <shuting@nirmata.com> * add kuttl tests Signed-off-by: ShutingZhao <shuting@nirmata.com> * rename the test Signed-off-by: ShutingZhao <shuting@nirmata.com> * add kuttl tests Signed-off-by: ShutingZhao <shuting@nirmata.com> * add kuttl tests Signed-off-by: ShutingZhao <shuting@nirmata.com> * split apiversion label into version and group Signed-off-by: ShutingZhao <shuting@nirmata.com> --------- Signed-off-by: ShutingZhao <shuting@nirmata.com>
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
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"
|
|
)
|
|
|
|
func updateSourceLabel(client dclient.Interface, source *unstructured.Unstructured) error {
|
|
labels := source.GetLabels()
|
|
if labels == nil {
|
|
labels = make(map[string]string)
|
|
}
|
|
|
|
common.TagSource(labels, source)
|
|
source.SetLabels(labels)
|
|
_, err := client.UpdateResource(context.TODO(), source.GetAPIVersion(), source.GetKind(), source.GetNamespace(), source, false)
|
|
return err
|
|
}
|
|
|
|
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)
|
|
}
|