From d485fe561080e064a3f84ae768be7052f340cd63 Mon Sep 17 00:00:00 2001 From: Ignoramuss Date: Fri, 23 Jan 2026 19:50:50 -0800 Subject: [PATCH 1/3] api: enable optionalorrequired linter for policy API Add missing +optional markers to PodDisruptionBudgetStatus fields in policy/v1 and policy/v1beta1 and enable the optionalorrequired linter for the policy API group. --- hack/golangci-hints.yaml | 2 +- hack/golangci.yaml | 2 +- hack/kube-api-linter/exceptions.yaml | 2 +- staging/src/k8s.io/api/policy/v1/generated.proto | 4 ++++ staging/src/k8s.io/api/policy/v1/types.go | 4 ++++ staging/src/k8s.io/api/policy/v1beta1/generated.proto | 4 ++++ staging/src/k8s.io/api/policy/v1beta1/types.go | 4 ++++ 7 files changed, 19 insertions(+), 3 deletions(-) diff --git a/hack/golangci-hints.yaml b/hack/golangci-hints.yaml index 5e238f12c59..eed6169fa14 100644 --- a/hack/golangci-hints.yaml +++ b/hack/golangci-hints.yaml @@ -214,7 +214,7 @@ linters: # OptionalOrRequired is being enabled over time. For now, each API group should be added to this list until we comb through each group and fix the missing tags. - text: "must be marked as optional or required" - path: "staging/src/k8s.io/api/(admission|apidiscovery|apiserverinternal|apps|authentication|authorization|autoscaling|batch|certificates|coordination|core|discovery|events|extensions|flowcontrol|networking|policy|rbac|resource|storage|storagemigration)" + path: "staging/src/k8s.io/api/(admission|apidiscovery|apiserverinternal|apps|authentication|authorization|autoscaling|batch|certificates|coordination|core|discovery|events|extensions|flowcontrol|networking|rbac|resource|storage|storagemigration)" # OptionalOrRequired - Existing fields that are marked as both optional and required (based on standard optional vs kubebuilder:validation:Required) and should not be fixed. - text: "field (PortStatus|IngressPortStatus)\\.Error must not be marked as both optional and required" diff --git a/hack/golangci.yaml b/hack/golangci.yaml index ad1309bd9ce..7eb4e0abff4 100644 --- a/hack/golangci.yaml +++ b/hack/golangci.yaml @@ -225,7 +225,7 @@ linters: # OptionalOrRequired is being enabled over time. For now, each API group should be added to this list until we comb through each group and fix the missing tags. - text: "must be marked as optional or required" - path: "staging/src/k8s.io/api/(admission|apidiscovery|apiserverinternal|apps|authentication|authorization|autoscaling|batch|certificates|coordination|core|discovery|events|extensions|flowcontrol|networking|policy|rbac|resource|storage|storagemigration)" + path: "staging/src/k8s.io/api/(admission|apidiscovery|apiserverinternal|apps|authentication|authorization|autoscaling|batch|certificates|coordination|core|discovery|events|extensions|flowcontrol|networking|rbac|resource|storage|storagemigration)" # OptionalOrRequired - Existing fields that are marked as both optional and required (based on standard optional vs kubebuilder:validation:Required) and should not be fixed. - text: "field (PortStatus|IngressPortStatus)\\.Error must not be marked as both optional and required" diff --git a/hack/kube-api-linter/exceptions.yaml b/hack/kube-api-linter/exceptions.yaml index 78a8dba3ff3..6837ce30bc7 100644 --- a/hack/kube-api-linter/exceptions.yaml +++ b/hack/kube-api-linter/exceptions.yaml @@ -90,7 +90,7 @@ # OptionalOrRequired is being enabled over time. For now, each API group should be added to this list until we comb through each group and fix the missing tags. - text: "must be marked as optional or required" - path: "staging/src/k8s.io/api/(admission|apidiscovery|apiserverinternal|apps|authentication|authorization|autoscaling|batch|certificates|coordination|core|discovery|events|extensions|flowcontrol|networking|policy|rbac|resource|storage|storagemigration)" + path: "staging/src/k8s.io/api/(admission|apidiscovery|apiserverinternal|apps|authentication|authorization|autoscaling|batch|certificates|coordination|core|discovery|events|extensions|flowcontrol|networking|rbac|resource|storage|storagemigration)" # OptionalOrRequired - Existing fields that are marked as both optional and required (based on standard optional vs kubebuilder:validation:Required) and should not be fixed. - text: "field (PortStatus|IngressPortStatus)\\.Error must not be marked as both optional and required" diff --git a/staging/src/k8s.io/api/policy/v1/generated.proto b/staging/src/k8s.io/api/policy/v1/generated.proto index 95348907234..704cc10b7db 100644 --- a/staging/src/k8s.io/api/policy/v1/generated.proto +++ b/staging/src/k8s.io/api/policy/v1/generated.proto @@ -142,15 +142,19 @@ message PodDisruptionBudgetStatus { map disruptedPods = 2; // Number of pod disruptions that are currently allowed. + // +optional optional int32 disruptionsAllowed = 3; // current number of healthy pods + // +optional optional int32 currentHealthy = 4; // minimum desired number of healthy pods + // +optional optional int32 desiredHealthy = 5; // total number of pods counted by this disruption budget + // +optional optional int32 expectedPods = 6; // Conditions contain conditions for PDB. The disruption controller sets the diff --git a/staging/src/k8s.io/api/policy/v1/types.go b/staging/src/k8s.io/api/policy/v1/types.go index 4e74367894a..ebf349e3177 100644 --- a/staging/src/k8s.io/api/policy/v1/types.go +++ b/staging/src/k8s.io/api/policy/v1/types.go @@ -117,15 +117,19 @@ type PodDisruptionBudgetStatus struct { DisruptedPods map[string]metav1.Time `json:"disruptedPods,omitempty" protobuf:"bytes,2,rep,name=disruptedPods"` // Number of pod disruptions that are currently allowed. + // +optional DisruptionsAllowed int32 `json:"disruptionsAllowed" protobuf:"varint,3,opt,name=disruptionsAllowed"` // current number of healthy pods + // +optional CurrentHealthy int32 `json:"currentHealthy" protobuf:"varint,4,opt,name=currentHealthy"` // minimum desired number of healthy pods + // +optional DesiredHealthy int32 `json:"desiredHealthy" protobuf:"varint,5,opt,name=desiredHealthy"` // total number of pods counted by this disruption budget + // +optional ExpectedPods int32 `json:"expectedPods" protobuf:"varint,6,opt,name=expectedPods"` // Conditions contain conditions for PDB. The disruption controller sets the diff --git a/staging/src/k8s.io/api/policy/v1beta1/generated.proto b/staging/src/k8s.io/api/policy/v1beta1/generated.proto index e0cbe00f1ca..a8200a2d78d 100644 --- a/staging/src/k8s.io/api/policy/v1beta1/generated.proto +++ b/staging/src/k8s.io/api/policy/v1beta1/generated.proto @@ -142,15 +142,19 @@ message PodDisruptionBudgetStatus { map disruptedPods = 2; // Number of pod disruptions that are currently allowed. + // +optional optional int32 disruptionsAllowed = 3; // current number of healthy pods + // +optional optional int32 currentHealthy = 4; // minimum desired number of healthy pods + // +optional optional int32 desiredHealthy = 5; // total number of pods counted by this disruption budget + // +optional optional int32 expectedPods = 6; // Conditions contain conditions for PDB. The disruption controller sets the diff --git a/staging/src/k8s.io/api/policy/v1beta1/types.go b/staging/src/k8s.io/api/policy/v1beta1/types.go index 9bba454f949..354c22a3d09 100644 --- a/staging/src/k8s.io/api/policy/v1beta1/types.go +++ b/staging/src/k8s.io/api/policy/v1beta1/types.go @@ -114,15 +114,19 @@ type PodDisruptionBudgetStatus struct { DisruptedPods map[string]metav1.Time `json:"disruptedPods,omitempty" protobuf:"bytes,2,rep,name=disruptedPods"` // Number of pod disruptions that are currently allowed. + // +optional DisruptionsAllowed int32 `json:"disruptionsAllowed" protobuf:"varint,3,opt,name=disruptionsAllowed"` // current number of healthy pods + // +optional CurrentHealthy int32 `json:"currentHealthy" protobuf:"varint,4,opt,name=currentHealthy"` // minimum desired number of healthy pods + // +optional DesiredHealthy int32 `json:"desiredHealthy" protobuf:"varint,5,opt,name=desiredHealthy"` // total number of pods counted by this disruption budget + // +optional ExpectedPods int32 `json:"expectedPods" protobuf:"varint,6,opt,name=expectedPods"` // Conditions contain conditions for PDB. The disruption controller sets the From 9e8deefd9a001571fa15e822efd7987381408606 Mon Sep 17 00:00:00 2001 From: Ignoramuss Date: Tue, 27 Jan 2026 07:45:45 -0800 Subject: [PATCH 2/3] Regenerate OpenAPI spec after adding +optional markers to policy API Run hack/update-codegen.sh to regenerate OpenAPI specifications after adding +optional markers to PodDisruptionBudgetStatus fields in both policy/v1 and policy/v1beta1. --- pkg/generated/openapi/zz_generated.openapi.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 805409848bf..2914738b325 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -43952,7 +43952,6 @@ func schema_k8sio_api_policy_v1_PodDisruptionBudgetStatus(ref common.ReferenceCa }, }, }, - Required: []string{"disruptionsAllowed", "currentHealthy", "desiredHealthy", "expectedPods"}, }, }, Dependencies: []string{ @@ -44229,7 +44228,6 @@ func schema_k8sio_api_policy_v1beta1_PodDisruptionBudgetStatus(ref common.Refere }, }, }, - Required: []string{"disruptionsAllowed", "currentHealthy", "desiredHealthy", "expectedPods"}, }, }, Dependencies: []string{ From c29724f060a74bd717f050d5eca31f849f5ddf79 Mon Sep 17 00:00:00 2001 From: Ignoramuss Date: Tue, 27 Jan 2026 16:12:14 -0800 Subject: [PATCH 3/3] Regenerate OpenAPI spec files for policy API Run hack/update-openapi-spec.sh to regenerate the static OpenAPI specification files after adding +optional markers to PodDisruptionBudgetStatus fields. --- api/openapi-spec/swagger.json | 6 ------ api/openapi-spec/v3/apis__policy__v1_openapi.json | 6 ------ 2 files changed, 12 deletions(-) diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index 7648d793986..67434d5b25c 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -14882,12 +14882,6 @@ "type": "integer" } }, - "required": [ - "disruptionsAllowed", - "currentHealthy", - "desiredHealthy", - "expectedPods" - ], "type": "object" }, "io.k8s.api.rbac.v1.AggregationRule": { diff --git a/api/openapi-spec/v3/apis__policy__v1_openapi.json b/api/openapi-spec/v3/apis__policy__v1_openapi.json index a250270601f..61fd5af0d3d 100644 --- a/api/openapi-spec/v3/apis__policy__v1_openapi.json +++ b/api/openapi-spec/v3/apis__policy__v1_openapi.json @@ -187,12 +187,6 @@ "type": "integer" } }, - "required": [ - "disruptionsAllowed", - "currentHealthy", - "desiredHealthy", - "expectedPods" - ], "type": "object" }, "io.k8s.apimachinery.pkg.apis.meta.v1.APIResource": {