diff --git a/.github/workflows/lint-sample.yml b/.github/workflows/lint-sample.yml index 9b7b3d21a0e..6812f3cf41c 100644 --- a/.github/workflows/lint-sample.yml +++ b/.github/workflows/lint-sample.yml @@ -33,6 +33,11 @@ jobs: - name: Prepare ${{ matrix.folder }} working-directory: ${{ matrix.folder }} run: go mod tidy + - name: Build kubeapilinter + working-directory: ${{ matrix.folder }} + run: make kube-api-linter + env: + CGO_ENABLED: 1 - name: Check linter configuration working-directory: ${{ matrix.folder }} run: make lint-config @@ -41,6 +46,7 @@ jobs: with: version: v2.2.2 working-directory: ${{ matrix.folder }} + install-mode: goinstall - name: Run linter via makefile target working-directory: ${{ matrix.folder }} run: make lint diff --git a/docs/book/src/cronjob-tutorial/testdata/project/.github/workflows/lint.yml b/docs/book/src/cronjob-tutorial/testdata/project/.github/workflows/lint.yml index 649d09042f7..bb2ebf17f27 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/.github/workflows/lint.yml +++ b/docs/book/src/cronjob-tutorial/testdata/project/.github/workflows/lint.yml @@ -21,3 +21,4 @@ jobs: uses: golangci/golangci-lint-action@v8 with: version: v2.2.2 + install-mode: goinstall diff --git a/docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml b/docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml index e5b21b0f11c..5496b5c1a46 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml +++ b/docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml @@ -21,11 +21,20 @@ linters: - unconvert - unparam - unused + - kubeapilinter settings: revive: rules: - name: comment-spacings - name: import-shadowing + custom: + kubeapilinter: + path: "./bin/kube-api-linter.so" + description: "Kube API Linter plugin" + original-url: "sigs.k8s.io/kube-api-linter" + settings: + linters: { } + lintersConfig: { } exclusions: generated: lax rules: @@ -36,6 +45,9 @@ linters: - dupl - lll path: internal/* + - path-except: "^api/" + linters: + - kubeapilinter paths: - third_party$ - builtin$ diff --git a/docs/book/src/cronjob-tutorial/testdata/project/Makefile b/docs/book/src/cronjob-tutorial/testdata/project/Makefile index 965e1d00ba4..5e6266181f3 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/Makefile +++ b/docs/book/src/cronjob-tutorial/testdata/project/Makefile @@ -95,7 +95,7 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests @$(KIND) delete cluster --name $(KIND_CLUSTER) .PHONY: lint -lint: golangci-lint ## Run golangci-lint linter +lint: golangci-lint kube-api-linter ## Run golangci-lint linter $(GOLANGCI_LINT) run .PHONY: lint-fix @@ -225,6 +225,23 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) +# To lint Kubernetes API definitions. +# More info: https://github.com/kubernetes-sigs/kube-api-linter +KUBE_API_LINTER_PLUGIN := $(LOCALBIN)/kube-api-linter.so +KUBE_API_LINTER_BUILD_DIR := ./hack/kube-api-linter + +.PHONY: kube-api-linter +kube-api-linter: $(KUBE_API_LINTER_PLUGIN) ## Build the kube-api-linter plugin +$(KUBE_API_LINTER_PLUGIN): $(KUBE_API_LINTER_BUILD_DIR)/go.mod + cd $(KUBE_API_LINTER_BUILD_DIR) && \ + go build -buildmode=plugin -o "$(abspath $(KUBE_API_LINTER_PLUGIN))" sigs.k8s.io/kube-api-linter/pkg/plugin +$(KUBE_API_LINTER_BUILD_DIR)/go.mod: + @echo "Setting up local module for kube-api-linter plugin..." + mkdir -p $(KUBE_API_LINTER_BUILD_DIR) + cd $(KUBE_API_LINTER_BUILD_DIR) && \ + go mod init local-kube-api-linter && \ + go get sigs.k8s.io/kube-api-linter@latest + # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist # $1 - target path with name of binary # $2 - package url which can be installed diff --git a/docs/book/src/getting-started.md b/docs/book/src/getting-started.md index d621818b288..5b1b5a46911 100644 --- a/docs/book/src/getting-started.md +++ b/docs/book/src/getting-started.md @@ -83,6 +83,8 @@ we will allow configuring the number of instances with the following: ```go type MemcachedSpec struct { ... + // +kubebuilder:validation:Minimum=0 + // +required Size int32 `json:"size,omitempty"` } ``` @@ -97,7 +99,21 @@ similar to how we do with any resource from the Kubernetes API. ```go // MemcachedStatus defines the observed state of Memcached type MemcachedStatus struct { - Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` + // For Kubernetes API conventions, see: + // https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties + + // conditions represent the current state of the {{ .Resource.Kind }} resource. + // Each condition has a unique type and reflects the status of a specific aspect of the resource. + // + // Standard condition types include: + // - "Available": the resource is fully functional. + // - "Progressing": the resource is being created or updated. + // - "Degraded": the resource failed to reach or maintain its desired state. + // + // The status of each condition is one of True, False, or Unknown. + // +listType=map + // +listMapKey=type + Conditions []metav1.Condition `json:"conditions,omitempty"` } ``` diff --git a/docs/book/src/getting-started/testdata/project/.github/workflows/lint.yml b/docs/book/src/getting-started/testdata/project/.github/workflows/lint.yml index 649d09042f7..bb2ebf17f27 100644 --- a/docs/book/src/getting-started/testdata/project/.github/workflows/lint.yml +++ b/docs/book/src/getting-started/testdata/project/.github/workflows/lint.yml @@ -21,3 +21,4 @@ jobs: uses: golangci/golangci-lint-action@v8 with: version: v2.2.2 + install-mode: goinstall diff --git a/docs/book/src/getting-started/testdata/project/.golangci.yml b/docs/book/src/getting-started/testdata/project/.golangci.yml index e5b21b0f11c..5496b5c1a46 100644 --- a/docs/book/src/getting-started/testdata/project/.golangci.yml +++ b/docs/book/src/getting-started/testdata/project/.golangci.yml @@ -21,11 +21,20 @@ linters: - unconvert - unparam - unused + - kubeapilinter settings: revive: rules: - name: comment-spacings - name: import-shadowing + custom: + kubeapilinter: + path: "./bin/kube-api-linter.so" + description: "Kube API Linter plugin" + original-url: "sigs.k8s.io/kube-api-linter" + settings: + linters: { } + lintersConfig: { } exclusions: generated: lax rules: @@ -36,6 +45,9 @@ linters: - dupl - lll path: internal/* + - path-except: "^api/" + linters: + - kubeapilinter paths: - third_party$ - builtin$ diff --git a/docs/book/src/getting-started/testdata/project/Makefile b/docs/book/src/getting-started/testdata/project/Makefile index de4fa8c93d4..7f163369a32 100644 --- a/docs/book/src/getting-started/testdata/project/Makefile +++ b/docs/book/src/getting-started/testdata/project/Makefile @@ -91,7 +91,7 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests @$(KIND) delete cluster --name $(KIND_CLUSTER) .PHONY: lint -lint: golangci-lint ## Run golangci-lint linter +lint: golangci-lint kube-api-linter ## Run golangci-lint linter $(GOLANGCI_LINT) run .PHONY: lint-fix @@ -221,6 +221,23 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) +# To lint Kubernetes API definitions. +# More info: https://github.com/kubernetes-sigs/kube-api-linter +KUBE_API_LINTER_PLUGIN := $(LOCALBIN)/kube-api-linter.so +KUBE_API_LINTER_BUILD_DIR := ./hack/kube-api-linter + +.PHONY: kube-api-linter +kube-api-linter: $(KUBE_API_LINTER_PLUGIN) ## Build the kube-api-linter plugin +$(KUBE_API_LINTER_PLUGIN): $(KUBE_API_LINTER_BUILD_DIR)/go.mod + cd $(KUBE_API_LINTER_BUILD_DIR) && \ + go build -buildmode=plugin -o "$(abspath $(KUBE_API_LINTER_PLUGIN))" sigs.k8s.io/kube-api-linter/pkg/plugin +$(KUBE_API_LINTER_BUILD_DIR)/go.mod: + @echo "Setting up local module for kube-api-linter plugin..." + mkdir -p $(KUBE_API_LINTER_BUILD_DIR) + cd $(KUBE_API_LINTER_BUILD_DIR) && \ + go mod init local-kube-api-linter && \ + go get sigs.k8s.io/kube-api-linter@latest + # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist # $1 - target path with name of binary # $2 - package url which can be installed diff --git a/docs/book/src/multiversion-tutorial/testdata/project/.github/workflows/lint.yml b/docs/book/src/multiversion-tutorial/testdata/project/.github/workflows/lint.yml index 649d09042f7..bb2ebf17f27 100644 --- a/docs/book/src/multiversion-tutorial/testdata/project/.github/workflows/lint.yml +++ b/docs/book/src/multiversion-tutorial/testdata/project/.github/workflows/lint.yml @@ -21,3 +21,4 @@ jobs: uses: golangci/golangci-lint-action@v8 with: version: v2.2.2 + install-mode: goinstall diff --git a/docs/book/src/multiversion-tutorial/testdata/project/.golangci.yml b/docs/book/src/multiversion-tutorial/testdata/project/.golangci.yml index e5b21b0f11c..5496b5c1a46 100644 --- a/docs/book/src/multiversion-tutorial/testdata/project/.golangci.yml +++ b/docs/book/src/multiversion-tutorial/testdata/project/.golangci.yml @@ -21,11 +21,20 @@ linters: - unconvert - unparam - unused + - kubeapilinter settings: revive: rules: - name: comment-spacings - name: import-shadowing + custom: + kubeapilinter: + path: "./bin/kube-api-linter.so" + description: "Kube API Linter plugin" + original-url: "sigs.k8s.io/kube-api-linter" + settings: + linters: { } + lintersConfig: { } exclusions: generated: lax rules: @@ -36,6 +45,9 @@ linters: - dupl - lll path: internal/* + - path-except: "^api/" + linters: + - kubeapilinter paths: - third_party$ - builtin$ diff --git a/docs/book/src/multiversion-tutorial/testdata/project/Makefile b/docs/book/src/multiversion-tutorial/testdata/project/Makefile index 965e1d00ba4..5e6266181f3 100644 --- a/docs/book/src/multiversion-tutorial/testdata/project/Makefile +++ b/docs/book/src/multiversion-tutorial/testdata/project/Makefile @@ -95,7 +95,7 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests @$(KIND) delete cluster --name $(KIND_CLUSTER) .PHONY: lint -lint: golangci-lint ## Run golangci-lint linter +lint: golangci-lint kube-api-linter ## Run golangci-lint linter $(GOLANGCI_LINT) run .PHONY: lint-fix @@ -225,6 +225,23 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) +# To lint Kubernetes API definitions. +# More info: https://github.com/kubernetes-sigs/kube-api-linter +KUBE_API_LINTER_PLUGIN := $(LOCALBIN)/kube-api-linter.so +KUBE_API_LINTER_BUILD_DIR := ./hack/kube-api-linter + +.PHONY: kube-api-linter +kube-api-linter: $(KUBE_API_LINTER_PLUGIN) ## Build the kube-api-linter plugin +$(KUBE_API_LINTER_PLUGIN): $(KUBE_API_LINTER_BUILD_DIR)/go.mod + cd $(KUBE_API_LINTER_BUILD_DIR) && \ + go build -buildmode=plugin -o "$(abspath $(KUBE_API_LINTER_PLUGIN))" sigs.k8s.io/kube-api-linter/pkg/plugin +$(KUBE_API_LINTER_BUILD_DIR)/go.mod: + @echo "Setting up local module for kube-api-linter plugin..." + mkdir -p $(KUBE_API_LINTER_BUILD_DIR) + cd $(KUBE_API_LINTER_BUILD_DIR) && \ + go mod init local-kube-api-linter && \ + go get sigs.k8s.io/kube-api-linter@latest + # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist # $1 - target path with name of binary # $2 - package url which can be installed diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/github/lint.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/github/lint.go index 730eba48ab4..515ba1330ac 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/github/lint.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/github/lint.go @@ -69,4 +69,5 @@ jobs: uses: golangci/golangci-lint-action@v8 with: version: {{ .GolangciLintVersion }} + install-mode: goinstall ` diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go index d2a1d1fc012..dcd353cee87 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go @@ -64,11 +64,20 @@ linters: - unconvert - unparam - unused + - kubeapilinter settings: revive: rules: - name: comment-spacings - name: import-shadowing + custom: + kubeapilinter: + path: "./bin/kube-api-linter.so" + description: "Kube API Linter plugin" + original-url: "sigs.k8s.io/kube-api-linter" + settings: + linters: { } + lintersConfig: { } exclusions: generated: lax rules: @@ -79,6 +88,9 @@ linters: - dupl - lll path: internal/* + - path-except: "^api/" + linters: + - kubeapilinter paths: - third_party$ - builtin$ diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go index 14548ea1dd1..3b00793a7a8 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go @@ -170,7 +170,7 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests @$(KIND) delete cluster --name $(KIND_CLUSTER) .PHONY: lint -lint: golangci-lint ## Run golangci-lint linter +lint: golangci-lint kube-api-linter ## Run golangci-lint linter $(GOLANGCI_LINT) run .PHONY: lint-fix @@ -300,6 +300,23 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) +# To lint Kubernetes API definitions. +# More info: https://github.com/kubernetes-sigs/kube-api-linter +KUBE_API_LINTER_PLUGIN := $(LOCALBIN)/kube-api-linter.so +KUBE_API_LINTER_BUILD_DIR := ./hack/kube-api-linter + +.PHONY: kube-api-linter +kube-api-linter: $(KUBE_API_LINTER_PLUGIN) ## Build the kube-api-linter plugin +$(KUBE_API_LINTER_PLUGIN): $(KUBE_API_LINTER_BUILD_DIR)/go.mod + cd $(KUBE_API_LINTER_BUILD_DIR) && \ + go build -buildmode=plugin -o "$(abspath $(KUBE_API_LINTER_PLUGIN))" sigs.k8s.io/kube-api-linter/pkg/plugin +$(KUBE_API_LINTER_BUILD_DIR)/go.mod: + @echo "Setting up local module for kube-api-linter plugin..." + mkdir -p $(KUBE_API_LINTER_BUILD_DIR) + cd $(KUBE_API_LINTER_BUILD_DIR) && \ + go mod init local-kube-api-linter && \ + go get sigs.k8s.io/kube-api-linter@latest + # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist # $1 - target path with name of binary # $2 - package url which can be installed diff --git a/testdata/project-v4-multigroup/.github/workflows/lint.yml b/testdata/project-v4-multigroup/.github/workflows/lint.yml index 649d09042f7..bb2ebf17f27 100644 --- a/testdata/project-v4-multigroup/.github/workflows/lint.yml +++ b/testdata/project-v4-multigroup/.github/workflows/lint.yml @@ -21,3 +21,4 @@ jobs: uses: golangci/golangci-lint-action@v8 with: version: v2.2.2 + install-mode: goinstall diff --git a/testdata/project-v4-multigroup/.golangci.yml b/testdata/project-v4-multigroup/.golangci.yml index e5b21b0f11c..5496b5c1a46 100644 --- a/testdata/project-v4-multigroup/.golangci.yml +++ b/testdata/project-v4-multigroup/.golangci.yml @@ -21,11 +21,20 @@ linters: - unconvert - unparam - unused + - kubeapilinter settings: revive: rules: - name: comment-spacings - name: import-shadowing + custom: + kubeapilinter: + path: "./bin/kube-api-linter.so" + description: "Kube API Linter plugin" + original-url: "sigs.k8s.io/kube-api-linter" + settings: + linters: { } + lintersConfig: { } exclusions: generated: lax rules: @@ -36,6 +45,9 @@ linters: - dupl - lll path: internal/* + - path-except: "^api/" + linters: + - kubeapilinter paths: - third_party$ - builtin$ diff --git a/testdata/project-v4-multigroup/Makefile b/testdata/project-v4-multigroup/Makefile index 3abd684e6a9..5a56ac13ace 100644 --- a/testdata/project-v4-multigroup/Makefile +++ b/testdata/project-v4-multigroup/Makefile @@ -91,7 +91,7 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests @$(KIND) delete cluster --name $(KIND_CLUSTER) .PHONY: lint -lint: golangci-lint ## Run golangci-lint linter +lint: golangci-lint kube-api-linter ## Run golangci-lint linter $(GOLANGCI_LINT) run .PHONY: lint-fix @@ -221,6 +221,23 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) +# To lint Kubernetes API definitions. +# More info: https://github.com/kubernetes-sigs/kube-api-linter +KUBE_API_LINTER_PLUGIN := $(LOCALBIN)/kube-api-linter.so +KUBE_API_LINTER_BUILD_DIR := ./hack/kube-api-linter + +.PHONY: kube-api-linter +kube-api-linter: $(KUBE_API_LINTER_PLUGIN) ## Build the kube-api-linter plugin +$(KUBE_API_LINTER_PLUGIN): $(KUBE_API_LINTER_BUILD_DIR)/go.mod + cd $(KUBE_API_LINTER_BUILD_DIR) && \ + go build -buildmode=plugin -o "$(abspath $(KUBE_API_LINTER_PLUGIN))" sigs.k8s.io/kube-api-linter/pkg/plugin +$(KUBE_API_LINTER_BUILD_DIR)/go.mod: + @echo "Setting up local module for kube-api-linter plugin..." + mkdir -p $(KUBE_API_LINTER_BUILD_DIR) + cd $(KUBE_API_LINTER_BUILD_DIR) && \ + go mod init local-kube-api-linter && \ + go get sigs.k8s.io/kube-api-linter@latest + # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist # $1 - target path with name of binary # $2 - package url which can be installed diff --git a/testdata/project-v4-with-plugins/.github/workflows/lint.yml b/testdata/project-v4-with-plugins/.github/workflows/lint.yml index 649d09042f7..bb2ebf17f27 100644 --- a/testdata/project-v4-with-plugins/.github/workflows/lint.yml +++ b/testdata/project-v4-with-plugins/.github/workflows/lint.yml @@ -21,3 +21,4 @@ jobs: uses: golangci/golangci-lint-action@v8 with: version: v2.2.2 + install-mode: goinstall diff --git a/testdata/project-v4-with-plugins/.golangci.yml b/testdata/project-v4-with-plugins/.golangci.yml index e5b21b0f11c..5496b5c1a46 100644 --- a/testdata/project-v4-with-plugins/.golangci.yml +++ b/testdata/project-v4-with-plugins/.golangci.yml @@ -21,11 +21,20 @@ linters: - unconvert - unparam - unused + - kubeapilinter settings: revive: rules: - name: comment-spacings - name: import-shadowing + custom: + kubeapilinter: + path: "./bin/kube-api-linter.so" + description: "Kube API Linter plugin" + original-url: "sigs.k8s.io/kube-api-linter" + settings: + linters: { } + lintersConfig: { } exclusions: generated: lax rules: @@ -36,6 +45,9 @@ linters: - dupl - lll path: internal/* + - path-except: "^api/" + linters: + - kubeapilinter paths: - third_party$ - builtin$ diff --git a/testdata/project-v4-with-plugins/Makefile b/testdata/project-v4-with-plugins/Makefile index 155b3c72c2f..badf3b29266 100644 --- a/testdata/project-v4-with-plugins/Makefile +++ b/testdata/project-v4-with-plugins/Makefile @@ -91,7 +91,7 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests @$(KIND) delete cluster --name $(KIND_CLUSTER) .PHONY: lint -lint: golangci-lint ## Run golangci-lint linter +lint: golangci-lint kube-api-linter ## Run golangci-lint linter $(GOLANGCI_LINT) run .PHONY: lint-fix @@ -221,6 +221,23 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) +# To lint Kubernetes API definitions. +# More info: https://github.com/kubernetes-sigs/kube-api-linter +KUBE_API_LINTER_PLUGIN := $(LOCALBIN)/kube-api-linter.so +KUBE_API_LINTER_BUILD_DIR := ./hack/kube-api-linter + +.PHONY: kube-api-linter +kube-api-linter: $(KUBE_API_LINTER_PLUGIN) ## Build the kube-api-linter plugin +$(KUBE_API_LINTER_PLUGIN): $(KUBE_API_LINTER_BUILD_DIR)/go.mod + cd $(KUBE_API_LINTER_BUILD_DIR) && \ + go build -buildmode=plugin -o "$(abspath $(KUBE_API_LINTER_PLUGIN))" sigs.k8s.io/kube-api-linter/pkg/plugin +$(KUBE_API_LINTER_BUILD_DIR)/go.mod: + @echo "Setting up local module for kube-api-linter plugin..." + mkdir -p $(KUBE_API_LINTER_BUILD_DIR) + cd $(KUBE_API_LINTER_BUILD_DIR) && \ + go mod init local-kube-api-linter && \ + go get sigs.k8s.io/kube-api-linter@latest + # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist # $1 - target path with name of binary # $2 - package url which can be installed diff --git a/testdata/project-v4/.github/workflows/lint.yml b/testdata/project-v4/.github/workflows/lint.yml index 649d09042f7..bb2ebf17f27 100644 --- a/testdata/project-v4/.github/workflows/lint.yml +++ b/testdata/project-v4/.github/workflows/lint.yml @@ -21,3 +21,4 @@ jobs: uses: golangci/golangci-lint-action@v8 with: version: v2.2.2 + install-mode: goinstall diff --git a/testdata/project-v4/.golangci.yml b/testdata/project-v4/.golangci.yml index e5b21b0f11c..5496b5c1a46 100644 --- a/testdata/project-v4/.golangci.yml +++ b/testdata/project-v4/.golangci.yml @@ -21,11 +21,20 @@ linters: - unconvert - unparam - unused + - kubeapilinter settings: revive: rules: - name: comment-spacings - name: import-shadowing + custom: + kubeapilinter: + path: "./bin/kube-api-linter.so" + description: "Kube API Linter plugin" + original-url: "sigs.k8s.io/kube-api-linter" + settings: + linters: { } + lintersConfig: { } exclusions: generated: lax rules: @@ -36,6 +45,9 @@ linters: - dupl - lll path: internal/* + - path-except: "^api/" + linters: + - kubeapilinter paths: - third_party$ - builtin$ diff --git a/testdata/project-v4/Makefile b/testdata/project-v4/Makefile index 9fdeac93659..9ed6030b0e2 100644 --- a/testdata/project-v4/Makefile +++ b/testdata/project-v4/Makefile @@ -91,7 +91,7 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests @$(KIND) delete cluster --name $(KIND_CLUSTER) .PHONY: lint -lint: golangci-lint ## Run golangci-lint linter +lint: golangci-lint kube-api-linter ## Run golangci-lint linter $(GOLANGCI_LINT) run .PHONY: lint-fix @@ -221,6 +221,23 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) +# To lint Kubernetes API definitions. +# More info: https://github.com/kubernetes-sigs/kube-api-linter +KUBE_API_LINTER_PLUGIN := $(LOCALBIN)/kube-api-linter.so +KUBE_API_LINTER_BUILD_DIR := ./hack/kube-api-linter + +.PHONY: kube-api-linter +kube-api-linter: $(KUBE_API_LINTER_PLUGIN) ## Build the kube-api-linter plugin +$(KUBE_API_LINTER_PLUGIN): $(KUBE_API_LINTER_BUILD_DIR)/go.mod + cd $(KUBE_API_LINTER_BUILD_DIR) && \ + go build -buildmode=plugin -o "$(abspath $(KUBE_API_LINTER_PLUGIN))" sigs.k8s.io/kube-api-linter/pkg/plugin +$(KUBE_API_LINTER_BUILD_DIR)/go.mod: + @echo "Setting up local module for kube-api-linter plugin..." + mkdir -p $(KUBE_API_LINTER_BUILD_DIR) + cd $(KUBE_API_LINTER_BUILD_DIR) && \ + go mod init local-kube-api-linter && \ + go get sigs.k8s.io/kube-api-linter@latest + # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist # $1 - target path with name of binary # $2 - package url which can be installed