diff --git a/pkg/apis/flowcontrol/fuzzer/fuzzer.go b/pkg/apis/flowcontrol/fuzzer/fuzzer.go index 37ce6c3eaf4..7e87abbee16 100644 --- a/pkg/apis/flowcontrol/fuzzer/fuzzer.go +++ b/pkg/apis/flowcontrol/fuzzer/fuzzer.go @@ -33,5 +33,16 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} { obj.LendablePercent = &i } }, + func(obj *flowcontrol.ExemptPriorityLevelConfiguration, c fuzz.Continue) { + c.FuzzNoCustom(obj) // fuzz self without calling this function again + if obj.NominalConcurrencyShares == nil { + i := int32(0) + obj.NominalConcurrencyShares = &i + } + if obj.LendablePercent == nil { + i := int32(0) + obj.LendablePercent = &i + } + }, } } diff --git a/pkg/apis/flowcontrol/types.go b/pkg/apis/flowcontrol/types.go index a844a078364..caf00ae28b1 100644 --- a/pkg/apis/flowcontrol/types.go +++ b/pkg/apis/flowcontrol/types.go @@ -475,7 +475,7 @@ type ExemptPriorityLevelConfiguration struct { // at the expense of every other priority level. // This field has a default value of zero. // +optional - NominalConcurrencyShares int32 + NominalConcurrencyShares *int32 // `lendablePercent` prescribes the fraction of the level's NominalCL that // can be borrowed by other priority levels. This value of this // field must be between 0 and 100, inclusive, and it defaults to 0. diff --git a/pkg/apis/flowcontrol/v1alpha1/defaults.go b/pkg/apis/flowcontrol/v1alpha1/defaults.go index 1c85f6c6f7b..511108fd4a1 100644 --- a/pkg/apis/flowcontrol/v1alpha1/defaults.go +++ b/pkg/apis/flowcontrol/v1alpha1/defaults.go @@ -40,6 +40,17 @@ func SetDefaults_FlowSchemaSpec(spec *v1alpha1.FlowSchemaSpec) { } } +func SetDefaults_ExemptPriorityLevelConfiguration(eplc *v1alpha1.ExemptPriorityLevelConfiguration) { + if eplc.NominalConcurrencyShares == nil { + eplc.NominalConcurrencyShares = new(int32) + *eplc.NominalConcurrencyShares = 0 + } + if eplc.LendablePercent == nil { + eplc.LendablePercent = new(int32) + *eplc.LendablePercent = 0 + } +} + func SetDefaults_LimitedPriorityLevelConfiguration(lplc *v1alpha1.LimitedPriorityLevelConfiguration) { if lplc.AssuredConcurrencyShares == 0 { lplc.AssuredConcurrencyShares = PriorityLevelConfigurationDefaultAssuredConcurrencyShares diff --git a/pkg/apis/flowcontrol/v1alpha1/defaults_test.go b/pkg/apis/flowcontrol/v1alpha1/defaults_test.go index 35baccb63ae..83a4d965fa5 100644 --- a/pkg/apis/flowcontrol/v1alpha1/defaults_test.go +++ b/pkg/apis/flowcontrol/v1alpha1/defaults_test.go @@ -33,6 +33,24 @@ func TestDefaultWithPriorityLevelConfiguration(t *testing.T) { original runtime.Object expected runtime.Object }{ + { + name: "Defaulting for Exempt", + original: &flowcontrolv1alpha1.PriorityLevelConfiguration{ + Spec: flowcontrolv1alpha1.PriorityLevelConfigurationSpec{ + Type: flowcontrolv1alpha1.PriorityLevelEnablementExempt, + Exempt: &flowcontrolv1alpha1.ExemptPriorityLevelConfiguration{}, + }, + }, + expected: &flowcontrolv1alpha1.PriorityLevelConfiguration{ + Spec: flowcontrolv1alpha1.PriorityLevelConfigurationSpec{ + Type: flowcontrolv1alpha1.PriorityLevelEnablementExempt, + Exempt: &flowcontrolv1alpha1.ExemptPriorityLevelConfiguration{ + NominalConcurrencyShares: pointer.Int32(0), + LendablePercent: pointer.Int32(0), + }, + }, + }, + }, { name: "LendablePercent is not specified, should default to zero", original: &flowcontrolv1alpha1.PriorityLevelConfiguration{ diff --git a/pkg/apis/flowcontrol/v1beta1/defaults.go b/pkg/apis/flowcontrol/v1beta1/defaults.go index a8ee8a784bb..cb2c8806c0d 100644 --- a/pkg/apis/flowcontrol/v1beta1/defaults.go +++ b/pkg/apis/flowcontrol/v1beta1/defaults.go @@ -40,6 +40,17 @@ func SetDefaults_FlowSchemaSpec(spec *v1beta1.FlowSchemaSpec) { } } +func SetDefaults_ExemptPriorityLevelConfiguration(eplc *v1beta1.ExemptPriorityLevelConfiguration) { + if eplc.NominalConcurrencyShares == nil { + eplc.NominalConcurrencyShares = new(int32) + *eplc.NominalConcurrencyShares = 0 + } + if eplc.LendablePercent == nil { + eplc.LendablePercent = new(int32) + *eplc.LendablePercent = 0 + } +} + func SetDefaults_LimitedPriorityLevelConfiguration(lplc *v1beta1.LimitedPriorityLevelConfiguration) { if lplc.AssuredConcurrencyShares == 0 { lplc.AssuredConcurrencyShares = PriorityLevelConfigurationDefaultAssuredConcurrencyShares diff --git a/pkg/apis/flowcontrol/v1beta1/defaults_test.go b/pkg/apis/flowcontrol/v1beta1/defaults_test.go index f5a83f521f2..66044ee69e9 100644 --- a/pkg/apis/flowcontrol/v1beta1/defaults_test.go +++ b/pkg/apis/flowcontrol/v1beta1/defaults_test.go @@ -33,6 +33,24 @@ func TestDefaultWithPriorityLevelConfiguration(t *testing.T) { original runtime.Object expected runtime.Object }{ + { + name: "Defaulting for Exempt", + original: &flowcontrolv1beta1.PriorityLevelConfiguration{ + Spec: flowcontrolv1beta1.PriorityLevelConfigurationSpec{ + Type: flowcontrolv1beta1.PriorityLevelEnablementExempt, + Exempt: &flowcontrolv1beta1.ExemptPriorityLevelConfiguration{}, + }, + }, + expected: &flowcontrolv1beta1.PriorityLevelConfiguration{ + Spec: flowcontrolv1beta1.PriorityLevelConfigurationSpec{ + Type: flowcontrolv1beta1.PriorityLevelEnablementExempt, + Exempt: &flowcontrolv1beta1.ExemptPriorityLevelConfiguration{ + NominalConcurrencyShares: pointer.Int32(0), + LendablePercent: pointer.Int32(0), + }, + }, + }, + }, { name: "LendablePercent is not specified, should default to zero", original: &flowcontrolv1beta1.PriorityLevelConfiguration{ diff --git a/pkg/apis/flowcontrol/v1beta2/defaults.go b/pkg/apis/flowcontrol/v1beta2/defaults.go index 389995bd090..ee37d354267 100644 --- a/pkg/apis/flowcontrol/v1beta2/defaults.go +++ b/pkg/apis/flowcontrol/v1beta2/defaults.go @@ -40,6 +40,17 @@ func SetDefaults_FlowSchemaSpec(spec *v1beta2.FlowSchemaSpec) { } } +func SetDefaults_ExemptPriorityLevelConfiguration(eplc *v1beta2.ExemptPriorityLevelConfiguration) { + if eplc.NominalConcurrencyShares == nil { + eplc.NominalConcurrencyShares = new(int32) + *eplc.NominalConcurrencyShares = 0 + } + if eplc.LendablePercent == nil { + eplc.LendablePercent = new(int32) + *eplc.LendablePercent = 0 + } +} + func SetDefaults_LimitedPriorityLevelConfiguration(lplc *v1beta2.LimitedPriorityLevelConfiguration) { if lplc.AssuredConcurrencyShares == 0 { lplc.AssuredConcurrencyShares = PriorityLevelConfigurationDefaultAssuredConcurrencyShares diff --git a/pkg/apis/flowcontrol/v1beta2/defaults_test.go b/pkg/apis/flowcontrol/v1beta2/defaults_test.go index f1d33daf67e..9d2bee1a2ce 100644 --- a/pkg/apis/flowcontrol/v1beta2/defaults_test.go +++ b/pkg/apis/flowcontrol/v1beta2/defaults_test.go @@ -33,6 +33,24 @@ func TestDefaultWithPriorityLevelConfiguration(t *testing.T) { original runtime.Object expected runtime.Object }{ + { + name: "Defaulting for Exempt", + original: &flowcontrolv1beta2.PriorityLevelConfiguration{ + Spec: flowcontrolv1beta2.PriorityLevelConfigurationSpec{ + Type: flowcontrolv1beta2.PriorityLevelEnablementExempt, + Exempt: &flowcontrolv1beta2.ExemptPriorityLevelConfiguration{}, + }, + }, + expected: &flowcontrolv1beta2.PriorityLevelConfiguration{ + Spec: flowcontrolv1beta2.PriorityLevelConfigurationSpec{ + Type: flowcontrolv1beta2.PriorityLevelEnablementExempt, + Exempt: &flowcontrolv1beta2.ExemptPriorityLevelConfiguration{ + NominalConcurrencyShares: pointer.Int32(0), + LendablePercent: pointer.Int32(0), + }, + }, + }, + }, { name: "LendablePercent is not specified, should default to zero", original: &flowcontrolv1beta2.PriorityLevelConfiguration{ diff --git a/pkg/apis/flowcontrol/v1beta3/defaults.go b/pkg/apis/flowcontrol/v1beta3/defaults.go index b590bfb5297..151664f4439 100644 --- a/pkg/apis/flowcontrol/v1beta3/defaults.go +++ b/pkg/apis/flowcontrol/v1beta3/defaults.go @@ -40,6 +40,17 @@ func SetDefaults_FlowSchemaSpec(spec *v1beta3.FlowSchemaSpec) { } } +func SetDefaults_ExemptPriorityLevelConfiguration(eplc *v1beta3.ExemptPriorityLevelConfiguration) { + if eplc.NominalConcurrencyShares == nil { + eplc.NominalConcurrencyShares = new(int32) + *eplc.NominalConcurrencyShares = 0 + } + if eplc.LendablePercent == nil { + eplc.LendablePercent = new(int32) + *eplc.LendablePercent = 0 + } +} + func SetDefaults_LimitedPriorityLevelConfiguration(lplc *v1beta3.LimitedPriorityLevelConfiguration) { if lplc.NominalConcurrencyShares == 0 { lplc.NominalConcurrencyShares = PriorityLevelConfigurationDefaultNominalConcurrencyShares diff --git a/pkg/apis/flowcontrol/v1beta3/defaults_test.go b/pkg/apis/flowcontrol/v1beta3/defaults_test.go index cb42cb8c262..fced3b74a8a 100644 --- a/pkg/apis/flowcontrol/v1beta3/defaults_test.go +++ b/pkg/apis/flowcontrol/v1beta3/defaults_test.go @@ -34,7 +34,25 @@ func TestDefaultWithPriorityLevelConfiguration(t *testing.T) { expected runtime.Object }{ { - name: "LendablePercent is not specified, should default to zero", + name: "Defaulting for Exempt", + original: &flowcontrolv1beta3.PriorityLevelConfiguration{ + Spec: flowcontrolv1beta3.PriorityLevelConfigurationSpec{ + Type: flowcontrolv1beta3.PriorityLevelEnablementExempt, + Exempt: &flowcontrolv1beta3.ExemptPriorityLevelConfiguration{}, + }, + }, + expected: &flowcontrolv1beta3.PriorityLevelConfiguration{ + Spec: flowcontrolv1beta3.PriorityLevelConfigurationSpec{ + Type: flowcontrolv1beta3.PriorityLevelEnablementExempt, + Exempt: &flowcontrolv1beta3.ExemptPriorityLevelConfiguration{ + NominalConcurrencyShares: pointer.Int32(0), + LendablePercent: pointer.Int32(0), + }, + }, + }, + }, + { + name: "LendablePercent is not specified in Limited, should default to zero", original: &flowcontrolv1beta3.PriorityLevelConfiguration{ Spec: flowcontrolv1beta3.PriorityLevelConfigurationSpec{ Type: flowcontrolv1beta3.PriorityLevelEnablementLimited, diff --git a/staging/src/k8s.io/api/flowcontrol/v1alpha1/types.go b/staging/src/k8s.io/api/flowcontrol/v1alpha1/types.go index 2d65cb9732a..161411ff338 100644 --- a/staging/src/k8s.io/api/flowcontrol/v1alpha1/types.go +++ b/staging/src/k8s.io/api/flowcontrol/v1alpha1/types.go @@ -497,7 +497,7 @@ type ExemptPriorityLevelConfiguration struct { // at the expense of every other priority level. // This field has a default value of zero. // +optional - NominalConcurrencyShares int32 `json:"nominalConcurrencyShares" protobuf:"varint,1,opt,name=nominalConcurrencyShares"` + NominalConcurrencyShares *int32 `json:"nominalConcurrencyShares,omitempty" protobuf:"varint,1,opt,name=nominalConcurrencyShares"` // `lendablePercent` prescribes the fraction of the level's NominalCL that // can be borrowed by other priority levels. This value of this // field must be between 0 and 100, inclusive, and it defaults to 0. diff --git a/staging/src/k8s.io/api/flowcontrol/v1beta1/types.go b/staging/src/k8s.io/api/flowcontrol/v1beta1/types.go index 4af14c76bb1..9e05ff1a090 100644 --- a/staging/src/k8s.io/api/flowcontrol/v1beta1/types.go +++ b/staging/src/k8s.io/api/flowcontrol/v1beta1/types.go @@ -77,7 +77,9 @@ const ( // is a boolean false or has an invalid boolean representation // (if the cluster operator sets it to 'false' it will be stomped) // - any changes to the spec made by the cluster operator will be - // stomped. + // stomped, except for changes to the `nominalConcurrencyShares` + // and `lendablePercent` fields of the PriorityLevelConfiguration + // named "exempt". // // The kube-apiserver will apply updates on the suggested configuration if: // - the cluster operator has enabled auto-update by setting the annotation @@ -533,7 +535,7 @@ type ExemptPriorityLevelConfiguration struct { // at the expense of every other priority level. // This field has a default value of zero. // +optional - NominalConcurrencyShares int32 `json:"nominalConcurrencyShares" protobuf:"varint,1,opt,name=nominalConcurrencyShares"` + NominalConcurrencyShares *int32 `json:"nominalConcurrencyShares,omitempty" protobuf:"varint,1,opt,name=nominalConcurrencyShares"` // `lendablePercent` prescribes the fraction of the level's NominalCL that // can be borrowed by other priority levels. This value of this // field must be between 0 and 100, inclusive, and it defaults to 0. diff --git a/staging/src/k8s.io/api/flowcontrol/v1beta2/types.go b/staging/src/k8s.io/api/flowcontrol/v1beta2/types.go index dd233dcde1a..e8cf7abfff6 100644 --- a/staging/src/k8s.io/api/flowcontrol/v1beta2/types.go +++ b/staging/src/k8s.io/api/flowcontrol/v1beta2/types.go @@ -77,7 +77,9 @@ const ( // is a boolean false or has an invalid boolean representation // (if the cluster operator sets it to 'false' it will be stomped) // - any changes to the spec made by the cluster operator will be - // stomped. + // stomped, except for changes to the `nominalConcurrencyShares` + // and `lendablePercent` fields of the PriorityLevelConfiguration + // named "exempt". // // The kube-apiserver will apply updates on the suggested configuration if: // - the cluster operator has enabled auto-update by setting the annotation @@ -533,7 +535,7 @@ type ExemptPriorityLevelConfiguration struct { // at the expense of every other priority level. // This field has a default value of zero. // +optional - NominalConcurrencyShares int32 `json:"nominalConcurrencyShares" protobuf:"varint,1,opt,name=nominalConcurrencyShares"` + NominalConcurrencyShares *int32 `json:"nominalConcurrencyShares,omitempty" protobuf:"varint,1,opt,name=nominalConcurrencyShares"` // `lendablePercent` prescribes the fraction of the level's NominalCL that // can be borrowed by other priority levels. This value of this // field must be between 0 and 100, inclusive, and it defaults to 0. diff --git a/staging/src/k8s.io/api/flowcontrol/v1beta3/types.go b/staging/src/k8s.io/api/flowcontrol/v1beta3/types.go index 83f73963ca3..810941557b2 100644 --- a/staging/src/k8s.io/api/flowcontrol/v1beta3/types.go +++ b/staging/src/k8s.io/api/flowcontrol/v1beta3/types.go @@ -77,7 +77,9 @@ const ( // is a boolean false or has an invalid boolean representation // (if the cluster operator sets it to 'false' it will be stomped) // - any changes to the spec made by the cluster operator will be - // stomped. + // stomped, except for changes to the `nominalConcurrencyShares` + // and `lendablePercent` fields of the PriorityLevelConfiguration + // named "exempt". // // The kube-apiserver will apply updates on the suggested configuration if: // - the cluster operator has enabled auto-update by setting the annotation @@ -531,7 +533,7 @@ type ExemptPriorityLevelConfiguration struct { // at the expense of every other priority level. // This field has a default value of zero. // +optional - NominalConcurrencyShares int32 `json:"nominalConcurrencyShares" protobuf:"varint,1,opt,name=nominalConcurrencyShares"` + NominalConcurrencyShares *int32 `json:"nominalConcurrencyShares,omitempty" protobuf:"varint,1,opt,name=nominalConcurrencyShares"` // `lendablePercent` prescribes the fraction of the level's NominalCL that // can be borrowed by other priority levels. This value of this // field must be between 0 and 100, inclusive, and it defaults to 0.