Skip to content

Commit

Permalink
chore: Linter configuration - Importas (#340)
Browse files Browse the repository at this point in the history
* Makefile

* loggercheck

* importas: metav1

* kcorev1 "k8s.io/api/core/v1"

* kutilruntime "k8s.io/apimachinery/pkg/util/runtime"

* kscheme "k8s.io/client-go/kubernetes/scheme"

* kappsv1 "k8s.io/api/apps/v1"

* kcontrollerruntime "sigs.k8s.io/controller-runtime"

* k8s.io/api/apps/v1

* ktypes "k8s.io/apimachinery/pkg/types"

* kapierrors "k8s.io/apimachinery/pkg/api/errors"

* klogzap "sigs.k8s.io/controller-runtime/pkg/log/zap"

* nmkmocks "github.com/kyma-project/nats-manager/pkg/k8s/mocks"

* kapiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"

* onsigomegatypes "github.com/onsi/gomega/types"

* kapiextclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"

* nmcontroller "github.com/kyma-project/nats-manager/internal/controller/nats"

* nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1"

* kapipolicyv1 "k8s.io/api/policy/v1"

* nmkchartmocks "github.com/kyma-project/nats-manager/pkg/k8s/chart/mocks"

* kapiextclientsetfake "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake"

* kutilyaml "k8s.io/apimachinery/pkg/util/yaml"

* nmmanagermocks "github.com/kyma-project/nats-manager/pkg/manager/mocks"

* nmctrlmocks "github.com/kyma-project/nats-manager/internal/controller/nats/mocks"

* nmctrl

* nmmgr "github.com/kyma-project/nats-manager/pkg/manager"

* nmmgrmocks

* nmctrlurl "github.com/kyma-project/nats-manager/internal/controller/nats/url"

* nmmgrmocks

* nmtsmatchers "github.com/kyma-project/nats-manager/testutils/matchers/nats"

* keventsv1 "k8s.io/api/events/v1"

* keventsv1 "k8s.io/api/events/v1"

* natsgo "github.com/kyma-project/nats-manager/pkg/nats"

* nmtsmatchers

* nmnats "github.com/kyma-project/nats-manager/pkg/nats"

* natsgo "github.com/nats-io/nats.go"

* krbacv1 "k8s.io/api/rbac/v1"

* kautoscalingv1 "k8s.io/api/autoscaling/v1"

* nmctrlcache "github.com/kyma-project/nats-manager/internal/controller/cache"

* nmlabels "github.com/kyma-project/nats-manager/pkg/labels"

* Linter config
  • Loading branch information
the1bit authored Feb 22, 2024
1 parent f2a48e0 commit aa46b5b
Show file tree
Hide file tree
Showing 51 changed files with 1,750 additions and 1,761 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ nats-manager.yaml
module-config.yaml

.env.dev


.golangci.yaml
.golangci.yaml_old
lint-report.json
487 changes: 220 additions & 267 deletions .golangci.yaml

Large diffs are not rendered by default.

36 changes: 33 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ endif
# Module Name used for bundling the OCI Image and later on for referencing in the Kyma Modules
MODULE_NAME ?= nats

# Lint issue category
CATEGORY = "default"

# Operating system architecture
OS_ARCH ?= $(shell uname -m)

Expand Down Expand Up @@ -104,6 +107,36 @@ generate-and-test: vendor manifests generate fmt imports vet lint test;
test: envtest ## Run only tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out

.PHONY: lint
lint: ## Check lint issues using `golangci-lint`
golangci-lint run --timeout 5m --config=./.golangci.yaml

.PHONY: lint-compact
lint-compact: ## Check lint issues using `golangci-lint` in compact result format
golangci-lint run --timeout 5m --config=./.golangci.yaml --print-issued-lines=false

.PHONY: lint-fix
lint-fix: ## Check and fix lint issues using `golangci-lint`
golangci-lint run --fix --timeout 5m --config=./.golangci.yaml

.PHONY: lint-report
lint-report: ## Check lint issues using `golangci-lint` then export them to a file, then print the list of linters used
golangci-lint run --timeout 5m --config=./.golangci.yaml --issues-exit-code 0 --out-format json > ./lint-report.json

.PHONY: lint-report-issue-category
lint-report-issue-category: ## Get lint issues categories
make lint-report-clean
make lint-report
cat ./lint-report.json | jq '.Issues[].FromLinter' | jq -s 'map({(.):1})|add|keys_unsorted'

.PHONY: lint-report-get-category
lint-report-get-category: ## Get lint issues by category
cat ./lint-report.json | jq --arg CATEGORY $$CATEGORY '.Issues[] | select(.FromLinter==$$CATEGORY)'

.PHONY: lint-report-clean
lint-report-clean: ## Clean lint report
rm -f ./lint-report.json

##@ Build

.PHONY: build
Expand Down Expand Up @@ -226,9 +259,6 @@ envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

lint:
golangci-lint run --fix

go-gen:
go generate ./...

Expand Down
42 changes: 21 additions & 21 deletions api/v1alpha1/nats_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import (
"reflect"

"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func (ns *NATSStatus) IsEqual(status NATSStatus) bool {
thisWithoutCond := ns.DeepCopy()
statusWithoutCond := status.DeepCopy()

// remove conditions, so that we don't compare them
thisWithoutCond.Conditions = []metav1.Condition{}
statusWithoutCond.Conditions = []metav1.Condition{}
thisWithoutCond.Conditions = []kmetav1.Condition{}
statusWithoutCond.Conditions = []kmetav1.Condition{}

return reflect.DeepEqual(thisWithoutCond, statusWithoutCond) &&
ConditionsEquals(ns.Conditions, status.Conditions)
}

func (ns *NATSStatus) FindCondition(conditionType ConditionType) *metav1.Condition {
func (ns *NATSStatus) FindCondition(conditionType ConditionType) *kmetav1.Condition {
for _, condition := range ns.Conditions {
if string(conditionType) == condition.Type {
return &condition
Expand All @@ -28,24 +28,24 @@ func (ns *NATSStatus) FindCondition(conditionType ConditionType) *metav1.Conditi
return nil
}

func (ns *NATSStatus) UpdateConditionStatefulSet(status metav1.ConditionStatus, reason ConditionReason,
func (ns *NATSStatus) UpdateConditionStatefulSet(status kmetav1.ConditionStatus, reason ConditionReason,
message string) {
condition := metav1.Condition{
condition := kmetav1.Condition{
Type: string(ConditionStatefulSet),
Status: status,
LastTransitionTime: metav1.Now(),
LastTransitionTime: kmetav1.Now(),
Reason: string(reason),
Message: message,
}
meta.SetStatusCondition(&ns.Conditions, condition)
}

func (ns *NATSStatus) UpdateConditionAvailable(status metav1.ConditionStatus, reason ConditionReason,
func (ns *NATSStatus) UpdateConditionAvailable(status kmetav1.ConditionStatus, reason ConditionReason,
message string) {
condition := metav1.Condition{
condition := kmetav1.Condition{
Type: string(ConditionAvailable),
Status: status,
LastTransitionTime: metav1.Now(),
LastTransitionTime: kmetav1.Now(),
Reason: string(reason),
Message: message,
}
Expand All @@ -54,9 +54,9 @@ func (ns *NATSStatus) UpdateConditionAvailable(status metav1.ConditionStatus, re

func (ns *NATSStatus) SetStateReady() {
ns.State = StateReady
ns.UpdateConditionStatefulSet(metav1.ConditionTrue,
ns.UpdateConditionStatefulSet(kmetav1.ConditionTrue,
ConditionReasonStatefulSetAvailable, "StatefulSet is ready")
ns.UpdateConditionAvailable(metav1.ConditionTrue, ConditionReasonDeployed, "NATS is deployed")
ns.UpdateConditionAvailable(kmetav1.ConditionTrue, ConditionReasonDeployed, "NATS is deployed")
}

func (ns *NATSStatus) SetStateProcessing() {
Expand All @@ -69,27 +69,27 @@ func (ns *NATSStatus) SetStateWarning() {

func (ns *NATSStatus) SetWaitingStateForStatefulSet() {
ns.SetStateProcessing()
ns.UpdateConditionStatefulSet(metav1.ConditionFalse,
ns.UpdateConditionStatefulSet(kmetav1.ConditionFalse,
ConditionReasonStatefulSetPending, "")
ns.UpdateConditionAvailable(metav1.ConditionFalse, ConditionReasonDeploying, "")
ns.UpdateConditionAvailable(kmetav1.ConditionFalse, ConditionReasonDeploying, "")
}

func (ns *NATSStatus) SetStateError() {
ns.State = StateError
ns.UpdateConditionStatefulSet(metav1.ConditionFalse, ConditionReasonSyncFailError, "")
ns.UpdateConditionAvailable(metav1.ConditionFalse, ConditionReasonProcessingError, "")
ns.UpdateConditionStatefulSet(kmetav1.ConditionFalse, ConditionReasonSyncFailError, "")
ns.UpdateConditionAvailable(kmetav1.ConditionFalse, ConditionReasonProcessingError, "")
}

func (ns *NATSStatus) SetStateDeleting() {
ns.State = StateDeleting
}

func (ns *NATSStatus) UpdateConditionDeletion(status metav1.ConditionStatus, reason ConditionReason,
func (ns *NATSStatus) UpdateConditionDeletion(status kmetav1.ConditionStatus, reason ConditionReason,
message string) {
condition := metav1.Condition{
condition := kmetav1.Condition{
Type: string(ConditionDeleted),
Status: status,
LastTransitionTime: metav1.Now(),
LastTransitionTime: kmetav1.Now(),
Reason: string(reason),
Message: message,
}
Expand All @@ -98,8 +98,8 @@ func (ns *NATSStatus) UpdateConditionDeletion(status metav1.ConditionStatus, rea

func (ns *NATSStatus) Initialize() {
ns.SetStateProcessing()
ns.UpdateConditionStatefulSet(metav1.ConditionFalse, ConditionReasonProcessing, "")
ns.UpdateConditionAvailable(metav1.ConditionFalse, ConditionReasonProcessing, "")
ns.UpdateConditionStatefulSet(kmetav1.ConditionFalse, ConditionReasonProcessing, "")
ns.UpdateConditionAvailable(kmetav1.ConditionFalse, ConditionReasonProcessing, "")
}

// ClearURL clears the url.
Expand Down
Loading

0 comments on commit aa46b5b

Please sign in to comment.