Skip to content

Commit 963e422

Browse files
(experimental) - Add kube-api custom lint
1 parent 202a630 commit 963e422

File tree

14 files changed

+203
-7
lines changed

14 files changed

+203
-7
lines changed

docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ linters:
2626
rules:
2727
- name: comment-spacings
2828
- name: import-shadowing
29+
custom:
30+
kubeapilinter:
31+
path: "./bin/kube-api-linter.so"
32+
description: "Kube API Linter plugin"
33+
original-url: "sigs.k8s.io/kube-api-linter"
34+
settings:
35+
linters: { }
36+
lintersConfig: { }
2937
exclusions:
3038
generated: lax
3139
rules:
@@ -36,6 +44,9 @@ linters:
3644
- dupl
3745
- lll
3846
path: internal/*
47+
- path-except: "^api/"
48+
linters:
49+
- kubeapilinter
3950
paths:
4051
- third_party$
4152
- builtin$

docs/book/src/cronjob-tutorial/testdata/project/Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
8989
@$(KIND) delete cluster --name $(KIND_CLUSTER)
9090

9191
.PHONY: lint
92-
lint: golangci-lint ## Run golangci-lint linter
92+
lint: golangci-lint kube-api-linter ## Run golangci-lint linter
9393
$(GOLANGCI_LINT) run
9494

9595
.PHONY: lint-fix
@@ -219,6 +219,23 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
219219
$(GOLANGCI_LINT): $(LOCALBIN)
220220
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
221221

222+
# Kube-API-Linter plugin
223+
KUBE_API_LINTER_PLUGIN := $(LOCALBIN)/kube-api-linter.so
224+
KUBE_API_LINTER_BUILD_DIR := ./hack/kube-api-linter
225+
226+
.PHONY: kube-api-linter
227+
kube-api-linter: $(KUBE_API_LINTER_PLUGIN) ## Build the kube-api-linter plugin
228+
$(KUBE_API_LINTER_PLUGIN): $(KUBE_API_LINTER_BUILD_DIR)/go.mod
229+
cd $(KUBE_API_LINTER_BUILD_DIR) && \
230+
go build -buildmode=plugin -o "$(abspath $(KUBE_API_LINTER_PLUGIN))" sigs.k8s.io/kube-api-linter/pkg/plugin
231+
$(KUBE_API_LINTER_BUILD_DIR)/go.mod:
232+
@echo "Setting up local module for kube-api-linter plugin..."
233+
mkdir -p $(KUBE_API_LINTER_BUILD_DIR)
234+
cd $(KUBE_API_LINTER_BUILD_DIR) && \
235+
go mod init local-kube-api-linter && \
236+
go get sigs.k8s.io/kube-api-linter@latest
237+
238+
222239
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
223240
# $1 - target path with name of binary
224241
# $2 - package url which can be installed

docs/book/src/getting-started/testdata/project/.golangci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ linters:
2626
rules:
2727
- name: comment-spacings
2828
- name: import-shadowing
29+
custom:
30+
kubeapilinter:
31+
path: "./bin/kube-api-linter.so"
32+
description: "Kube API Linter plugin"
33+
original-url: "sigs.k8s.io/kube-api-linter"
34+
settings:
35+
linters: { }
36+
lintersConfig: { }
2937
exclusions:
3038
generated: lax
3139
rules:
@@ -36,6 +44,9 @@ linters:
3644
- dupl
3745
- lll
3846
path: internal/*
47+
- path-except: "^api/"
48+
linters:
49+
- kubeapilinter
3950
paths:
4051
- third_party$
4152
- builtin$

docs/book/src/getting-started/testdata/project/Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
8585
@$(KIND) delete cluster --name $(KIND_CLUSTER)
8686

8787
.PHONY: lint
88-
lint: golangci-lint ## Run golangci-lint linter
88+
lint: golangci-lint kube-api-linter ## Run golangci-lint linter
8989
$(GOLANGCI_LINT) run
9090

9191
.PHONY: lint-fix
@@ -215,6 +215,23 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
215215
$(GOLANGCI_LINT): $(LOCALBIN)
216216
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
217217

218+
# Kube-API-Linter plugin
219+
KUBE_API_LINTER_PLUGIN := $(LOCALBIN)/kube-api-linter.so
220+
KUBE_API_LINTER_BUILD_DIR := ./hack/kube-api-linter
221+
222+
.PHONY: kube-api-linter
223+
kube-api-linter: $(KUBE_API_LINTER_PLUGIN) ## Build the kube-api-linter plugin
224+
$(KUBE_API_LINTER_PLUGIN): $(KUBE_API_LINTER_BUILD_DIR)/go.mod
225+
cd $(KUBE_API_LINTER_BUILD_DIR) && \
226+
go build -buildmode=plugin -o "$(abspath $(KUBE_API_LINTER_PLUGIN))" sigs.k8s.io/kube-api-linter/pkg/plugin
227+
$(KUBE_API_LINTER_BUILD_DIR)/go.mod:
228+
@echo "Setting up local module for kube-api-linter plugin..."
229+
mkdir -p $(KUBE_API_LINTER_BUILD_DIR)
230+
cd $(KUBE_API_LINTER_BUILD_DIR) && \
231+
go mod init local-kube-api-linter && \
232+
go get sigs.k8s.io/kube-api-linter@latest
233+
234+
218235
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
219236
# $1 - target path with name of binary
220237
# $2 - package url which can be installed

docs/book/src/multiversion-tutorial/testdata/project/.golangci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ linters:
2626
rules:
2727
- name: comment-spacings
2828
- name: import-shadowing
29+
custom:
30+
kubeapilinter:
31+
path: "./bin/kube-api-linter.so"
32+
description: "Kube API Linter plugin"
33+
original-url: "sigs.k8s.io/kube-api-linter"
34+
settings:
35+
linters: { }
36+
lintersConfig: { }
2937
exclusions:
3038
generated: lax
3139
rules:
@@ -36,6 +44,9 @@ linters:
3644
- dupl
3745
- lll
3846
path: internal/*
47+
- path-except: "^api/"
48+
linters:
49+
- kubeapilinter
3950
paths:
4051
- third_party$
4152
- builtin$

docs/book/src/multiversion-tutorial/testdata/project/Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
8989
@$(KIND) delete cluster --name $(KIND_CLUSTER)
9090

9191
.PHONY: lint
92-
lint: golangci-lint ## Run golangci-lint linter
92+
lint: golangci-lint kube-api-linter ## Run golangci-lint linter
9393
$(GOLANGCI_LINT) run
9494

9595
.PHONY: lint-fix
@@ -219,6 +219,23 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
219219
$(GOLANGCI_LINT): $(LOCALBIN)
220220
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
221221

222+
# Kube-API-Linter plugin
223+
KUBE_API_LINTER_PLUGIN := $(LOCALBIN)/kube-api-linter.so
224+
KUBE_API_LINTER_BUILD_DIR := ./hack/kube-api-linter
225+
226+
.PHONY: kube-api-linter
227+
kube-api-linter: $(KUBE_API_LINTER_PLUGIN) ## Build the kube-api-linter plugin
228+
$(KUBE_API_LINTER_PLUGIN): $(KUBE_API_LINTER_BUILD_DIR)/go.mod
229+
cd $(KUBE_API_LINTER_BUILD_DIR) && \
230+
go build -buildmode=plugin -o "$(abspath $(KUBE_API_LINTER_PLUGIN))" sigs.k8s.io/kube-api-linter/pkg/plugin
231+
$(KUBE_API_LINTER_BUILD_DIR)/go.mod:
232+
@echo "Setting up local module for kube-api-linter plugin..."
233+
mkdir -p $(KUBE_API_LINTER_BUILD_DIR)
234+
cd $(KUBE_API_LINTER_BUILD_DIR) && \
235+
go mod init local-kube-api-linter && \
236+
go get sigs.k8s.io/kube-api-linter@latest
237+
238+
222239
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
223240
# $1 - target path with name of binary
224241
# $2 - package url which can be installed

pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ linters:
6969
rules:
7070
- name: comment-spacings
7171
- name: import-shadowing
72+
custom:
73+
kubeapilinter:
74+
path: "./bin/kube-api-linter.so"
75+
description: "Kube API Linter plugin"
76+
original-url: "sigs.k8s.io/kube-api-linter"
77+
settings:
78+
linters: { }
79+
lintersConfig: { }
7280
exclusions:
7381
generated: lax
7482
rules:
@@ -79,6 +87,9 @@ linters:
7987
- dupl
8088
- lll
8189
path: internal/*
90+
- path-except: "^api/"
91+
linters:
92+
- kubeapilinter
8293
paths:
8394
- third_party$
8495
- builtin$

pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
164164
@$(KIND) delete cluster --name $(KIND_CLUSTER)
165165
166166
.PHONY: lint
167-
lint: golangci-lint ## Run golangci-lint linter
167+
lint: golangci-lint kube-api-linter ## Run golangci-lint linter
168168
$(GOLANGCI_LINT) run
169169
170170
.PHONY: lint-fix
@@ -294,6 +294,23 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
294294
$(GOLANGCI_LINT): $(LOCALBIN)
295295
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
296296
297+
# Kube-API-Linter plugin
298+
KUBE_API_LINTER_PLUGIN := $(LOCALBIN)/kube-api-linter.so
299+
KUBE_API_LINTER_BUILD_DIR := ./hack/kube-api-linter
300+
301+
.PHONY: kube-api-linter
302+
kube-api-linter: $(KUBE_API_LINTER_PLUGIN) ## Build the kube-api-linter plugin
303+
$(KUBE_API_LINTER_PLUGIN): $(KUBE_API_LINTER_BUILD_DIR)/go.mod
304+
cd $(KUBE_API_LINTER_BUILD_DIR) && \
305+
go build -buildmode=plugin -o "$(abspath $(KUBE_API_LINTER_PLUGIN))" sigs.k8s.io/kube-api-linter/pkg/plugin
306+
$(KUBE_API_LINTER_BUILD_DIR)/go.mod:
307+
@echo "Setting up local module for kube-api-linter plugin..."
308+
mkdir -p $(KUBE_API_LINTER_BUILD_DIR)
309+
cd $(KUBE_API_LINTER_BUILD_DIR) && \
310+
go mod init local-kube-api-linter && \
311+
go get sigs.k8s.io/kube-api-linter@latest
312+
313+
297314
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
298315
# $1 - target path with name of binary
299316
# $2 - package url which can be installed

testdata/project-v4-multigroup/.golangci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ linters:
2626
rules:
2727
- name: comment-spacings
2828
- name: import-shadowing
29+
custom:
30+
kubeapilinter:
31+
path: "./bin/kube-api-linter.so"
32+
description: "Kube API Linter plugin"
33+
original-url: "sigs.k8s.io/kube-api-linter"
34+
settings:
35+
linters: { }
36+
lintersConfig: { }
2937
exclusions:
3038
generated: lax
3139
rules:
@@ -36,6 +44,9 @@ linters:
3644
- dupl
3745
- lll
3846
path: internal/*
47+
- path-except: "^api/"
48+
linters:
49+
- kubeapilinter
3950
paths:
4051
- third_party$
4152
- builtin$

testdata/project-v4-multigroup/Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
8585
@$(KIND) delete cluster --name $(KIND_CLUSTER)
8686

8787
.PHONY: lint
88-
lint: golangci-lint ## Run golangci-lint linter
88+
lint: golangci-lint kube-api-linter ## Run golangci-lint linter
8989
$(GOLANGCI_LINT) run
9090

9191
.PHONY: lint-fix
@@ -215,6 +215,23 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
215215
$(GOLANGCI_LINT): $(LOCALBIN)
216216
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
217217

218+
# Kube-API-Linter plugin
219+
KUBE_API_LINTER_PLUGIN := $(LOCALBIN)/kube-api-linter.so
220+
KUBE_API_LINTER_BUILD_DIR := ./hack/kube-api-linter
221+
222+
.PHONY: kube-api-linter
223+
kube-api-linter: $(KUBE_API_LINTER_PLUGIN) ## Build the kube-api-linter plugin
224+
$(KUBE_API_LINTER_PLUGIN): $(KUBE_API_LINTER_BUILD_DIR)/go.mod
225+
cd $(KUBE_API_LINTER_BUILD_DIR) && \
226+
go build -buildmode=plugin -o "$(abspath $(KUBE_API_LINTER_PLUGIN))" sigs.k8s.io/kube-api-linter/pkg/plugin
227+
$(KUBE_API_LINTER_BUILD_DIR)/go.mod:
228+
@echo "Setting up local module for kube-api-linter plugin..."
229+
mkdir -p $(KUBE_API_LINTER_BUILD_DIR)
230+
cd $(KUBE_API_LINTER_BUILD_DIR) && \
231+
go mod init local-kube-api-linter && \
232+
go get sigs.k8s.io/kube-api-linter@latest
233+
234+
218235
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
219236
# $1 - target path with name of binary
220237
# $2 - package url which can be installed

testdata/project-v4-with-plugins/.golangci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ linters:
2626
rules:
2727
- name: comment-spacings
2828
- name: import-shadowing
29+
custom:
30+
kubeapilinter:
31+
path: "./bin/kube-api-linter.so"
32+
description: "Kube API Linter plugin"
33+
original-url: "sigs.k8s.io/kube-api-linter"
34+
settings:
35+
linters: { }
36+
lintersConfig: { }
2937
exclusions:
3038
generated: lax
3139
rules:
@@ -36,6 +44,9 @@ linters:
3644
- dupl
3745
- lll
3846
path: internal/*
47+
- path-except: "^api/"
48+
linters:
49+
- kubeapilinter
3950
paths:
4051
- third_party$
4152
- builtin$

testdata/project-v4-with-plugins/Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
8585
@$(KIND) delete cluster --name $(KIND_CLUSTER)
8686

8787
.PHONY: lint
88-
lint: golangci-lint ## Run golangci-lint linter
88+
lint: golangci-lint kube-api-linter ## Run golangci-lint linter
8989
$(GOLANGCI_LINT) run
9090

9191
.PHONY: lint-fix
@@ -215,6 +215,23 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
215215
$(GOLANGCI_LINT): $(LOCALBIN)
216216
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
217217

218+
# Kube-API-Linter plugin
219+
KUBE_API_LINTER_PLUGIN := $(LOCALBIN)/kube-api-linter.so
220+
KUBE_API_LINTER_BUILD_DIR := ./hack/kube-api-linter
221+
222+
.PHONY: kube-api-linter
223+
kube-api-linter: $(KUBE_API_LINTER_PLUGIN) ## Build the kube-api-linter plugin
224+
$(KUBE_API_LINTER_PLUGIN): $(KUBE_API_LINTER_BUILD_DIR)/go.mod
225+
cd $(KUBE_API_LINTER_BUILD_DIR) && \
226+
go build -buildmode=plugin -o "$(abspath $(KUBE_API_LINTER_PLUGIN))" sigs.k8s.io/kube-api-linter/pkg/plugin
227+
$(KUBE_API_LINTER_BUILD_DIR)/go.mod:
228+
@echo "Setting up local module for kube-api-linter plugin..."
229+
mkdir -p $(KUBE_API_LINTER_BUILD_DIR)
230+
cd $(KUBE_API_LINTER_BUILD_DIR) && \
231+
go mod init local-kube-api-linter && \
232+
go get sigs.k8s.io/kube-api-linter@latest
233+
234+
218235
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
219236
# $1 - target path with name of binary
220237
# $2 - package url which can be installed

testdata/project-v4/.golangci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ linters:
2626
rules:
2727
- name: comment-spacings
2828
- name: import-shadowing
29+
custom:
30+
kubeapilinter:
31+
path: "./bin/kube-api-linter.so"
32+
description: "Kube API Linter plugin"
33+
original-url: "sigs.k8s.io/kube-api-linter"
34+
settings:
35+
linters: { }
36+
lintersConfig: { }
2937
exclusions:
3038
generated: lax
3139
rules:
@@ -36,6 +44,9 @@ linters:
3644
- dupl
3745
- lll
3846
path: internal/*
47+
- path-except: "^api/"
48+
linters:
49+
- kubeapilinter
3950
paths:
4051
- third_party$
4152
- builtin$

0 commit comments

Comments
 (0)