Skip to content

Commit 5e2d618

Browse files
committed
[golanci.yaml.tmpl] disable modernize omitzero plugin with controllergen
This plugin is breaking practically all kubernetes-operators that have CRDs. The CRDs are generated from golang types, where the omitempty tag for nested structs has an direct effect on the generated CRD - they just don't work without omitempty. ``` Error: api/v1/eviction_types.go:91:20: omitzero: Omitempty has no effect on nested struct fields (modernize) ```
1 parent 90760e5 commit 5e2d618

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

internal/golangcilint/golangci.yaml.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ linters:
154154
enable-all: true
155155
nolintlint:
156156
require-specific: true
157+
{{- if .WithControllerGen }}
158+
modernize:
159+
disable:
160+
# omitzero requires removing omitempty tags in kubernetes api struct types which are nested, which is intepreted by controller-gen and breaks the CRDs.
161+
- omitzero
162+
{{- end }}
157163
{{- if .MisspellIgnoreWords }}
158164
misspell:
159165
ignore-rules:

internal/golangcilint/golangci_lint.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ func RenderConfig(cfg core.Configuration, sr golang.ScanResult) {
3636
"SkipDirs": cfg.GolangciLint.SkipDirs,
3737
"Timeout": timeout,
3838
"ReviveRules": cfg.GolangciLint.ReviveRules,
39+
"WithControllerGen": cfg.ControllerGen.Enabled.UnwrapOr(sr.KubernetesController),
3940
}))
4041
}

0 commit comments

Comments
 (0)