Skip to content

Commit b886341

Browse files
committed
Fix integration tests as CRO will now floor to CPU & Memory limits
1 parent ad179fc commit b886341

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

test/integration/clusterresourceoverride_admission_test.go

+21-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package integration
33
import (
44
"testing"
55

6-
apierrors "k8s.io/apimachinery/pkg/api/errors"
76
"k8s.io/apimachinery/pkg/api/resource"
87
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
98
kapi "k8s.io/kubernetes/pkg/apis/core"
@@ -96,12 +95,27 @@ func TestClusterResourceOverridePluginWithLimits(t *testing.T) {
9695
t.Errorf("limit-with-default: CPU req did not match expected 250 mcore: %v", cpu)
9796
}
9897

99-
// set it up so that the overrides create resources that fail validation
100-
_, err = podHandler.Create(testClusterResourceOverridePod("limit-with-default-fail", "128Mi", "1"))
101-
if err == nil {
102-
t.Errorf("limit-with-default-fail: expected to be forbidden")
103-
} else if !apierrors.IsForbidden(err) {
104-
t.Errorf("limit-with-default-fail: unexpected error: %v", err)
98+
// CRO admission plugin now ensures that a limit does not fall
99+
// below the minimum across all containers in the namespace
100+
// and validation should never fail. Create a POD that would
101+
// ordinarily fail validation checks but notice that it a)
102+
// doesn't fail and b) the CPU limits and requests are clamped
103+
// to the floor of CPU and Memory respectively.
104+
podCreated, err = podHandler.Create(testClusterResourceOverridePod("limit-with-min-floor-cpu", "128Mi", "1"))
105+
if err != nil {
106+
t.Fatalf("unexpected error: %v", err)
107+
}
108+
if memory := podCreated.Spec.Containers[0].Resources.Limits.Memory(); memory.Cmp(resource.MustParse("128Mi")) != 0 {
109+
t.Errorf("limit-with-min-floor-cpu: Memory limit did not match default 128Mi: %v", memory)
110+
}
111+
if memory := podCreated.Spec.Containers[0].Resources.Requests.Memory(); memory.Cmp(resource.MustParse("128Mi")) != 0 {
112+
t.Errorf("limit-with-min-floor-cpu: Memory req did not match expected 128Mi: %v", memory)
113+
}
114+
if cpu := podCreated.Spec.Containers[0].Resources.Limits.Cpu(); cpu.Cmp(resource.MustParse("200m")) != 0 {
115+
t.Errorf("limit-with-min-floor-cpu: CPU limit did not match expected 200 mcore: %v", cpu)
116+
}
117+
if cpu := podCreated.Spec.Containers[0].Resources.Requests.Cpu(); cpu.Cmp(resource.MustParse("200m")) != 0 {
118+
t.Errorf("limit-with-min-floor-cpu: CPU req did not match expected 200 mcore: %v", cpu)
105119
}
106120
}
107121

0 commit comments

Comments
 (0)