From 3a489c21f8284f712c0339710dd8f88e2b14e2ba Mon Sep 17 00:00:00 2001 From: Abbas Gheydi Date: Sat, 7 Sep 2024 21:44:18 +0330 Subject: [PATCH] fix lint --- .golangci.yml | 2 +- internal/controller/service/controller.go | 2 ++ internal/controller/service/helpers.go | 9 +++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index f378bfe..a1caa82 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -22,7 +22,7 @@ linters: - nilerr - nlreturn - nolintlint - - nonamedreturns + #- nonamedreturns - prealloc - predeclared - reassign diff --git a/internal/controller/service/controller.go b/internal/controller/service/controller.go index 19e0b07..5557e0b 100644 --- a/internal/controller/service/controller.go +++ b/internal/controller/service/controller.go @@ -194,6 +194,7 @@ func (re *ReconcilerExtended) updateCNP(ctx context.Context) (*ctrl.Result, erro desiredCNP, err := re.buildCNP() if err != nil { re.logger.Info("failed to build cnp", "buildCNP", err) + return &ctrl.Result{}, nil } @@ -232,6 +233,7 @@ func (re *ReconcilerExtended) createCNP(ctx context.Context) (*ctrl.Result, erro desiredCNP, err := re.buildCNP() if err != nil { re.logger.Info("failed to build cnp", "buildCNP", err) + return &ctrl.Result{}, nil } diff --git a/internal/controller/service/helpers.go b/internal/controller/service/helpers.go index 582e416..db59055 100644 --- a/internal/controller/service/helpers.go +++ b/internal/controller/service/helpers.go @@ -59,7 +59,6 @@ func init() { // buildCNP builds and returns a CiliumNetworkPolicyand error based on the Service object. func (re *ReconcilerExtended) buildCNP() (cnp *ciliumv2.CiliumNetworkPolicy, err error) { - fromEntities := cilium_policy_api.EntitySlice{ cilium_policy_api.EntityCluster, cilium_policy_api.EntityWorld, @@ -67,7 +66,6 @@ func (re *ReconcilerExtended) buildCNP() (cnp *ciliumv2.CiliumNetworkPolicy, err endpointSelector, err := getEndponitSelector(re.service.Spec.Selector) if err == nil { - cnp = &ciliumv2.CiliumNetworkPolicy{ ObjectMeta: metav1.ObjectMeta{ Name: re.service.Name, @@ -91,18 +89,21 @@ func (re *ReconcilerExtended) buildCNP() (cnp *ciliumv2.CiliumNetworkPolicy, err return cnp, err } -// getEndponitSelector is used to filter and extract cilium endpoint selector from service labels +// getEndponitSelector is used to filter and extract cilium endpoint selector from service labels. +// +//nolint:wsl func getEndponitSelector(serviceSlector map[string]string) (ciliumEndPointSelector cilium_policy_api.EndpointSelector, err error) { - identityLabels, informationLabels := cilium_labelsfilter.Filter(cilium_labels.Map2Labels(serviceSlector, cilium_labels.LabelSourceK8s)) if len(informationLabels.K8sStringMap()) != 0 { log.Log.Info("excluded_labels", "information labels", informationLabels.String()) } + identityLabelSelector := cilium_slim_metav1.LabelSelector{MatchLabels: identityLabels.K8sStringMap()} ciliumEndPointSelector = cilium_policy_api.NewESFromK8sLabelSelector(cilium_labels.LabelSourceK8sKeyPrefix, &identityLabelSelector) if len(ciliumEndPointSelector.MatchLabels) == 0 { err = errors.New("endpointSelector is empty") } + return ciliumEndPointSelector, err }