Skip to content

Commit 3f964cb

Browse files
committed
ci: add kube-api-linter and fix doc and marker findings in api types
1 parent c1ab095 commit 3f964cb

12 files changed

Lines changed: 1476 additions & 111 deletions

File tree

.golangci-kal.yaml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Config for kube-api-linter (github.com/kubernetes-sigs/kube-api-linter),
16+
# run by hack/verify/kube-api-linter.sh against the API types in pkg/api/.
17+
# It is a separate file from .golangci.yaml because the kubeapilinter module
18+
# plugin only exists in the golangci-lint-kube-api-linter binary, not in the
19+
# regular golangci-lint one.
20+
21+
version: "2"
22+
23+
linters:
24+
default: none
25+
enable:
26+
- kubeapilinter
27+
28+
settings:
29+
custom:
30+
kubeapilinter:
31+
type: module
32+
description: Kubernetes API conventions linter.
33+
settings:
34+
# The enabled set below is the default set of the pinned linter
35+
# version, spelled out so the enforced rules are visible here.
36+
linters:
37+
enable:
38+
- "arrayofstruct" # Structs in arrays need at least one required field, to avoid ambiguous YAML.
39+
- "commentstart" # Field godocs must start with the serialized field name.
40+
- "conditions" # Conditions fields need the correct json tags and markers.
41+
- "defaultorrequired" # A field cannot have both a default and be required.
42+
- "defaults" # Default markers must use the preferred form (see lintersConfig).
43+
- "duplicatemarkers" # No exact duplicate markers on types and fields.
44+
- "integers" # Only int32 and int64 for integers.
45+
- "jsontags" # Every field needs a json tag.
46+
- "nodurations" # No Duration types.
47+
- "nofloats" # No float types.
48+
- "nomaps" # No map types (string-to-string maps allowed), use lists with a unique key.
49+
- "nonpointerstructs" # Non-pointer struct fields with no required fields must be optional.
50+
- "nonullable" # No nullable marker.
51+
- "nophase" # No phase fields, use conditions instead.
52+
- "noreferences" # Field names should use Ref rather than Reference.
53+
- "notimestamp" # No Timestamp fields, use Time.
54+
- "optionalfields" # Optional fields must be pointers/omitempty where appropriate.
55+
- "optionalorrequired" # Every field must be marked +optional or +required.
56+
- "requiredfields" # Required fields must not be pointers or have omitempty.
57+
- "ssatags" # Array fields need listType markers for Server-Side Apply.
58+
- "uniquemarkers" # Single-definition markers must not repeat.
59+
# Everything not listed above stays off until evaluated.
60+
disable:
61+
- "*"
62+
lintersConfig:
63+
conditions:
64+
# CRD types are not protobuf-serialized in this project.
65+
useProtobuf: Ignore
66+
defaults:
67+
# CRDs are generated with controller-gen, which reads
68+
# +kubebuilder:default.
69+
preferredDefaultMarker: kubebuilder:default
70+
71+
exclusions:
72+
rules:
73+
# Pre-existing findings from rules that require Go API changes
74+
# (pointer fields, omitempty/omitzero tags, map-to-list refactors)
75+
# on the existing v1alpha1 types. Excluded here per file rather than
76+
# disabling the rules, so new API files are still checked. Fixing
77+
# these on the existing types is tracked in issue #207.
78+
- path: 'pkg/api/v1alpha1/(actortemplate|sandboxconfig|workerpool)_types\.go'
79+
text: '^(nomaps|nonpointerstructs|nophase|optionalfields|requiredfields|ssatags):'
80+
81+
issues:
82+
max-issues-per-linter: 0
83+
max-same-issues: 0

hack/run-tool.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ case "${TOOL_NAME}" in
3535
"client-gen"|"informer-gen"|"lister-gen")
3636
TOOL_DIR="${ROOT}/hack/tools/code-generator"
3737
;;
38+
"golangci-lint-kube-api-linter")
39+
TOOL_DIR="${ROOT}/hack/tools/kube-api-linter"
40+
;;
3841
*)
3942
TOOL_DIR="${ROOT}/hack/tools/${TOOL_NAME}"
4043
;;

hack/tools/kube-api-linter/go.mod

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
module github.com/agent-substrate/substrate/hack/tools/kube-api-linter
2+
3+
go 1.26.2
4+
5+
tool sigs.k8s.io/kube-api-linter/cmd/golangci-lint-kube-api-linter
6+
7+
require (
8+
4d63.com/gocheckcompilerdirectives v1.3.0 // indirect
9+
4d63.com/gochecknoglobals v0.2.2 // indirect
10+
codeberg.org/chavacava/garif v0.2.0 // indirect
11+
dev.gaijin.team/go/exhaustruct/v4 v4.0.0 // indirect
12+
dev.gaijin.team/go/golib v0.6.0 // indirect
13+
github.com/4meepo/tagalign v1.4.3 // indirect
14+
github.com/Abirdcfly/dupword v0.1.6 // indirect
15+
github.com/AdminBenni/iota-mixing v1.0.0 // indirect
16+
github.com/AlwxSin/noinlineerr v1.0.5 // indirect
17+
github.com/Antonboom/errname v1.1.1 // indirect
18+
github.com/Antonboom/nilnil v1.1.1 // indirect
19+
github.com/Antonboom/testifylint v1.6.4 // indirect
20+
github.com/BurntSushi/toml v1.5.0 // indirect
21+
github.com/Djarvur/go-err113 v0.1.1 // indirect
22+
github.com/Masterminds/semver/v3 v3.3.1 // indirect
23+
github.com/MirrexOne/unqueryvet v1.2.1 // indirect
24+
github.com/OpenPeeDeeP/depguard/v2 v2.2.1 // indirect
25+
github.com/alecthomas/chroma/v2 v2.20.0 // indirect
26+
github.com/alecthomas/go-check-sumtype v0.3.1 // indirect
27+
github.com/alexkohler/nakedret/v2 v2.0.6 // indirect
28+
github.com/alexkohler/prealloc v1.0.0 // indirect
29+
github.com/alfatraining/structtag v1.0.0 // indirect
30+
github.com/alingse/asasalint v0.0.11 // indirect
31+
github.com/alingse/nilnesserr v0.2.0 // indirect
32+
github.com/ashanbrown/forbidigo/v2 v2.1.0 // indirect
33+
github.com/ashanbrown/makezero/v2 v2.0.1 // indirect
34+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
35+
github.com/beorn7/perks v1.0.1 // indirect
36+
github.com/bkielbasa/cyclop v1.2.3 // indirect
37+
github.com/blizzy78/varnamelen v0.8.0 // indirect
38+
github.com/bombsimon/wsl/v4 v4.7.0 // indirect
39+
github.com/bombsimon/wsl/v5 v5.2.0 // indirect
40+
github.com/breml/bidichk v0.3.3 // indirect
41+
github.com/breml/errchkjson v0.4.1 // indirect
42+
github.com/butuzov/ireturn v0.4.0 // indirect
43+
github.com/butuzov/mirror v1.3.0 // indirect
44+
github.com/catenacyber/perfsprint v0.9.1 // indirect
45+
github.com/ccojocar/zxcvbn-go v1.0.4 // indirect
46+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
47+
github.com/charithe/durationcheck v0.0.10 // indirect
48+
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
49+
github.com/charmbracelet/lipgloss v1.1.0 // indirect
50+
github.com/charmbracelet/x/ansi v0.8.0 // indirect
51+
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
52+
github.com/charmbracelet/x/term v0.2.1 // indirect
53+
github.com/ckaznocha/intrange v0.3.1 // indirect
54+
github.com/curioswitch/go-reassign v0.3.0 // indirect
55+
github.com/daixiang0/gci v0.13.7 // indirect
56+
github.com/dave/dst v0.27.3 // indirect
57+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
58+
github.com/denis-tingaikin/go-header v0.5.0 // indirect
59+
github.com/dlclark/regexp2 v1.11.5 // indirect
60+
github.com/ettle/strcase v0.2.0 // indirect
61+
github.com/fatih/color v1.18.0 // indirect
62+
github.com/fatih/structtag v1.2.0 // indirect
63+
github.com/firefart/nonamedreturns v1.0.6 // indirect
64+
github.com/fsnotify/fsnotify v1.5.4 // indirect
65+
github.com/fzipp/gocyclo v0.6.0 // indirect
66+
github.com/ghostiam/protogetter v0.3.16 // indirect
67+
github.com/go-critic/go-critic v0.13.0 // indirect
68+
github.com/go-toolsmith/astcast v1.1.0 // indirect
69+
github.com/go-toolsmith/astcopy v1.1.0 // indirect
70+
github.com/go-toolsmith/astequal v1.2.0 // indirect
71+
github.com/go-toolsmith/astfmt v1.1.0 // indirect
72+
github.com/go-toolsmith/astp v1.1.0 // indirect
73+
github.com/go-toolsmith/strparse v1.1.0 // indirect
74+
github.com/go-toolsmith/typep v1.1.0 // indirect
75+
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
76+
github.com/go-xmlfmt/xmlfmt v1.1.3 // indirect
77+
github.com/gobwas/glob v0.2.3 // indirect
78+
github.com/godoc-lint/godoc-lint v0.10.0 // indirect
79+
github.com/gofrs/flock v0.12.1 // indirect
80+
github.com/golang/protobuf v1.5.4 // indirect
81+
github.com/golangci/asciicheck v0.5.0 // indirect
82+
github.com/golangci/dupl v0.0.0-20250308024227-f665c8d69b32 // indirect
83+
github.com/golangci/go-printf-func-name v0.1.1 // indirect
84+
github.com/golangci/gofmt v0.0.0-20250106114630-d62b90e6713d // indirect
85+
github.com/golangci/golangci-lint/v2 v2.5.0 // indirect
86+
github.com/golangci/golines v0.0.0-20250217134842-442fd0091d95 // indirect
87+
github.com/golangci/misspell v0.7.0 // indirect
88+
github.com/golangci/nilerr v0.0.0-20250918000102-015671e622fe // indirect
89+
github.com/golangci/plugin-module-register v0.1.2 // indirect
90+
github.com/golangci/revgrep v0.8.0 // indirect
91+
github.com/golangci/swaggoswag v0.0.0-20250504205917-77f2aca3143e // indirect
92+
github.com/golangci/unconvert v0.0.0-20250410112200-a129a6e6413e // indirect
93+
github.com/google/go-cmp v0.7.0 // indirect
94+
github.com/gordonklaus/ineffassign v0.2.0 // indirect
95+
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
96+
github.com/gostaticanalysis/comment v1.5.0 // indirect
97+
github.com/gostaticanalysis/forcetypeassert v0.2.0 // indirect
98+
github.com/hashicorp/go-immutable-radix/v2 v2.1.0 // indirect
99+
github.com/hashicorp/go-version v1.7.0 // indirect
100+
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
101+
github.com/hashicorp/hcl v1.0.0 // indirect
102+
github.com/hexops/gotextdiff v1.0.3 // indirect
103+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
104+
github.com/jgautheron/goconst v1.8.2 // indirect
105+
github.com/jingyugao/rowserrcheck v1.1.1 // indirect
106+
github.com/jjti/go-spancheck v0.6.5 // indirect
107+
github.com/julz/importas v0.2.0 // indirect
108+
github.com/karamaru-alpha/copyloopvar v1.2.1 // indirect
109+
github.com/kisielk/errcheck v1.9.0 // indirect
110+
github.com/kkHAIKE/contextcheck v1.1.6 // indirect
111+
github.com/kulti/thelper v0.7.1 // indirect
112+
github.com/kunwardeep/paralleltest v1.0.14 // indirect
113+
github.com/lasiar/canonicalheader v1.1.2 // indirect
114+
github.com/ldez/exptostd v0.4.4 // indirect
115+
github.com/ldez/gomoddirectives v0.7.0 // indirect
116+
github.com/ldez/grignotin v0.10.1 // indirect
117+
github.com/ldez/tagliatelle v0.7.2 // indirect
118+
github.com/ldez/usetesting v0.5.0 // indirect
119+
github.com/leonklingele/grouper v1.1.2 // indirect
120+
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
121+
github.com/macabu/inamedparam v0.2.0 // indirect
122+
github.com/magiconair/properties v1.8.6 // indirect
123+
github.com/manuelarte/embeddedstructfieldcheck v0.4.0 // indirect
124+
github.com/manuelarte/funcorder v0.5.0 // indirect
125+
github.com/maratori/testableexamples v1.0.0 // indirect
126+
github.com/maratori/testpackage v1.1.1 // indirect
127+
github.com/matoous/godox v1.1.0 // indirect
128+
github.com/mattn/go-colorable v0.1.14 // indirect
129+
github.com/mattn/go-isatty v0.0.20 // indirect
130+
github.com/mattn/go-runewidth v0.0.16 // indirect
131+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
132+
github.com/mgechev/revive v1.12.0 // indirect
133+
github.com/mitchellh/go-homedir v1.1.0 // indirect
134+
github.com/mitchellh/mapstructure v1.5.0 // indirect
135+
github.com/moricho/tparallel v0.3.2 // indirect
136+
github.com/muesli/termenv v0.16.0 // indirect
137+
github.com/nakabonne/nestif v0.3.1 // indirect
138+
github.com/nishanths/exhaustive v0.12.0 // indirect
139+
github.com/nishanths/predeclared v0.2.2 // indirect
140+
github.com/nunnatsa/ginkgolinter v0.21.0 // indirect
141+
github.com/pelletier/go-toml v1.9.5 // indirect
142+
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
143+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
144+
github.com/polyfloyd/go-errorlint v1.8.0 // indirect
145+
github.com/prometheus/client_golang v1.12.1 // indirect
146+
github.com/prometheus/client_model v0.2.0 // indirect
147+
github.com/prometheus/common v0.32.1 // indirect
148+
github.com/prometheus/procfs v0.7.3 // indirect
149+
github.com/quasilyte/go-ruleguard v0.4.4 // indirect
150+
github.com/quasilyte/go-ruleguard/dsl v0.3.22 // indirect
151+
github.com/quasilyte/gogrep v0.5.0 // indirect
152+
github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 // indirect
153+
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
154+
github.com/raeperd/recvcheck v0.2.0 // indirect
155+
github.com/rivo/uniseg v0.4.7 // indirect
156+
github.com/rogpeppe/go-internal v1.14.1 // indirect
157+
github.com/ryancurrah/gomodguard v1.4.1 // indirect
158+
github.com/ryanrolds/sqlclosecheck v0.5.1 // indirect
159+
github.com/sanposhiho/wastedassign/v2 v2.1.0 // indirect
160+
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 // indirect
161+
github.com/sashamelentyev/interfacebloat v1.1.0 // indirect
162+
github.com/sashamelentyev/usestdlibvars v1.29.0 // indirect
163+
github.com/securego/gosec/v2 v2.22.8 // indirect
164+
github.com/sirupsen/logrus v1.9.3 // indirect
165+
github.com/sivchari/containedctx v1.0.3 // indirect
166+
github.com/sonatard/noctx v0.4.0 // indirect
167+
github.com/sourcegraph/go-diff v0.7.0 // indirect
168+
github.com/spf13/afero v1.14.0 // indirect
169+
github.com/spf13/cast v1.5.0 // indirect
170+
github.com/spf13/cobra v1.10.1 // indirect
171+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
172+
github.com/spf13/pflag v1.0.10 // indirect
173+
github.com/spf13/viper v1.12.0 // indirect
174+
github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect
175+
github.com/stbenjam/no-sprintf-host-port v0.2.0 // indirect
176+
github.com/stretchr/objx v0.5.2 // indirect
177+
github.com/stretchr/testify v1.11.1 // indirect
178+
github.com/subosito/gotenv v1.4.1 // indirect
179+
github.com/tetafro/godot v1.5.4 // indirect
180+
github.com/timakin/bodyclose v0.0.0-20241222091800-1db5c5ca4d67 // indirect
181+
github.com/timonwong/loggercheck v0.11.0 // indirect
182+
github.com/tomarrell/wrapcheck/v2 v2.11.0 // indirect
183+
github.com/tommy-muehle/go-mnd/v2 v2.5.1 // indirect
184+
github.com/ultraware/funlen v0.2.0 // indirect
185+
github.com/ultraware/whitespace v0.2.0 // indirect
186+
github.com/uudashr/gocognit v1.2.0 // indirect
187+
github.com/uudashr/iface v1.4.1 // indirect
188+
github.com/xen0n/gosmopolitan v1.3.0 // indirect
189+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
190+
github.com/yagipy/maintidx v1.0.0 // indirect
191+
github.com/yeya24/promlinter v0.3.0 // indirect
192+
github.com/ykadowak/zerologlint v0.1.5 // indirect
193+
gitlab.com/bosi/decorder v0.4.2 // indirect
194+
go-simpler.org/musttag v0.14.0 // indirect
195+
go-simpler.org/sloglint v0.11.1 // indirect
196+
go.augendre.info/arangolint v0.2.0 // indirect
197+
go.augendre.info/fatcontext v0.8.1 // indirect
198+
go.uber.org/automaxprocs v1.6.0 // indirect
199+
go.uber.org/multierr v1.10.0 // indirect
200+
go.uber.org/zap v1.27.0 // indirect
201+
golang.org/x/exp/typeparams v0.0.0-20250911091902-df9299821621 // indirect
202+
golang.org/x/mod v0.28.0 // indirect
203+
golang.org/x/sync v0.17.0 // indirect
204+
golang.org/x/sys v0.36.0 // indirect
205+
golang.org/x/text v0.29.0 // indirect
206+
golang.org/x/tools v0.37.0 // indirect
207+
google.golang.org/protobuf v1.36.6 // indirect
208+
gopkg.in/ini.v1 v1.67.0 // indirect
209+
gopkg.in/yaml.v2 v2.4.0 // indirect
210+
gopkg.in/yaml.v3 v3.0.1 // indirect
211+
honnef.co/go/tools v0.6.1 // indirect
212+
k8s.io/apimachinery v0.32.3 // indirect
213+
k8s.io/gengo/v2 v2.0.0-20250922181213-ec3ebc5fd46b // indirect
214+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
215+
mvdan.cc/gofumpt v0.9.1 // indirect
216+
mvdan.cc/unparam v0.0.0-20250301125049-0df0534333a4 // indirect
217+
sigs.k8s.io/kube-api-linter v0.0.0-20260518104151-5ebe05f9440b // indirect
218+
sigs.k8s.io/yaml v1.4.0 // indirect
219+
)

0 commit comments

Comments
 (0)