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)