From e67747260b00711aabb2d187af47a8a57a14b279 Mon Sep 17 00:00:00 2001 From: NoSkillGirl Date: Mon, 4 Jan 2021 15:19:06 +0530 Subject: [PATCH] generate refactorings --- pkg/backward_compatibility/add_labels.go | 5 ++--- pkg/policy/validate_controller.go | 5 +---- pkg/webhooks/generate/generate.go | 2 +- pkg/webhooks/generation.go | 2 -- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/pkg/backward_compatibility/add_labels.go b/pkg/backward_compatibility/add_labels.go index 6408a6452b..04d9dc0286 100644 --- a/pkg/backward_compatibility/add_labels.go +++ b/pkg/backward_compatibility/add_labels.go @@ -28,7 +28,7 @@ func AddLabels(client *kyvernoclient.Clientset, grInformer kyvernoinformer.Gener for _, gr := range grList { grLabels := gr.Labels - if grLabels == nil || len(grLabels) == 0 { + if len(grLabels) == 0 { grLabels = make(map[string]string) } grLabels["generate.kyverno.io/policy-name"] = gr.Spec.Policy @@ -53,7 +53,6 @@ func AddLabels(client *kyvernoclient.Clientset, grInformer kyvernoinformer.Gener } } } - return } func addLabelForGR(name string, namespace string, client *kyvernoclient.Clientset, grInformer kyvernoinformer.GenerateRequestInformer) error { @@ -64,7 +63,7 @@ func addLabelForGR(name string, namespace string, client *kyvernoclient.Clientse } grLabels := gr.Labels - if grLabels == nil || len(grLabels) == 0 { + if len(grLabels) == 0 { grLabels = make(map[string]string) } grLabels["generate.kyverno.io/policy-name"] = gr.Spec.Policy diff --git a/pkg/policy/validate_controller.go b/pkg/policy/validate_controller.go index a3d3a3ab4b..9268d43760 100644 --- a/pkg/policy/validate_controller.go +++ b/pkg/policy/validate_controller.go @@ -440,13 +440,10 @@ func updateGR(kyvernoClient *kyvernoclient.Clientset, policyKey string, grList [ for _, gr := range grList { if policyKey == gr.Spec.Policy { grLabels := gr.Labels - if grLabels == nil || len(grLabels) == 0 { + if len(grLabels) == 0 { grLabels = make(map[string]string) } grLabels["policy-update"] = fmt.Sprintf("revision-count-%d", rand.Intn(100000)) - // gr.SetLabels(map[string]string{ - // "policy-update": fmt.Sprintf("revision-count-%d", rand.Intn(100000)), - // }) gr.SetLabels(grLabels) _, err := kyvernoClient.KyvernoV1().GenerateRequests(config.KyvernoNamespace).Update(context.TODO(), gr, metav1.UpdateOptions{}) if err != nil { diff --git a/pkg/webhooks/generate/generate.go b/pkg/webhooks/generate/generate.go index 031bffb01b..6264793568 100644 --- a/pkg/webhooks/generate/generate.go +++ b/pkg/webhooks/generate/generate.go @@ -155,7 +155,7 @@ func retryApplyResource(client *kyvernoclient.Clientset, grSpec kyverno.Generate for _, v := range grList { grLabels := gr.Labels - if grLabels == nil || len(grLabels) == 0 { + if len(grLabels) == 0 { grLabels = make(map[string]string) } grLabels["resources-update"] = "true" diff --git a/pkg/webhooks/generation.go b/pkg/webhooks/generation.go index 951aac9a9f..b1655d8a0a 100644 --- a/pkg/webhooks/generation.go +++ b/pkg/webhooks/generation.go @@ -86,8 +86,6 @@ func (ws *WebhookServer) HandleGenerate(request *v1beta1.AdmissionRequest, polic if request.Operation == v1beta1.Update { ws.handleUpdate(request) } - - return } //HandleUpdate handles admission-requests for update