Add feature flag to admission controller

Signed-off-by: Omer Aplatony <omerap12@gmail.com>
This commit is contained in:
Omer Aplatony 2025-08-21 14:01:58 +00:00
parent 6cbd4499c9
commit 697934c96b
3 changed files with 70 additions and 1 deletions

View File

@ -137,6 +137,11 @@ func ValidateVPA(vpa *vpa_types.VerticalPodAutoscaler, isCreate bool) error {
return fmt.Errorf("containerPolicies.ContainerName is required")
}
// check that perVPA is on if being used
if err := validatePerVPAFeatureFlag(&policy); err != nil {
return err
}
// Validate OOMBumpUpRatio
if policy.OOMBumpUpRatio != nil {
ratio := float64(policy.OOMBumpUpRatio.MilliValue()) / 1000.0
@ -217,3 +222,12 @@ func validateMemoryResolution(val apires.Quantity) error {
}
return nil
}
func validatePerVPAFeatureFlag(policy *vpa_types.ContainerResourcePolicy) error {
featureFlagOn := features.Enabled(features.PerVPAConfig)
perVPA := policy.OOMBumpUpRatio != nil || policy.OOMMinBumpUp != nil
if !featureFlagOn && perVPA {
return fmt.Errorf("OOMBumpUpRatio and OOMMinBumpUp are not supported when feature flag %s is disabled", features.PerVPAConfig)
}
return nil
}

View File

@ -51,6 +51,7 @@ func TestValidateVPA(t *testing.T) {
isCreate bool
expectError error
inPlaceOrRecreateFeatureGateDisabled bool
PerVPAConfigDisabled bool
}{
{
name: "empty update",
@ -319,10 +320,64 @@ func TestValidateVPA(t *testing.T) {
},
},
},
{
name: "per-vpa config active and used",
vpa: vpa_types.VerticalPodAutoscaler{
Spec: vpa_types.VerticalPodAutoscalerSpec{
UpdatePolicy: &vpa_types.PodUpdatePolicy{
UpdateMode: &validUpdateMode,
},
ResourcePolicy: &vpa_types.PodResourcePolicy{
ContainerPolicies: []vpa_types.ContainerResourcePolicy{
{
ContainerName: "loot box",
Mode: &validScalingMode,
MinAllowed: apiv1.ResourceList{
cpu: resource.MustParse("10"),
},
MaxAllowed: apiv1.ResourceList{
cpu: resource.MustParse("100"),
},
OOMBumpUpRatio: resource.NewQuantity(2, resource.DecimalSI),
},
},
},
},
},
PerVPAConfigDisabled: false,
},
{
name: "per-vpa config disabled and used",
vpa: vpa_types.VerticalPodAutoscaler{
Spec: vpa_types.VerticalPodAutoscalerSpec{
UpdatePolicy: &vpa_types.PodUpdatePolicy{
UpdateMode: &validUpdateMode,
},
ResourcePolicy: &vpa_types.PodResourcePolicy{
ContainerPolicies: []vpa_types.ContainerResourcePolicy{
{
ContainerName: "loot box",
Mode: &validScalingMode,
MinAllowed: apiv1.ResourceList{
cpu: resource.MustParse("10"),
},
MaxAllowed: apiv1.ResourceList{
cpu: resource.MustParse("100"),
},
OOMMinBumpUp: resource.NewQuantity(2, resource.DecimalSI),
},
},
},
},
},
PerVPAConfigDisabled: true,
expectError: fmt.Errorf("OOMBumpUpRatio and OOMMinBumpUp are not supported when feature flag PerVPAConfig is disabled"),
},
}
for _, tc := range tests {
t.Run(fmt.Sprintf("test case: %s", tc.name), func(t *testing.T) {
featuregatetesting.SetFeatureGateDuringTest(t, features.MutableFeatureGate, features.InPlaceOrRecreate, !tc.inPlaceOrRecreateFeatureGateDisabled)
featuregatetesting.SetFeatureGateDuringTest(t, features.MutableFeatureGate, features.PerVPAConfig, !tc.PerVPAConfigDisabled)
err := ValidateVPA(&tc.vpa, tc.isCreate)
if tc.expectError == nil {
assert.NoError(t, err)

View File

@ -50,7 +50,7 @@ const (
InPlaceOrRecreate featuregate.Feature = "InPlaceOrRecreate"
// alpha: v1.5.0
// components: recommender
// components: recommender, updater
// PerVPAConfig enables the ability to specify component-specific configuration
// parameters at the individual VPA object level. This allows for different