Skip to content

Commit

Permalink
Add nilaway linter. (#184)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mneverov and hiddenmarten authored Apr 21, 2024
1 parent 0e6659b commit b6e8f5a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/etcdcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b6e8f5a

Please sign in to comment.