Skip to content

Commit ee87745

Browse files
committed
Split out features.PerVPAConfig tests
1 parent 1ad66f3 commit ee87745

File tree

1 file changed

+45
-29
lines changed

1 file changed

+45
-29
lines changed

vertical-pod-autoscaler/e2e/v1/admission_controller.go

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -888,33 +888,49 @@ var _ = AdmissionControllerE2eDescribe("Admission-controller", func() {
888888
expectedErr string
889889
}{
890890
{
891-
name: "Invalid oomBumpUpRatio (negative value)",
891+
name: "Invalid minAllowed (invalid requests field)",
892892
vpaJSON: `{
893893
"apiVersion": "autoscaling.k8s.io/v1",
894894
"kind": "VerticalPodAutoscaler",
895-
"metadata": {"name": "oom-test-vpa"},
895+
"metadata": {"name": "hamster-vpa-invalid"},
896896
"spec": {
897897
"targetRef": {
898898
"apiVersion": "apps/v1",
899899
"kind": "Deployment",
900-
"name": "oom-test"
901-
},
902-
"updatePolicy": {
903-
"updateMode": "Auto"
900+
"name": "hamster"
904901
},
905902
"resourcePolicy": {
906903
"containerPolicies": [{
907904
"containerName": "*",
908-
"oomBumpUpRatio": -1,
909-
"oomMinBumpUp": 104857600
905+
"minAllowed": {
906+
"requests": {
907+
"cpu": "50m"
908+
}
909+
}
910910
}]
911911
}
912912
}
913913
}`,
914-
expectedErr: "spec.resourcePolicy.containerPolicies[0].oomBumpUpRatio: Invalid value: -1: spec.resourcePolicy.containerPolicies[0].oomBumpUpRatio in body should be greater than or equal to 1",
914+
expectedErr: "admission webhook .*vpa.* denied the request:",
915915
},
916+
}
917+
for _, tc := range testCases {
918+
ginkgo.By(fmt.Sprintf("Testing %s", tc.name))
919+
err := InstallRawVPA(f, []byte(tc.vpaJSON))
920+
gomega.Expect(err).To(gomega.HaveOccurred(), "Invalid VPA object accepted")
921+
gomega.Expect(err.Error()).To(gomega.MatchRegexp(tc.expectedErr))
922+
}
923+
})
924+
925+
f.It("accepts valid and rejects invalid VPA object with features.PerVPAConfig enabled", framework.WithFeatureGate(features.PerVPAConfig), func() {
926+
ginkgo.By("Setting up invalid VPA objects")
927+
testCases := []struct {
928+
name string
929+
vpaJSON string
930+
expectedErr string
931+
}{
916932
{
917-
name: "Invalid oomBumpUpRatio (string value)",
933+
name: "Invalid oomBumpUpRatio (negative value)",
918934
vpaJSON: `{
919935
"apiVersion": "autoscaling.k8s.io/v1",
920936
"kind": "VerticalPodAutoscaler",
@@ -931,16 +947,16 @@ var _ = AdmissionControllerE2eDescribe("Admission-controller", func() {
931947
"resourcePolicy": {
932948
"containerPolicies": [{
933949
"containerName": "*",
934-
"oomBumpUpRatio": "12",
950+
"oomBumpUpRatio": -1,
935951
"oomMinBumpUp": 104857600
936952
}]
937953
}
938954
}
939955
}`,
940-
expectedErr: "json: cannot unmarshal string into Go struct field ContainerResourcePolicy.spec.resourcePolicy.containerPolicies.oomBumpUpRatio of type float64",
956+
expectedErr: "admission webhook \"vpa.k8s.io\" denied the request: oomBumpUpRatio must be greater than or equal to 1.0, got -1",
941957
},
942958
{
943-
name: "Invalid oomBumpUpRatio (less than 1)",
959+
name: "Invalid oomBumpUpRatio (string value)",
944960
vpaJSON: `{
945961
"apiVersion": "autoscaling.k8s.io/v1",
946962
"kind": "VerticalPodAutoscaler",
@@ -957,16 +973,16 @@ var _ = AdmissionControllerE2eDescribe("Admission-controller", func() {
957973
"resourcePolicy": {
958974
"containerPolicies": [{
959975
"containerName": "*",
960-
"oomBumpUpRatio": 0.5,
976+
"oomBumpUpRatio": "not-a-number",
961977
"oomMinBumpUp": 104857600
962978
}]
963979
}
964980
}
965981
}`,
966-
expectedErr: "spec.resourcePolicy.containerPolicies[0].oomBumpUpRatio: Invalid value: 0.5: spec.resourcePolicy.containerPolicies[0].oomBumpUpRatio in body should be greater than or equal to 1",
982+
expectedErr: "admission webhook \"vpa\\.k8s\\.io\" denied the request: quantities must match the regular expression",
967983
},
968984
{
969-
name: "Invalid oomMinBumpUp (negative value)",
985+
name: "Invalid oomBumpUpRatio (less than 1)",
970986
vpaJSON: `{
971987
"apiVersion": "autoscaling.k8s.io/v1",
972988
"kind": "VerticalPodAutoscaler",
@@ -983,45 +999,45 @@ var _ = AdmissionControllerE2eDescribe("Admission-controller", func() {
983999
"resourcePolicy": {
9841000
"containerPolicies": [{
9851001
"containerName": "*",
986-
"oomBumpUpRatio": 2,
987-
"oomMinBumpUp": -1
1002+
"oomBumpUpRatio": 0.5,
1003+
"oomMinBumpUp": 104857600
9881004
}]
9891005
}
9901006
}
9911007
}`,
992-
expectedErr: "spec.resourcePolicy.containerPolicies[0].oomMinBumpUp: Invalid value: -1: spec.resourcePolicy.containerPolicies[0].oomMinBumpUp in body should be greater than or equal to 0",
1008+
expectedErr: "admission webhook \"vpa.k8s.io\" denied the request: oomBumpUpRatio must be greater than or equal to 1.0, got 0.5",
9931009
},
9941010
{
995-
name: "Invalid minAllowed (invalid requests field)",
1011+
name: "Invalid oomMinBumpUp (negative value)",
9961012
vpaJSON: `{
9971013
"apiVersion": "autoscaling.k8s.io/v1",
9981014
"kind": "VerticalPodAutoscaler",
999-
"metadata": {"name": "hamster-vpa-invalid"},
1015+
"metadata": {"name": "oom-test-vpa"},
10001016
"spec": {
10011017
"targetRef": {
10021018
"apiVersion": "apps/v1",
10031019
"kind": "Deployment",
1004-
"name": "hamster"
1020+
"name": "oom-test"
1021+
},
1022+
"updatePolicy": {
1023+
"updateMode": "Auto"
10051024
},
10061025
"resourcePolicy": {
10071026
"containerPolicies": [{
10081027
"containerName": "*",
1009-
"minAllowed": {
1010-
"requests": {
1011-
"cpu": "50m"
1012-
}
1013-
}
1028+
"oomBumpUpRatio": 2,
1029+
"oomMinBumpUp": -1
10141030
}]
10151031
}
10161032
}
10171033
}`,
1018-
expectedErr: "admission webhook .*vpa.* denied the request:",
1034+
expectedErr: "admission webhook \"vpa.k8s.io\" denied the request: oomMinBumpUp must be greater than or equal to 0, got -1 bytes",
10191035
},
10201036
}
10211037
for _, tc := range testCases {
10221038
ginkgo.By(fmt.Sprintf("Testing %s", tc.name))
10231039
err := InstallRawVPA(f, []byte(tc.vpaJSON))
1024-
gomega.Expect(err).To(gomega.HaveOccurred(), "Invalid VPA object accepted")
1040+
gomega.Expect(err).To(gomega.HaveOccurred(), fmt.Sprintf("Invalid VPA object accepted, name: \"%s\"", tc.name))
10251041
gomega.Expect(err.Error()).To(gomega.MatchRegexp(tc.expectedErr))
10261042
}
10271043
})

0 commit comments

Comments
 (0)