From b6e8f5ac505752b5f4ea4cbad97247f6df494476 Mon Sep 17 00:00:00 2001 From: Max Neverov <1296281+mneverov@users.noreply.github.com> Date: Sun, 21 Apr 2024 08:06:19 +0200 Subject: [PATCH] Add nilaway linter. (#184) Closes #174. Without specifying packages the linter consume all memory when trying to parse `site` and other directories. I excluded `cmd` package because the linter complained on using [mgr](https://github.com/aenix-io/etcd-operator/blob/main/cmd/main.go#L126) even if it cannot be nil since the error that is returned from the manager constructer is checked. Co-authored-by: Oleg Kunitsyn <114359669+hiddenmarten@users.noreply.github.com> --- .pre-commit-config.yaml | 5 +++++ Makefile | 9 +++++++++ internal/controller/etcdcluster_controller.go | 4 +++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b629d9fe..af9d055e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,6 +24,11 @@ repos: entry: sh -c "make lint-fix" language: system require_serial: true + - id: make-nilaway-lint + name: make-nilaway-lint + entry: sh -c "make nilaway-lint" + language: system + require_serial: true - id: make-helm-lint name: make-helm-lint entry: sh -c "make helm-lint" diff --git a/Makefile b/Makefile index 9e2aeaad..2ff7d420 100644 --- a/Makefile +++ b/Makefile @@ -80,6 +80,10 @@ lint: golangci-lint ## Run golangci-lint linter & yamllint lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes $(GOLANGCI_LINT) run --fix +.PHONY: nilaway-lint +nilaway-lint: nilaway + $(NILAWAY_LINT) -include-pkgs=github.com/aenix-io/etcd-operator/api,github.com/aenix-io/etcd-operator/internal,github.com/aenix-io/etcd-operator/test ./... + .PHONY: helm-lint helm-lint: helm ## Run helm lint over chart $(HELM) lint charts/etcd-operator @@ -221,6 +225,7 @@ KUSTOMIZE ?= $(LOCALBIN)/kustomize CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint +NILAWAY_LINT ?= $(LOCALBIN)/nilaway KIND ?= $(LOCALBIN)/kind HELM ?= $(LOCALBIN)/helm HELM_DOCS ?= $(LOCALBIN)/helm-docs @@ -270,6 +275,10 @@ golangci-lint: $(LOCALBIN) @test -x $(GOLANGCI_LINT) && $(GOLANGCI_LINT) version | grep -q $(GOLANGCI_LINT_VERSION) || \ GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) +.PHONY: nilaway +nilaway: $(LOCALBIN) + @test -x $(NILAWAY_LINT) || GOBIN=$(LOCALBIN) go install go.uber.org/nilaway/cmd/nilaway@latest + kind: $(LOCALBIN) @test -x $(KIND) && $(KIND) version | grep -q $(KIND_VERSION) || \ GOBIN=$(LOCALBIN) go install sigs.k8s.io/kind@$(KIND_VERSION) diff --git a/internal/controller/etcdcluster_controller.go b/internal/controller/etcdcluster_controller.go index 1ca84255..0e7be751 100644 --- a/internal/controller/etcdcluster_controller.go +++ b/internal/controller/etcdcluster_controller.go @@ -99,7 +99,9 @@ func (r *EtcdClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) // set cluster readiness condition existingCondition := factory.GetCondition(instance, etcdaenixiov1alpha1.EtcdConditionReady) - if existingCondition.Reason == string(etcdaenixiov1alpha1.EtcdCondTypeWaitingForFirstQuorum) && !clusterReady { + if existingCondition != nil && + existingCondition.Reason == string(etcdaenixiov1alpha1.EtcdCondTypeWaitingForFirstQuorum) && + !clusterReady { // if we are still "waiting for first quorum establishment" and the StatefulSet // isn't ready yet, don't update the EtcdConditionReady, but circuit-break. return r.updateStatus(ctx, instance)