|
| 1 | +version: "2" |
1 | 2 | run: |
2 | | - timeout: 10m |
3 | 3 | go: "1.23" |
4 | 4 | allow-parallel-runners: true |
5 | | - |
6 | 5 | linters: |
7 | | - disable-all: true |
| 6 | + default: none |
8 | 7 | enable: |
9 | 8 | - kubeapilinter # linter for Kube API conventions |
10 | | - |
11 | | -linters-settings: |
12 | | - custom: |
13 | | - kubeapilinter: |
14 | | - type: "module" |
15 | | - description: kube-api-linter and lints Kube like APIs based on API conventions and best practices. |
16 | | - settings: |
17 | | - linters: |
18 | | - enable: |
19 | | - - "commentstart" # Ensure comments start with the serialized version of the field name. |
20 | | - - "conditions" # Ensure conditions have the correct json tags and markers. |
21 | | - - "integers" # Ensure only int32 and int64 are used for integers. |
22 | | - - "jsontags" # Ensure every field has a json tag. |
23 | | - - "maxlength" # Ensure all strings and arrays have maximum lengths/maximum items. |
24 | | - - "nobools" # Bools do not evolve over time, should use enums instead. |
25 | | - - "nofloats" # Ensure floats are not used. |
26 | | - - "optionalorrequired" # Every field should be marked as `+optional` or `+required`. |
27 | | - - "requiredfields" # Required fields should not be pointers, and should not have `omitempty`. |
28 | | - - "statussubresource" # All root objects that have a `status` field should have a status subresource. |
| 9 | + settings: |
| 10 | + custom: |
| 11 | + kubeapilinter: |
| 12 | + type: module |
| 13 | + description: KAL is the Kube-API-Linter and lints Kube like APIs based on API conventions and best practices. |
| 14 | + settings: |
| 15 | + linters: |
| 16 | + enable: |
| 17 | + - "commentstart" # Ensure comments start with the serialized version of the field name. |
| 18 | + - "conditions" # Ensure conditions have the correct json tags and markers. |
| 19 | + - "integers" # Ensure only int32 and int64 are used for integers. |
| 20 | + - "jsontags" # Ensure every field has a json tag. |
| 21 | + - "maxlength" # Ensure all strings and arrays have maximum lengths/maximum items. |
| 22 | + - "nobools" # Bools do not evolve over time, should use enums instead. |
| 23 | + - "nofloats" # Ensure floats are not used. |
| 24 | + - "optionalorrequired" # Every field should be marked as `+optional` or `+required`. |
| 25 | + - "requiredfields" # Required fields should not be pointers, and should not have `omitempty`. |
| 26 | + - "statussubresource" # All root objects that have a `status` field should have a status subresource. |
| 27 | + |
| 28 | + # Per discussion in July 2024, we are keeping phase fields for now. |
| 29 | + # See https://github.com/kubernetes-sigs/cluster-api/pull/10897#discussion_r1685929508 |
| 30 | + # and https://github.com/kubernetes-sigs/cluster-api/pull/10897#discussion_r1685919394. |
| 31 | + # - "nophase" # Phase fields are discouraged by the Kube API conventions, use conditions instead. |
29 | 32 |
|
30 | | - # Per discussion in July 2024, we are keeping phase fields for now. |
31 | | - # See https://github.com/kubernetes-sigs/cluster-api/pull/10897#discussion_r1685929508 |
32 | | - # and https://github.com/kubernetes-sigs/cluster-api/pull/10897#discussion_r1685919394. |
33 | | - # - "nophase" # Phase fields are discouraged by the Kube API conventions, use conditions instead. |
34 | | - |
35 | | - # Linters below this line are disabled, pending conversation on how and when to enable them. |
36 | | - disable: |
37 | | - - "*" # We will manually enable new linters after understanding the impact. Disable all by default. |
38 | | - lintersConfig: |
39 | | - conditions: |
40 | | - isFirstField: Warn # Require conditions to be the first field in the status struct. |
41 | | - usePatchStrategy: Forbid # Conditions should not use the patch strategy on CRDs. |
42 | | - useProtobuf: Forbid # We don't use protobuf, so protobuf tags are not required. |
43 | | - # jsonTags: |
44 | | - # jsonTagRegex: "^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$" # The default regex is appropriate for our use case. |
45 | | - # optionalOrRequired: |
46 | | - # preferredOptionalMarker: optional | kubebuilder:validation:Optional # The preferred optional marker to use, fixes will suggest to use this marker. Defaults to `optional`. |
47 | | - # preferredRequiredMarker: required | kubebuilder:validation:Required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`. |
48 | | - # requiredFields: |
49 | | - # pointerPolicy: Warn | SuggestFix # Defaults to `SuggestFix`. We want our required fields to not be pointers. |
| 33 | + # Linters below this line are disabled, pending conversation on how and when to enable them. |
| 34 | + disable: |
| 35 | + - "*" # We will manually enable new linters after understanding the impact. Disable all by default. |
| 36 | + lintersConfig: |
| 37 | + conditions: |
| 38 | + isFirstField: Warn # Require conditions to be the first field in the status struct. |
| 39 | + usePatchStrategy: Forbid # Require conditions to be the first field in the status struct. |
| 40 | + useProtobuf: Forbid # We don't use protobuf, so protobuf tags are not required. |
| 41 | + # jsonTags: |
| 42 | + # jsonTagRegex: "^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$" # The default regex is appropriate for our use case. |
| 43 | + # optionalOrRequired: |
| 44 | + # preferredOptionalMarker: optional | kubebuilder:validation:Optional # The preferred optional marker to use, fixes will suggest to use this marker. Defaults to `optional`. |
| 45 | + # preferredRequiredMarker: required | kubebuilder:validation:Required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`. |
| 46 | + # requiredFields: |
| 47 | + # pointerPolicy: Warn | SuggestFix # Defaults to `SuggestFix`. We want our required fields to not be pointers. |
50 | 48 |
|
| 49 | + exclusions: |
| 50 | + generated: strict |
| 51 | + paths: |
| 52 | + - zz_generated.*\.go$ |
| 53 | + - vendored_openapi\.go$ |
| 54 | + # We don't want to invest time to fix new linter findings in old API types. |
| 55 | + - internal/apis/.* |
| 56 | + - ".*_test.go" # Exclude test files. |
| 57 | + rules: |
| 58 | + # KAL should only run on API folders. |
| 59 | + - path-except: "api//*" |
| 60 | + linters: |
| 61 | + - kubeapilinter |
| 62 | + - path: "api/v1beta2/*|api/addons/v1beta2/*|api/v1beta1/*|api/v1alpha1/*|api/addons/v1beta1/*" |
| 63 | + text: "Conditions field must be a slice of metav1.Condition" |
| 64 | + linters: |
| 65 | + - kubeapilinter |
| 66 | + - path: "api/v1beta2/*|api/v1beta1/*" |
| 67 | + text: "type ClusterIPFamily should not use an int, int8 or int16. Use int32 or int64 depending on bounding requirements" |
| 68 | + linters: |
| 69 | + - kubeapilinter |
| 70 | + - path: "exp/ipam/api/v1beta2/*|exp/ipam/api/v1alpha1/*|exp/ipam/api/v1beta1/*" |
| 71 | + text: "field Prefix should not use an int, int8 or int16. Use int32 or int64 depending on bounding requirements" |
| 72 | + linters: |
| 73 | + - kubeapilinter |
| 74 | + # clusterctl and Runtime Hooks can be fixed once we bump their apiVersion. |
| 75 | + - path: "cmd/clusterctl/api/v1alpha3|exp/runtime/hooks/api/v1alpha1" |
| 76 | + text: "maxlength" |
| 77 | + linters: |
| 78 | + - kubeapilinter |
| 79 | + # controller-gen does not allow to add MaxItems to Schemaless fields |
| 80 | + - path: "api/v1beta2/*|api/v1beta1/*" |
| 81 | + text: "maxlength: field (AllOf|OneOf|AnyOf) must have a maximum items, add kubebuilder:validation:MaxItems marker" |
| 82 | + linters: |
| 83 | + - kubeapilinter |
| 84 | + # It does not make sense to add a maxItems marker on the *List structs as they are not used to generate CRD YAMLs. |
| 85 | + # This exclude will be removed once https://github.com/JoelSpeed/kubeapilinter/issues/38 is resolved. |
| 86 | + - path: "api/v1beta2/*|api/addons/v1beta2/*|api/v1beta1/*|api/v1alpha1/*|api/addons/v1beta1/*" |
| 87 | + text: "maxlength: field Items must have a maximum items, add kubebuilder:validation:MaxItems marker" |
| 88 | + linters: |
| 89 | + - kubeapilinter |
| 90 | + - path: "api/v1beta2/*|api/addons/v1beta2/*|api/v1alpha1/*|api/v1beta1/*|api/addons/v1beta1/*" |
| 91 | + text: "nobools" |
| 92 | + linters: |
| 93 | + - kubeapilinter |
| 94 | + # We follow the current CustomResourceDefinition field's json tag pattern. |
| 95 | + - path: "api/v1beta2/*|api/v1beta1/*" |
| 96 | + text: "field (XPreserveUnknownFields|XPreserveUnknownFields|XValidations|XMetadata|XIntOrString) json tag does not match pattern" |
| 97 | + linters: |
| 98 | + - kubeapilinter |
| 99 | + # The following rules are disabled until we migrate to the new API. |
| 100 | + - path: "bootstrap/kubeadm/api/v1beta2/kubeadm_types.go|bootstrap/kubeadm/api/v1beta1/kubeadm_types.go" |
| 101 | + text: "field Token is marked as required, should not be a pointer" |
| 102 | + linters: |
| 103 | + - kubeapilinter |
| 104 | + - path: "api/v1beta2/clusterclass_types.go|api/v1beta1/clusterclass_types.go" |
| 105 | + text: "field Ref is marked as required, should not be a pointer" |
| 106 | + linters: |
| 107 | + - kubeapilinter |
| 108 | + - path: "api/v1beta2/*|api/addons/v1beta2/*|api/v1alpha1/*|api/v1beta1/*|api/v1alpha3/*|api/addons/v1beta1/*" |
| 109 | + text: "field Items must be marked as optional or required" |
| 110 | + linters: |
| 111 | + - kubeapilinter |
51 | 112 | issues: |
52 | | - exclude-files: |
53 | | - - "zz_generated.*\\.go$" |
54 | | - - "vendored_openapi\\.go$" |
55 | | - # We don't want to invest time to fix new linter findings in old API types. |
56 | | - - "internal/apis/.*" |
57 | | - - ".*_test.go" # Exclude test files. |
58 | 113 | max-same-issues: 0 |
59 | 114 | max-issues-per-linter: 0 |
60 | | - exclude-rules: |
61 | | - # KAL should only run on API folders. |
62 | | - - path-except: "api//*" |
63 | | - linters: |
64 | | - - kubeapilinter |
65 | | - - path: "api/v1beta2/*|api/addons/v1beta2/*|api/v1beta1/*|api/v1alpha1/*|api/addons/v1beta1/*" |
66 | | - text: "Conditions field must be a slice of metav1.Condition" |
67 | | - linters: |
68 | | - - kubeapilinter |
69 | | - - path: "api/v1beta2/*|api/v1beta1/*" |
70 | | - text: "type ClusterIPFamily should not use an int, int8 or int16. Use int32 or int64 depending on bounding requirements" |
71 | | - linters: |
72 | | - - kubeapilinter |
73 | | - - path: "exp/ipam/api/v1beta2/*|exp/ipam/api/v1alpha1/*|exp/ipam/api/v1beta1/*" |
74 | | - text: "field Prefix should not use an int, int8 or int16. Use int32 or int64 depending on bounding requirements" |
75 | | - linters: |
76 | | - - kubeapilinter |
77 | | - # clusterctl and Runtime Hooks can be fixed once we bump their apiVersion. |
78 | | - - path: "cmd/clusterctl/api/v1alpha3|exp/runtime/hooks/api/v1alpha1" |
79 | | - text: "maxlength" |
80 | | - linters: |
81 | | - - kubeapilinter |
82 | | - # controller-gen does not allow to add MaxItems to Schemaless fields |
83 | | - - path: "api/v1beta2/*|api/v1beta1/*" |
84 | | - text: "maxlength: field (AllOf|OneOf|AnyOf) must have a maximum items, add kubebuilder:validation:MaxItems marker" |
85 | | - linters: |
86 | | - - kubeapilinter |
87 | | - # It does not make sense to add a maxItems marker on the *List structs as they are not used to generate CRD YAMLs. |
88 | | - # This exclude will be removed once https://github.com/JoelSpeed/kubeapilinter/issues/38 is resolved. |
89 | | - - path: "api/v1beta2/*|api/addons/v1beta2/*|api/v1beta1/*|api/v1alpha1/*|api/addons/v1beta1/*" |
90 | | - text: "maxlength: field Items must have a maximum items, add kubebuilder:validation:MaxItems marker" |
91 | | - linters: |
92 | | - - kubeapilinter |
93 | | - - path: "api/v1beta2/*|api/addons/v1beta2/*|api/v1alpha1/*|api/v1beta1/*|api/addons/v1beta1/*" |
94 | | - text: "nobools" |
95 | | - linters: |
96 | | - - kubeapilinter |
97 | | - # We follow the current CustomResourceDefinition field's json tag pattern. |
98 | | - - path: "api/v1beta2/*|api/v1beta1/*" |
99 | | - text: "field (XPreserveUnknownFields|XPreserveUnknownFields|XValidations|XMetadata|XIntOrString) json tag does not match pattern" |
100 | | - linters: |
101 | | - - kubeapilinter |
102 | | - # The following rules are disabled until we migrate to the new API. |
103 | | - - path: "bootstrap/kubeadm/api/v1beta2/kubeadm_types.go|bootstrap/kubeadm/api/v1beta1/kubeadm_types.go" |
104 | | - text: "field Token is marked as required, should not be a pointer" |
105 | | - linters: |
106 | | - - kubeapilinter |
107 | | - - path: "api/v1beta2/clusterclass_types.go|api/v1beta1/clusterclass_types.go" |
108 | | - text: "field Ref is marked as required, should not be a pointer" |
109 | | - linters: |
110 | | - - kubeapilinter |
111 | | - - path: "api/v1beta2/*|api/addons/v1beta2/*|api/v1alpha1/*|api/v1beta1/*|api/v1alpha3/*|api/addons/v1beta1/*" |
112 | | - text: "field Items must be marked as optional or required" |
113 | | - linters: |
114 | | - - kubeapilinter |
0 commit comments