Skip to content

Commit ca3b542

Browse files
(go/v4): Add kubeapilinter to the default scaffold
1 parent 659b14e commit ca3b542

File tree

29 files changed

+335
-21
lines changed

29 files changed

+335
-21
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: v2.7.2
2+
name: golangci-lint-kube-api
3+
destination: ./bin
4+
5+
plugins:
6+
- module: sigs.k8s.io/kube-api-linter
7+
version: latest

docs/book/src/cronjob-tutorial/testdata/project/.github/workflows/lint.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ jobs:
1717
with:
1818
go-version-file: go.mod
1919

20+
- name: Check linter configuration
21+
run: make lint-config
22+
2023
- name: Run linter
2124
uses: golangci/golangci-lint-action@v8
2225
with:
2326
version: v2.7.2
27+
28+
- name: Run lint target
29+
run: make lint

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ linters:
2222
- unconvert
2323
- unparam
2424
- unused
25+
- kubeapilinter
2526
settings:
2627
revive:
2728
rules:
@@ -30,6 +31,17 @@ linters:
3031
modernize:
3132
disable:
3233
- omitzero
34+
custom:
35+
kubeapilinter:
36+
type: module
37+
description: "Kube API Linter plugin"
38+
original-url: "sigs.k8s.io/kube-api-linter"
39+
settings:
40+
linters: {}
41+
lintersConfig:
42+
optionalfields:
43+
pointers:
44+
preference: WhenRequired
3345
exclusions:
3446
generated: lax
3547
rules:
@@ -40,6 +52,9 @@ linters:
4052
- dupl
4153
- lll
4254
path: internal/*
55+
- path-except: "^api/"
56+
linters:
57+
- kubeapilinter
4358
paths:
4459
- third_party$
4560
- builtin$

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ KIND ?= kind
188188
KUSTOMIZE ?= $(LOCALBIN)/kustomize
189189
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
190190
ENVTEST ?= $(LOCALBIN)/setup-envtest
191-
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
191+
GOLANGCI_LINT_BASE = $(LOCALBIN)/golangci-lint
192+
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-kube-api
192193

193194
## Tool Versions
194195
KUSTOMIZE_VERSION ?= v5.7.1
@@ -230,8 +231,17 @@ $(ENVTEST): $(LOCALBIN)
230231

231232
.PHONY: golangci-lint
232233
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
233-
$(GOLANGCI_LINT): $(LOCALBIN)
234-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
234+
235+
$(GOLANGCI_LINT_BASE): $(LOCALBIN)
236+
$(call go-install-tool,$(GOLANGCI_LINT_BASE),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
237+
238+
$(GOLANGCI_LINT): $(GOLANGCI_LINT_BASE) .custom-gcl.yml
239+
@echo "Running golangci-lint custom..."
240+
@$(GOLANGCI_LINT_BASE) custom || { \
241+
echo "golangci-lint failed. Cleaning up..."; \
242+
rm -f $(GOLANGCI_LINT_BASE); \
243+
exit 1; \
244+
}
235245

236246
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
237247
# $1 - target path with name of binary
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: v2.7.2
2+
name: golangci-lint-kube-api
3+
destination: ./bin
4+
5+
plugins:
6+
- module: sigs.k8s.io/kube-api-linter
7+
version: latest

docs/book/src/getting-started/testdata/project/.github/workflows/lint.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ jobs:
1717
with:
1818
go-version-file: go.mod
1919

20+
- name: Check linter configuration
21+
run: make lint-config
22+
2023
- name: Run linter
2124
uses: golangci/golangci-lint-action@v8
2225
with:
2326
version: v2.7.2
27+
28+
- name: Run lint target
29+
run: make lint

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ linters:
2222
- unconvert
2323
- unparam
2424
- unused
25+
- kubeapilinter
2526
settings:
2627
revive:
2728
rules:
@@ -30,6 +31,17 @@ linters:
3031
modernize:
3132
disable:
3233
- omitzero
34+
custom:
35+
kubeapilinter:
36+
type: module
37+
description: "Kube API Linter plugin"
38+
original-url: "sigs.k8s.io/kube-api-linter"
39+
settings:
40+
linters: {}
41+
lintersConfig:
42+
optionalfields:
43+
pointers:
44+
preference: WhenRequired
3345
exclusions:
3446
generated: lax
3547
rules:
@@ -40,6 +52,9 @@ linters:
4052
- dupl
4153
- lll
4254
path: internal/*
55+
- path-except: "^api/"
56+
linters:
57+
- kubeapilinter
4358
paths:
4459
- third_party$
4560
- builtin$

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ KIND ?= kind
184184
KUSTOMIZE ?= $(LOCALBIN)/kustomize
185185
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
186186
ENVTEST ?= $(LOCALBIN)/setup-envtest
187-
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
187+
GOLANGCI_LINT_BASE = $(LOCALBIN)/golangci-lint
188+
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-kube-api
188189

189190
## Tool Versions
190191
KUSTOMIZE_VERSION ?= v5.7.1
@@ -226,8 +227,17 @@ $(ENVTEST): $(LOCALBIN)
226227

227228
.PHONY: golangci-lint
228229
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
229-
$(GOLANGCI_LINT): $(LOCALBIN)
230-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
230+
231+
$(GOLANGCI_LINT_BASE): $(LOCALBIN)
232+
$(call go-install-tool,$(GOLANGCI_LINT_BASE),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
233+
234+
$(GOLANGCI_LINT): $(GOLANGCI_LINT_BASE) .custom-gcl.yml
235+
@echo "Running golangci-lint custom..."
236+
@$(GOLANGCI_LINT_BASE) custom || { \
237+
echo "golangci-lint failed. Cleaning up..."; \
238+
rm -f $(GOLANGCI_LINT_BASE); \
239+
exit 1; \
240+
}
231241

232242
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
233243
# $1 - target path with name of binary
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: v2.7.2
2+
name: golangci-lint-kube-api
3+
destination: ./bin
4+
5+
plugins:
6+
- module: sigs.k8s.io/kube-api-linter
7+
version: latest

docs/book/src/multiversion-tutorial/testdata/project/.github/workflows/lint.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ jobs:
1717
with:
1818
go-version-file: go.mod
1919

20+
- name: Check linter configuration
21+
run: make lint-config
22+
2023
- name: Run linter
2124
uses: golangci/golangci-lint-action@v8
2225
with:
2326
version: v2.7.2
27+
28+
- name: Run lint target
29+
run: make lint

0 commit comments

Comments
 (0)