diff --git a/hack/golangci-hints.yaml b/hack/golangci-hints.yaml index 68a56bbc9fc..022417c7887 100644 --- a/hack/golangci-hints.yaml +++ b/hack/golangci-hints.yaml @@ -161,7 +161,22 @@ linters: path: "staging/src/k8s.io/api/events/(v1|v1beta1)/types.go" - text: 'notimestamp: naming convention "notimestamp": field AllocationResult.AllocationTimestamp: prefer use of the term ''time'' over ''timestamp''' path: "staging/src/k8s.io/api/resource/(v1|v1beta1|v1beta2)/types.go" - + # optionalfields - Ignore optionalfields issues for existing API group + # TODO: For each existing API group, we aim to remove it over time. + - text: "optionalfields: field .* should (?:be a pointer|have the omitempty tag)\\." + path: "staging/src/k8s.io/api/(admission|admissionregistration|apps|authentication|authorization|autoscaling|batch|certificates|coordination|core|discovery|events|extensions|flowcontrol|imagepolicy|networking|node|policy|rbac|resource|scheduling|storage|storagemigration)" + - text: "optionalfields: field StorageVersionCondition.ObservedGeneration should be a pointer." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" + - text: "optionalfields: field StorageVersion.Spec should be a pointer." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" + - text: "optionalfields: field StorageVersion.Status should be a pointer." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" + - text: "optionalfields: field StorageVersionCondition.LastTransitionTime should be a pointer." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" + - text: "optionalfields: field StorageVersion.Spec should have the omitempty tag." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" + - text: "optionalfields: field StorageVersion.Status should have the omitempty tag." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" # Pre-existing issues from the conflictmarkers linter # The Error field in some older API types is marked as both optional and required. # This is incorrect, but cannot be changed without breaking changes. @@ -417,7 +432,7 @@ linters: - "nonullable" # Ensure fields are not marked as nullable. # - "nophase" # Ensure field names do not have the word "phase" in them. - "notimestamp" # Ensure fields are not named "timestamp", prefer "time". - # - "optionalfields" # Ensure fields marked optional have omitempty and pointers. + - "optionalfields" # Ensure fields marked optional have omitempty and pointers. - "optionalorrequired" # Every field should be marked as `+optional` xor `+required`. # - "requiredfields" # Required fields should only be pointers when required based on the validity of the zero value, they should always have `omitempty`. - "ssatags" # Ensure lists have a listType tag. diff --git a/hack/golangci.yaml b/hack/golangci.yaml index 4f44df20cc1..29166908c59 100644 --- a/hack/golangci.yaml +++ b/hack/golangci.yaml @@ -176,7 +176,22 @@ linters: path: "staging/src/k8s.io/api/events/(v1|v1beta1)/types.go" - text: 'notimestamp: naming convention "notimestamp": field AllocationResult.AllocationTimestamp: prefer use of the term ''time'' over ''timestamp''' path: "staging/src/k8s.io/api/resource/(v1|v1beta1|v1beta2)/types.go" - + # optionalfields - Ignore optionalfields issues for existing API group + # TODO: For each existing API group, we aim to remove it over time. + - text: "optionalfields: field .* should (?:be a pointer|have the omitempty tag)\\." + path: "staging/src/k8s.io/api/(admission|admissionregistration|apps|authentication|authorization|autoscaling|batch|certificates|coordination|core|discovery|events|extensions|flowcontrol|imagepolicy|networking|node|policy|rbac|resource|scheduling|storage|storagemigration)" + - text: "optionalfields: field StorageVersionCondition.ObservedGeneration should be a pointer." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" + - text: "optionalfields: field StorageVersion.Spec should be a pointer." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" + - text: "optionalfields: field StorageVersion.Status should be a pointer." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" + - text: "optionalfields: field StorageVersionCondition.LastTransitionTime should be a pointer." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" + - text: "optionalfields: field StorageVersion.Spec should have the omitempty tag." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" + - text: "optionalfields: field StorageVersion.Status should have the omitempty tag." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" # Pre-existing issues from the conflictmarkers linter # The Error field in some older API types is marked as both optional and required. # This is incorrect, but cannot be changed without breaking changes. @@ -430,7 +445,7 @@ linters: - "nonullable" # Ensure fields are not marked as nullable. # - "nophase" # Ensure field names do not have the word "phase" in them. - "notimestamp" # Ensure fields are not named "timestamp", prefer "time". - # - "optionalfields" # Ensure fields marked optional have omitempty and pointers. + - "optionalfields" # Ensure fields marked optional have omitempty and pointers. - "optionalorrequired" # Every field should be marked as `+optional` xor `+required`. # - "requiredfields" # Required fields should only be pointers when required based on the validity of the zero value, they should always have `omitempty`. - "ssatags" # Ensure lists have a listType tag. diff --git a/hack/kube-api-linter/exceptions.yaml b/hack/kube-api-linter/exceptions.yaml index fe2705e5e93..0bed59d7c63 100644 --- a/hack/kube-api-linter/exceptions.yaml +++ b/hack/kube-api-linter/exceptions.yaml @@ -37,7 +37,22 @@ path: "staging/src/k8s.io/api/events/(v1|v1beta1)/types.go" - text: 'notimestamp: naming convention "notimestamp": field AllocationResult.AllocationTimestamp: prefer use of the term ''time'' over ''timestamp''' path: "staging/src/k8s.io/api/resource/(v1|v1beta1|v1beta2)/types.go" - +# optionalfields - Ignore optionalfields issues for existing API group +# TODO: For each existing API group, we aim to remove it over time. +- text: "optionalfields: field .* should (?:be a pointer|have the omitempty tag)\\." + path: "staging/src/k8s.io/api/(admission|admissionregistration|apps|authentication|authorization|autoscaling|batch|certificates|coordination|core|discovery|events|extensions|flowcontrol|imagepolicy|networking|node|policy|rbac|resource|scheduling|storage|storagemigration)" +- text: "optionalfields: field StorageVersionCondition.ObservedGeneration should be a pointer." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" +- text: "optionalfields: field StorageVersion.Spec should be a pointer." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" +- text: "optionalfields: field StorageVersion.Status should be a pointer." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" +- text: "optionalfields: field StorageVersionCondition.LastTransitionTime should be a pointer." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" +- text: "optionalfields: field StorageVersion.Spec should have the omitempty tag." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" +- text: "optionalfields: field StorageVersion.Status should have the omitempty tag." + path: "staging/src/k8s.io/api/apiserverinternal/v1alpha1/types.go" # Pre-existing issues from the conflictmarkers linter # The Error field in some older API types is marked as both optional and required. # This is incorrect, but cannot be changed without breaking changes. diff --git a/hack/kube-api-linter/kube-api-linter.yaml b/hack/kube-api-linter/kube-api-linter.yaml index 2ce454912be..fe60a59f59b 100644 --- a/hack/kube-api-linter/kube-api-linter.yaml +++ b/hack/kube-api-linter/kube-api-linter.yaml @@ -16,7 +16,7 @@ linters: - "nonullable" # Ensure fields are not marked as nullable. # - "nophase" # Ensure field names do not have the word "phase" in them. - "notimestamp" # Ensure fields are not named "timestamp", prefer "time". - # - "optionalfields" # Ensure fields marked optional have omitempty and pointers. + - "optionalfields" # Ensure fields marked optional have omitempty and pointers. - "optionalorrequired" # Every field should be marked as `+optional` xor `+required`. # - "requiredfields" # Required fields should only be pointers when required based on the validity of the zero value, they should always have `omitempty`. - "ssatags" # Ensure lists have a listType tag.