Skip to content

Commit

Permalink
ci: update linter and fix lint violations
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <[email protected]>
  • Loading branch information
sagikazarmark committed Apr 14, 2023
1 parent e9ee651 commit 57481e6
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 87 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ jobs:
name: Checks
runs-on: ubuntu-latest

env:
GOLANGCI_LINT_VERSION: 1.26.0

steps:
- name: Checkout repository
uses: actions/checkout@83b7061638ee4956cf7545a6f7efe594e5ad0247 # v3.5.1
Expand Down Expand Up @@ -55,7 +52,7 @@ jobs:
run: go mod vendor && make license-check

- name: Run lint
run: GOLANGCI_VERSION=${{ env.GOLANGCI_LINT_VERSION }} make lint
run: make lint

build:
name: Build
Expand Down
18 changes: 16 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,28 @@ linters:
- nestif
- testpackage
- nolintlint
- wrapcheck
- varnamelen
- ireturn
- exhaustivestruct
- exhaustruct
- gomoddirectives
- exhaustive
- cyclop
- ifshort

linters-settings:
golint:
min-confidence: 0.1
gocyclo:
min-complexity: 40
goimports:
local-prefixes: github.com/banzaicloud
gci:
sections:
- standard
- default
- prefix(github.com/banzaicloud/imps)
goimports:
local-prefixes: github.com/banzaicloud/imps
gocritic:
disabled-checks:
- ifElseChain
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CRD_OPTIONS ?= "crd"
# TODO: Use this when allowDangerousTypes feature is released to support floats
# CRD_OPTIONS ?= "crd:trivialVersions=true,allowDangerousTypes=true"
LICENSEI_VERSION = 0.7.0
GOLANGCI_VERSION ?= 1.45.2
GOLANGCI_VERSION ?= 1.52.2

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down
18 changes: 5 additions & 13 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,19 @@ import (
"strings"
"time"

"github.com/banzaicloud/imps/api/v1alpha1"
"github.com/banzaicloud/imps/controllers"
"github.com/banzaicloud/imps/internal/errorhandler"
"github.com/banzaicloud/imps/internal/log"
"github.com/banzaicloud/imps/pkg/ecr"

"github.com/banzaicloud/operator-tools/pkg/reconciler"

logrintegration "logur.dev/integration/logr"

"github.com/banzaicloud/imps/internal/errorhandler"

"github.com/spf13/pflag"
"github.com/spf13/viper"
"k8s.io/apimachinery/pkg/runtime"

"github.com/banzaicloud/imps/controllers"
"github.com/banzaicloud/imps/internal/log"

clientgoscheme "k8s.io/client-go/kubernetes/scheme"
logrintegration "logur.dev/integration/logr"
"logur.dev/logur"
ctrl "sigs.k8s.io/controller-runtime"

"github.com/banzaicloud/imps/api/v1alpha1"
// +kubebuilder:scaffold:imports
)

var (
Expand Down
11 changes: 5 additions & 6 deletions cmd/refresher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import (
"time"

"emperror.dev/errors"
"github.com/banzaicloud/imps/controllers"
"github.com/banzaicloud/imps/internal/errorhandler"
"github.com/banzaicloud/imps/internal/log"
"github.com/banzaicloud/imps/pkg/ecr"
"github.com/banzaicloud/operator-tools/pkg/reconciler"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -15,12 +20,6 @@ import (
logrintegration "logur.dev/integration/logr"
"logur.dev/logur"
ctrl "sigs.k8s.io/controller-runtime"

"github.com/banzaicloud/imps/controllers"
"github.com/banzaicloud/imps/internal/errorhandler"
"github.com/banzaicloud/imps/internal/log"
"github.com/banzaicloud/imps/pkg/ecr"
"github.com/banzaicloud/operator-tools/pkg/reconciler"
)

var (
Expand Down
25 changes: 17 additions & 8 deletions controllers/imagepullsecret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,20 @@ import (
"time"

"emperror.dev/emperror"
"logur.dev/logur"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/banzaicloud/imps/api/v1alpha1"
"github.com/banzaicloud/imps/internal/cron"
"github.com/banzaicloud/operator-tools/pkg/reconciler"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"logur.dev/logur"
ctrl "sigs.k8s.io/controller-runtime"
ctrlBuilder "sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/banzaicloud/imps/api/v1alpha1"
"github.com/banzaicloud/imps/internal/cron"
"github.com/banzaicloud/operator-tools/pkg/reconciler"
)

// AlertingPolicyReconciler reconciles a AlertingPolicy object
Expand All @@ -58,6 +56,7 @@ func (r *ImagePullSecretReconciler) Reconcile(ctx context.Context, req ctrl.Requ
if err != nil {
r.ErrorHandler.Handle(err)
}

return result, err
}

Expand Down Expand Up @@ -87,6 +86,7 @@ func (r *ImagePullSecretReconciler) impsMatchingNamespace(obj client.Object) []c
ns, ok := obj.(*corev1.Namespace)
if !ok {
r.Log.Info("object is not a Namespace")

return []ctrl.Request{}
}

Expand All @@ -95,6 +95,7 @@ func (r *ImagePullSecretReconciler) impsMatchingNamespace(obj client.Object) []c
err := r.Client.List(context.TODO(), impsList)
if err != nil {
r.Log.Info(err.Error())

return []ctrl.Request{}
}

Expand All @@ -107,6 +108,7 @@ func (r *ImagePullSecretReconciler) impsMatchingNamespace(obj client.Object) []c
"namespace": ns,
"error": err,
})

continue
}

Expand All @@ -119,13 +121,15 @@ func (r *ImagePullSecretReconciler) impsMatchingNamespace(obj client.Object) []c
})
}
}

return res
}

func (r *ImagePullSecretReconciler) impsMatchingPod(obj client.Object) []ctrl.Request {
pod, ok := obj.(*corev1.Pod)
if !ok {
r.Log.Info("object is not a Pod or Namespace")

return []ctrl.Request{}
}

Expand All @@ -135,7 +139,6 @@ func (r *ImagePullSecretReconciler) impsMatchingPod(obj client.Object) []ctrl.Re
err := r.Client.Get(context.TODO(), types.NamespacedName{
Name: pod.Namespace,
}, podsNamespace)

if err != nil {
r.Log.Warn("cannot get pod's namespace, please authorize the controller to list namespaces, or too many reconcilations will be executed", map[string]interface{}{
"error": err,
Expand All @@ -149,6 +152,7 @@ func (r *ImagePullSecretReconciler) impsMatchingPod(obj client.Object) []ctrl.Re
err = r.Client.List(context.TODO(), impsList)
if err != nil {
r.Log.Info(err.Error())

return []ctrl.Request{}
}
var res []ctrl.Request
Expand All @@ -160,6 +164,7 @@ func (r *ImagePullSecretReconciler) impsMatchingPod(obj client.Object) []ctrl.Re
"pod": pod,
"error": err,
})

continue
}

Expand All @@ -184,13 +189,15 @@ func (r *ImagePullSecretReconciler) impsMatchingPod(obj client.Object) []ctrl.Re
})
}
}

return res
}

func (r *ImagePullSecretReconciler) impsReferencingSecret(obj client.Object) []ctrl.Request {
secret, ok := obj.(*corev1.Secret)
if !ok {
r.Log.Info("object is not a Secret")

return []ctrl.Request{}
}

Expand All @@ -199,6 +206,7 @@ func (r *ImagePullSecretReconciler) impsReferencingSecret(obj client.Object) []c
err := r.Client.List(context.TODO(), impsList)
if err != nil {
r.Log.Info(err.Error())

return []ctrl.Request{}
}

Expand All @@ -215,5 +223,6 @@ func (r *ImagePullSecretReconciler) impsReferencingSecret(obj client.Object) []c
}
}
}

return res
}
29 changes: 16 additions & 13 deletions controllers/imagepullsecret_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,22 @@ import (
"fmt"
"time"

"github.com/banzaicloud/imps/pkg/pullsecrets"

"emperror.dev/errors"
"github.com/banzaicloud/imps/api/v1alpha1"
"github.com/banzaicloud/imps/pkg/pullsecrets"
"github.com/banzaicloud/operator-tools/pkg/reconciler"
corev1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/banzaicloud/imps/api/v1alpha1"
"github.com/banzaicloud/operator-tools/pkg/reconciler"

"logur.dev/logur"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var (
requeueObject = ctrl.Result{
Requeue: true,
RequeueAfter: 5 * time.Second,
}
)
var requeueObject = ctrl.Result{
Requeue: true,
RequeueAfter: 5 * time.Second,
}

func (r *ImagePullSecretReconciler) setFailedStatus(ctx context.Context, imps *v1alpha1.ImagePullSecret, failureError error) {
imps.Status.Status = v1alpha1.ReconciliationFailed
Expand Down Expand Up @@ -121,6 +116,7 @@ func (r *ImagePullSecretReconciler) reconcile(ctx context.Context, req ctrl.Requ
r.setReadyStatus(ctx, &imps, targetNamespaces, resultingConfig.Expiration)
}
logger.Info("Reconciling ImagePullSecret finished")

return result, err
}

Expand All @@ -132,6 +128,7 @@ func (r *ImagePullSecretReconciler) reconcileImagePullSecret(ctx context.Context
"imps": imps,
})
r.Recorder.Event(imps, "Warning", "SecretReconciliationError", fmt.Sprintf("Cannot list namespaces requiring the secret: %s", err.Error()))

return requeueObject, nil, err
}

Expand All @@ -150,6 +147,7 @@ func (r *ImagePullSecretReconciler) reconcileImagePullSecret(ctx context.Context
})
r.Recorder.Event(imps, "Warning", "SecretReconciliationError", fmt.Sprintf("Cannot reconcile secret: %s/%s", namespaceName, imps.Spec.Target.Secret.Name))
wasError = true

continue
}
r.Log.Info("reconciled secret", map[string]interface{}{
Expand All @@ -172,6 +170,7 @@ func (r *ImagePullSecretReconciler) reconcileImagePullSecret(ctx context.Context
"imps": imps,
})
r.Recorder.Event(imps, "Warning", "SecretReconciliationError", fmt.Sprintf("Cannot enumerate secrets: %s", err.Error()))

return requeueObject, nil, err
}

Expand Down Expand Up @@ -203,6 +202,7 @@ func (r *ImagePullSecretReconciler) reconcileImagePullSecret(ctx context.Context
"secret": existingSecret,
})
r.Recorder.Event(imps, "Warning", "SecretDeletionError", fmt.Sprintf("Cannot remove secret %s/%s", existingSecret.Namespace, existingSecret.Name))

return requeueObject, nil, err
}
}
Expand Down Expand Up @@ -237,6 +237,7 @@ func (r *ImagePullSecretReconciler) namespacesRequiringSecret(ctx context.Contex
"error": err,
"imps": imps,
})

continue
}
if shouldReconcile {
Expand Down Expand Up @@ -267,13 +268,15 @@ func (r *ImagePullSecretReconciler) anyPodMatchesSelectorInNS(ctx context.Contex
"pod": pod,
"imps": imps,
})

continue
}

if matches {
return true, nil
}
}

return false, nil
}

Expand Down
Loading

0 comments on commit 57481e6

Please sign in to comment.