Skip to content

Commit 697934c

Browse files
committed
Add feature flag to admission controller
Signed-off-by: Omer Aplatony <[email protected]>
1 parent 6cbd449 commit 697934c

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

vertical-pod-autoscaler/pkg/admission-controller/resource/vpa/handler.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ func ValidateVPA(vpa *vpa_types.VerticalPodAutoscaler, isCreate bool) error {
137137
return fmt.Errorf("containerPolicies.ContainerName is required")
138138
}
139139

140+
// check that perVPA is on if being used
141+
if err := validatePerVPAFeatureFlag(&policy); err != nil {
142+
return err
143+
}
144+
140145
// Validate OOMBumpUpRatio
141146
if policy.OOMBumpUpRatio != nil {
142147
ratio := float64(policy.OOMBumpUpRatio.MilliValue()) / 1000.0
@@ -217,3 +222,12 @@ func validateMemoryResolution(val apires.Quantity) error {
217222
}
218223
return nil
219224
}
225+
226+
func validatePerVPAFeatureFlag(policy *vpa_types.ContainerResourcePolicy) error {
227+
featureFlagOn := features.Enabled(features.PerVPAConfig)
228+
perVPA := policy.OOMBumpUpRatio != nil || policy.OOMMinBumpUp != nil
229+
if !featureFlagOn && perVPA {
230+
return fmt.Errorf("OOMBumpUpRatio and OOMMinBumpUp are not supported when feature flag %s is disabled", features.PerVPAConfig)
231+
}
232+
return nil
233+
}

vertical-pod-autoscaler/pkg/admission-controller/resource/vpa/handler_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func TestValidateVPA(t *testing.T) {
5151
isCreate bool
5252
expectError error
5353
inPlaceOrRecreateFeatureGateDisabled bool
54+
PerVPAConfigDisabled bool
5455
}{
5556
{
5657
name: "empty update",
@@ -319,10 +320,64 @@ func TestValidateVPA(t *testing.T) {
319320
},
320321
},
321322
},
323+
{
324+
name: "per-vpa config active and used",
325+
vpa: vpa_types.VerticalPodAutoscaler{
326+
Spec: vpa_types.VerticalPodAutoscalerSpec{
327+
UpdatePolicy: &vpa_types.PodUpdatePolicy{
328+
UpdateMode: &validUpdateMode,
329+
},
330+
ResourcePolicy: &vpa_types.PodResourcePolicy{
331+
ContainerPolicies: []vpa_types.ContainerResourcePolicy{
332+
{
333+
ContainerName: "loot box",
334+
Mode: &validScalingMode,
335+
MinAllowed: apiv1.ResourceList{
336+
cpu: resource.MustParse("10"),
337+
},
338+
MaxAllowed: apiv1.ResourceList{
339+
cpu: resource.MustParse("100"),
340+
},
341+
OOMBumpUpRatio: resource.NewQuantity(2, resource.DecimalSI),
342+
},
343+
},
344+
},
345+
},
346+
},
347+
PerVPAConfigDisabled: false,
348+
},
349+
{
350+
name: "per-vpa config disabled and used",
351+
vpa: vpa_types.VerticalPodAutoscaler{
352+
Spec: vpa_types.VerticalPodAutoscalerSpec{
353+
UpdatePolicy: &vpa_types.PodUpdatePolicy{
354+
UpdateMode: &validUpdateMode,
355+
},
356+
ResourcePolicy: &vpa_types.PodResourcePolicy{
357+
ContainerPolicies: []vpa_types.ContainerResourcePolicy{
358+
{
359+
ContainerName: "loot box",
360+
Mode: &validScalingMode,
361+
MinAllowed: apiv1.ResourceList{
362+
cpu: resource.MustParse("10"),
363+
},
364+
MaxAllowed: apiv1.ResourceList{
365+
cpu: resource.MustParse("100"),
366+
},
367+
OOMMinBumpUp: resource.NewQuantity(2, resource.DecimalSI),
368+
},
369+
},
370+
},
371+
},
372+
},
373+
PerVPAConfigDisabled: true,
374+
expectError: fmt.Errorf("OOMBumpUpRatio and OOMMinBumpUp are not supported when feature flag PerVPAConfig is disabled"),
375+
},
322376
}
323377
for _, tc := range tests {
324378
t.Run(fmt.Sprintf("test case: %s", tc.name), func(t *testing.T) {
325379
featuregatetesting.SetFeatureGateDuringTest(t, features.MutableFeatureGate, features.InPlaceOrRecreate, !tc.inPlaceOrRecreateFeatureGateDisabled)
380+
featuregatetesting.SetFeatureGateDuringTest(t, features.MutableFeatureGate, features.PerVPAConfig, !tc.PerVPAConfigDisabled)
326381
err := ValidateVPA(&tc.vpa, tc.isCreate)
327382
if tc.expectError == nil {
328383
assert.NoError(t, err)

vertical-pod-autoscaler/pkg/features/features.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const (
5050
InPlaceOrRecreate featuregate.Feature = "InPlaceOrRecreate"
5151

5252
// alpha: v1.5.0
53-
// components: recommender
53+
// components: recommender, updater
5454

5555
// PerVPAConfig enables the ability to specify component-specific configuration
5656
// parameters at the individual VPA object level. This allows for different

0 commit comments

Comments
 (0)