|
| 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 | - kal # linter for Kube API conventions
|
10 |
| - |
11 |
| -linters-settings: |
12 |
| - custom: |
13 |
| - kal: |
14 |
| - type: "module" |
15 |
| - description: KAL is the 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 | + kal: |
| 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 |
| 39 | + usePatchStrategy: Forbid |
| 40 | + useProtobuf: Forbid |
| 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: lax |
| 51 | + rules: |
| 52 | + # KAL should only run on API folders. |
| 53 | + - path-except: "api//*" |
| 54 | + linters: |
| 55 | + - kal |
| 56 | + - path: "api/v1beta2/*|api/addons/v1beta2/*|api/v1beta1/*|api/v1alpha1/*|api/addons/v1beta1/*" |
| 57 | + text: "Conditions field must be a slice of metav1.Condition" |
| 58 | + linters: |
| 59 | + - kal |
| 60 | + - path: "api/v1beta2/*|api/v1beta1/*" |
| 61 | + text: "type ClusterIPFamily should not use an int, int8 or int16. Use int32 or int64 depending on bounding requirements" |
| 62 | + linters: |
| 63 | + - kal |
| 64 | + - path: "exp/ipam/api/v1beta2/*|exp/ipam/api/v1alpha1/*|exp/ipam/api/v1beta1/*" |
| 65 | + text: "field Prefix should not use an int, int8 or int16. Use int32 or int64 depending on bounding requirements" |
| 66 | + linters: |
| 67 | + - kal |
| 68 | + # clusterctl and Runtime Hooks can be fixed once we bump their apiVersion. |
| 69 | + - path: "cmd/clusterctl/api/v1alpha3|exp/runtime/hooks/api/v1alpha1" |
| 70 | + text: "maxlength" |
| 71 | + linters: |
| 72 | + - kal |
| 73 | + # controller-gen does not allow to add MaxItems to Schemaless fields |
| 74 | + - path: "api/v1beta2/*|api/v1beta1/*" |
| 75 | + text: "maxlength: field (AllOf|OneOf|AnyOf) must have a maximum items, add kubebuilder:validation:MaxItems marker" |
| 76 | + linters: |
| 77 | + - kal |
| 78 | + # It does not make sense to add a maxItems marker on the *List structs as they are not used to generate CRD YAMLs. |
| 79 | + # This exclude will be removed once https://github.com/JoelSpeed/kal/issues/38 is resolved. |
| 80 | + - path: "api/v1beta2/*|api/addons/v1beta2/*|api/v1beta1/*|api/v1alpha1/*|api/addons/v1beta1/*" |
| 81 | + text: "maxlength: field Items must have a maximum items, add kubebuilder:validation:MaxItems marker" |
| 82 | + linters: |
| 83 | + - kal |
| 84 | + - path: "api/v1beta2/*|api/addons/v1beta2/*|api/v1alpha1/*|api/v1beta1/*|api/addons/v1beta1/*" |
| 85 | + text: "nobools" |
| 86 | + linters: |
| 87 | + - kal |
| 88 | + # We follow the current CustomResourceDefinition field's json tag pattern. |
| 89 | + - path: "api/v1beta2/*|api/v1beta1/*" |
| 90 | + text: "field (XPreserveUnknownFields|XPreserveUnknownFields|XValidations|XMetadata|XIntOrString) json tag does not match pattern" |
| 91 | + linters: |
| 92 | + - kal |
| 93 | + # The following rules are disabled until we migrate to the new API. |
| 94 | + - path: "bootstrap/kubeadm/api/v1beta2/kubeadm_types.go|bootstrap/kubeadm/api/v1beta1/kubeadm_types.go" |
| 95 | + text: "field Token is marked as required, should not be a pointer" |
| 96 | + linters: |
| 97 | + - kal |
| 98 | + - path: "api/v1beta2/clusterclass_types.go|api/v1beta1/clusterclass_types.go" |
| 99 | + text: "field Ref is marked as required, should not be a pointer" |
| 100 | + linters: |
| 101 | + - kal |
| 102 | + - path: "api/v1beta2/*|api/addons/v1beta2/*|api/v1alpha1/*|api/v1beta1/*|api/v1alpha3/*|api/addons/v1beta1/*" |
| 103 | + text: "field Items must be marked as optional or required" |
| 104 | + linters: |
| 105 | + - kal |
| 106 | + paths: |
| 107 | + - zz_generated.*\.go$ |
| 108 | + - vendored_openapi\.go$ |
| 109 | + # We don't want to invest time to fix new linter findings in old API types. |
| 110 | + - internal/apis/.* |
| 111 | + - ".*_test.go" # Exclude test files. |
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 |
| - max-same-issues: 0 |
59 | 113 | max-issues-per-linter: 0
|
60 |
| - exclude-rules: |
61 |
| - # KAL should only run on API folders. |
62 |
| - - path-except: "api//*" |
63 |
| - linters: |
64 |
| - - kal |
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 |
| - - kal |
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 |
| - - kal |
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 |
| - - kal |
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 |
| - - kal |
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 |
| - - kal |
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/kal/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 |
| - - kal |
93 |
| - - path: "api/v1beta2/*|api/addons/v1beta2/*|api/v1alpha1/*|api/v1beta1/*|api/addons/v1beta1/*" |
94 |
| - text: "nobools" |
95 |
| - linters: |
96 |
| - - kal |
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 |
| - - kal |
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 |
| - - kal |
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 |
| - - kal |
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 |
| - - kal |
| 114 | + max-same-issues: 0 |
0 commit comments