Skip to content

Commit faa4c72

Browse files
Add KAL and fix missing parts from tutorials
1 parent cf5dbb3 commit faa4c72

File tree

40 files changed

+297
-28
lines changed

40 files changed

+297
-28
lines changed

.github/workflows/lint-sample.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ jobs:
3333
- name: Prepare ${{ matrix.folder }}
3434
working-directory: ${{ matrix.folder }}
3535
run: go mod tidy
36+
- name: Build kubeapilinter
37+
working-directory: ${{ matrix.folder }}
38+
run: make kube-api-linter
39+
env:
40+
CGO_ENABLED: 1
3641
- name: Check linter configuration
3742
working-directory: ${{ matrix.folder }}
3843
run: make lint-config
@@ -41,6 +46,7 @@ jobs:
4146
with:
4247
version: v2.1.6
4348
working-directory: ${{ matrix.folder }}
49+
install-mode: goinstall
4450
- name: Run linter via makefile target
4551
working-directory: ${{ matrix.folder }}
4652
run: make lint

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ jobs:
2121
uses: golangci/golangci-lint-action@v8
2222
with:
2323
version: v2.1.6
24+
install-mode: goinstall

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,20 @@ linters:
2121
- unconvert
2222
- unparam
2323
- unused
24+
- kubeapilinter
2425
settings:
2526
revive:
2627
rules:
2728
- name: comment-spacings
2829
- name: import-shadowing
30+
custom:
31+
kubeapilinter:
32+
path: "./bin/kube-api-linter.so"
33+
description: "Kube API Linter plugin"
34+
original-url: "sigs.k8s.io/kube-api-linter"
35+
settings:
36+
linters: { }
37+
lintersConfig: { }
2938
exclusions:
3039
generated: lax
3140
rules:
@@ -36,6 +45,9 @@ linters:
3645
- dupl
3746
- lll
3847
path: internal/*
48+
- path-except: "^api/"
49+
linters:
50+
- kubeapilinter
3951
paths:
4052
- third_party$
4153
- builtin$

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

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

9797
.PHONY: lint
98-
lint: golangci-lint ## Run golangci-lint linter
98+
lint: golangci-lint kube-api-linter ## Run golangci-lint linter
9999
$(GOLANGCI_LINT) run
100100

101101
.PHONY: lint-fix
@@ -225,6 +225,23 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
225225
$(GOLANGCI_LINT): $(LOCALBIN)
226226
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
227227

228+
# To lint Kubernetes API definitions.
229+
# More info: https://github.com/kubernetes-sigs/kube-api-linter
230+
KUBE_API_LINTER_PLUGIN := $(LOCALBIN)/kube-api-linter.so
231+
KUBE_API_LINTER_BUILD_DIR := ./hack/kube-api-linter
232+
233+
.PHONY: kube-api-linter
234+
kube-api-linter: $(KUBE_API_LINTER_PLUGIN) ## Build the kube-api-linter plugin
235+
$(KUBE_API_LINTER_PLUGIN): $(KUBE_API_LINTER_BUILD_DIR)/go.mod
236+
cd $(KUBE_API_LINTER_BUILD_DIR) && \
237+
go build -buildmode=plugin -o "$(abspath $(KUBE_API_LINTER_PLUGIN))" sigs.k8s.io/kube-api-linter/pkg/plugin
238+
$(KUBE_API_LINTER_BUILD_DIR)/go.mod:
239+
@echo "Setting up local module for kube-api-linter plugin..."
240+
mkdir -p $(KUBE_API_LINTER_BUILD_DIR)
241+
cd $(KUBE_API_LINTER_BUILD_DIR) && \
242+
go mod init local-kube-api-linter && \
243+
go get sigs.k8s.io/kube-api-linter@latest
244+
228245
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
229246
# $1 - target path with name of binary
230247
# $2 - package url which can be installed

docs/book/src/cronjob-tutorial/testdata/project/api/v1/cronjob_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ type CronJobSpec struct {
8181
// - "Forbid": forbids concurrent runs, skipping next run if previous run hasn't finished yet;
8282
// - "Replace": cancels currently running job and replaces it with a new one
8383
// +optional
84+
// +kubebuilder:default:=Allow
8485
ConcurrencyPolicy ConcurrencyPolicy `json:"concurrencyPolicy,omitempty"`
8586

8687
// suspend tells the controller to suspend subsequent executions, it does
@@ -89,6 +90,7 @@ type CronJobSpec struct {
8990
Suspend *bool `json:"suspend,omitempty"`
9091

9192
// jobTemplate defines the job that will be created when executing a CronJob.
93+
// +required
9294
JobTemplate batchv1.JobTemplateSpec `json:"jobTemplate"`
9395

9496
// successfulJobsHistoryLimit defines the number of successful finished jobs to retain.

docs/book/src/cronjob-tutorial/testdata/project/config/crd/bases/batch.tutorial.kubebuilder.io_cronjobs.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ spec:
2727
spec:
2828
properties:
2929
concurrencyPolicy:
30+
default: Allow
3031
enum:
3132
- Allow
3233
- Forbid

docs/book/src/cronjob-tutorial/testdata/project/dist/chart/templates/crd/batch.tutorial.kubebuilder.io_cronjobs.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ spec:
3333
spec:
3434
properties:
3535
concurrencyPolicy:
36+
default: Allow
3637
enum:
3738
- Allow
3839
- Forbid

docs/book/src/cronjob-tutorial/testdata/project/dist/install.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ spec:
3535
spec:
3636
properties:
3737
concurrencyPolicy:
38+
default: Allow
3839
enum:
3940
- Allow
4041
- Forbid

docs/book/src/cronjob-tutorial/testdata/project/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
k8s.io/api v0.33.0
1010
k8s.io/apimachinery v0.33.0
1111
k8s.io/client-go v0.33.0
12+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
1213
sigs.k8s.io/controller-runtime v0.21.0
1314
)
1415

@@ -89,7 +90,6 @@ require (
8990
k8s.io/component-base v0.33.0 // indirect
9091
k8s.io/klog/v2 v2.130.1 // indirect
9192
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
92-
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
9393
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 // indirect
9494
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
9595
sigs.k8s.io/randfill v1.0.0 // indirect

docs/book/src/cronjob-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
batchv1 "tutorial.kubebuilder.io/project/api/v1"
2424
// TODO (user): Add any additional imports if needed
25+
"k8s.io/utils/ptr"
2526
)
2627

2728
var _ = Describe("CronJob Webhook", func() {
@@ -40,8 +41,8 @@ var _ = Describe("CronJob Webhook", func() {
4041
Spec: batchv1.CronJobSpec{
4142
Schedule: schedule,
4243
ConcurrencyPolicy: batchv1.AllowConcurrent,
43-
SuccessfulJobsHistoryLimit: new(int32),
44-
FailedJobsHistoryLimit: new(int32),
44+
SuccessfulJobsHistoryLimit: ptr.To(int32(3)),
45+
FailedJobsHistoryLimit: ptr.To(int32(1)),
4546
},
4647
}
4748
*obj.Spec.SuccessfulJobsHistoryLimit = 3
@@ -51,8 +52,8 @@ var _ = Describe("CronJob Webhook", func() {
5152
Spec: batchv1.CronJobSpec{
5253
Schedule: schedule,
5354
ConcurrencyPolicy: batchv1.AllowConcurrent,
54-
SuccessfulJobsHistoryLimit: new(int32),
55-
FailedJobsHistoryLimit: new(int32),
55+
SuccessfulJobsHistoryLimit: ptr.To(int32(3)),
56+
FailedJobsHistoryLimit: ptr.To(int32(1)),
5657
},
5758
}
5859
*oldObj.Spec.SuccessfulJobsHistoryLimit = 3

0 commit comments

Comments
 (0)