Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
abbas-gheydi committed Sep 7, 2024
1 parent e0284d2 commit 3a489c2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ linters:
- nilerr
- nlreturn
- nolintlint
- nonamedreturns
#- nonamedreturns
- prealloc
- predeclared
- reassign
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
9 changes: 5 additions & 4 deletions internal/controller/service/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ 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,
}

endpointSelector, err := getEndponitSelector(re.service.Spec.Selector)
if err == nil {

cnp = &ciliumv2.CiliumNetworkPolicy{
ObjectMeta: metav1.ObjectMeta{
Name: re.service.Name,
Expand All @@ -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
}

Expand Down

0 comments on commit 3a489c2

Please sign in to comment.