From dfaeaa7f8e50879860be2d809bf52da2df5bbf50 Mon Sep 17 00:00:00 2001 From: NoSkillGirl Date: Tue, 29 Dec 2020 16:35:48 +0530 Subject: [PATCH] add lables update fix --- cmd/kyverno/main.go | 2 +- .../backward_compatibility/add_labels.go | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cmd/kyverno/main.go b/cmd/kyverno/main.go index 697d72cb10..9f3b9389bc 100755 --- a/cmd/kyverno/main.go +++ b/cmd/kyverno/main.go @@ -15,7 +15,7 @@ import ( dclient "github.com/kyverno/kyverno/pkg/dclient" event "github.com/kyverno/kyverno/pkg/event" "github.com/kyverno/kyverno/pkg/generate" - backwardcompatibility "github.com/kyverno/kyverno/pkg/generate/backwardCompatibility" + backwardcompatibility "github.com/kyverno/kyverno/pkg/generate/backward_compatibility" generatecleanup "github.com/kyverno/kyverno/pkg/generate/cleanup" "github.com/kyverno/kyverno/pkg/openapi" "github.com/kyverno/kyverno/pkg/policy" diff --git a/pkg/generate/backward_compatibility/add_labels.go b/pkg/generate/backward_compatibility/add_labels.go index 6f0ba16397..08a1b1535f 100644 --- a/pkg/generate/backward_compatibility/add_labels.go +++ b/pkg/generate/backward_compatibility/add_labels.go @@ -23,12 +23,17 @@ func AddLabels(client *kyvernoclient.Clientset, grInformer kyvernoinformer.Gener } for _, gr := range grList { - gr.SetLabels(map[string]string{ - "generate.kyverno.io/policy-name": gr.Spec.Policy, - "generate.kyverno.io/resource-name": gr.Spec.Resource.Name, - "generate.kyverno.io/resource-kind": gr.Spec.Resource.Kind, - "generate.kyverno.io/resource-namespace": gr.Spec.Resource.Namespace, - }) + + grLabels := gr.Labels + if grLabels == nil || len(grLabels) == 0 { + grLabels = make(map[string]string) + } + grLabels["generate.kyverno.io/policy-name"] = gr.Spec.Policy + grLabels["generate.kyverno.io/resource-name"] = gr.Spec.Resource.Name + grLabels["generate.kyverno.io/resource-kind"] = gr.Spec.Resource.Kind + grLabels["generate.kyverno.io/resource-namespace"] = gr.Spec.Resource.Namespace + + gr.SetLabels(grLabels) _, err = client.KyvernoV1().GenerateRequests(config.KyvernoNamespace).Update(context.TODO(), gr, metav1.UpdateOptions{}) if err != nil {