|
| 1 | +run: |
| 2 | + timeout: 10m |
| 3 | + go: "1.22" |
| 4 | + allow-parallel-runners: true |
| 5 | + |
| 6 | +linters: |
| 7 | + disable-all: true |
| 8 | + enable: |
| 9 | + - 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. |
| 29 | + |
| 30 | + # Linters below this line are disabled, pending conversation on how and when to enable them. |
| 31 | + disable: |
| 32 | + - "*" # We will manually enable new linters after understanding the impact. Disable all by default. |
| 33 | + lintersConfig: |
| 34 | + conditions: |
| 35 | + isFirstField: Warn # Require conditions to be the first field in the status struct. |
| 36 | + usePatchStrategy: Forbid # Conditions should not use the patch strategy on CRDs. |
| 37 | + useProtobuf: Forbid # We don't use protobuf, so protobuf tags are not required. |
| 38 | + # jsonTags: |
| 39 | + # jsonTagRegex: "^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$" # The default regex is appropriate for our use case. |
| 40 | + # optionalOrRequired: |
| 41 | + # preferredOptionalMarker: optional | kubebuilder:validation:Optional # The preferred optional marker to use, fixes will suggest to use this marker. Defaults to `optional`. |
| 42 | + # preferredRequiredMarker: required | kubebuilder:validation:Required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`. |
| 43 | + # requiredFields: |
| 44 | + # pointerPolicy: Warn | SuggestFix # Defaults to `SuggestFix`. We want our required fields to not be pointers. |
| 45 | + |
| 46 | +issues: |
| 47 | + exclude-files: |
| 48 | + - "zz_generated.*\\.go$" |
| 49 | + - "vendored_openapi\\.go$" |
| 50 | + # We don't want to invest time to fix new linter findings in old API types. |
| 51 | + - "internal/apis/.*" |
| 52 | + - ".*_test.go" # Exclude test files. |
| 53 | + max-same-issues: 0 |
| 54 | + max-issues-per-linter: 0 |
| 55 | + exclude-rules: |
| 56 | + # KAL should only run on API folders. |
| 57 | + - path-except: "api//*" |
| 58 | + linters: |
| 59 | + - kal |
| 60 | + - path: "api/v1beta1/*|api/v1alpha1/*" |
| 61 | + text: "Conditions field must be a slice of metav1.Condition" |
| 62 | + linters: |
| 63 | + - kal |
| 64 | + - path: "api/v1beta1/*" |
| 65 | + text: "type ClusterIPFamily should not use an int, int8 or int16. Use int32 or int64 depending on bounding requirements" |
| 66 | + linters: |
| 67 | + - kal |
| 68 | + - path: "exp/ipam/api/v1alpha1/*|exp/ipam/api/v1beta1/*" |
| 69 | + text: "field Prefix should not use an int, int8 or int16. Use int32 or int64 depending on bounding requirements" |
| 70 | + linters: |
| 71 | + - kal |
| 72 | + # clusterctl and Runtime Hooks can be fixed once we bump their apiVersion. |
| 73 | + - path: "cmd/clusterctl/api/v1alpha3|exp/runtime/hooks/api/v1alpha1" |
| 74 | + text: "maxlength" |
| 75 | + linters: |
| 76 | + - kal |
| 77 | + # controller-gen does not allow to add MaxItems to Schemaless fields |
| 78 | + - path: "api/v1beta1/*" |
| 79 | + text: "maxlength: field (AllOf|OneOf|AnyOf) must have a maximum items, add kubebuilder:validation:MaxItems marker" |
| 80 | + linters: |
| 81 | + - kal |
| 82 | + # It does not make sense to add a maxItems marker on the *List structs as they are not used to generate CRD YAMLs. |
| 83 | + # This exclude will be removed once https://github.com/JoelSpeed/kal/issues/38 is resolved. |
| 84 | + - path: "api/v1beta1/*|api/v1alpha1/*" |
| 85 | + text: "maxlength: field Items must have a maximum items, add kubebuilder:validation:MaxItems marker" |
| 86 | + linters: |
| 87 | + - kal |
| 88 | + - path: "api/v1alpha1/*|api/v1beta1/*" |
| 89 | + text: "nobools" |
| 90 | + linters: |
| 91 | + - kal |
| 92 | + # We follow the current CustomResourceDefinition field's json tag pattern. |
| 93 | + - path: "api/v1beta1/*" |
| 94 | + text: "field (XPreserveUnknownFields|XPreserveUnknownFields|XValidations|XMetadata|XIntOrString) json tag does not match pattern" |
| 95 | + linters: |
| 96 | + - kal |
| 97 | + # The following rules are disabled until we migrate to the new API. |
| 98 | + - path: "bootstrap/kubeadm/api/v1beta1/kubeadm_types.go" |
| 99 | + text: "field Token is marked as required, should not be a pointer" |
| 100 | + linters: |
| 101 | + - kal |
| 102 | + - path: "api/v1beta1/clusterclass_types.go" |
| 103 | + text: "field Ref is marked as required, should not be a pointer" |
| 104 | + linters: |
| 105 | + - kal |
| 106 | + - path: "api/v1alpha1/*|api/v1beta1/*|api/v1alpha3/*" |
| 107 | + text: "field Items must be marked as optional or required" |
| 108 | + linters: |
| 109 | + - kal |
0 commit comments