@@ -3,7 +3,6 @@ package integration
3
3
import (
4
4
"testing"
5
5
6
- apierrors "k8s.io/apimachinery/pkg/api/errors"
7
6
"k8s.io/apimachinery/pkg/api/resource"
8
7
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9
8
kapi "k8s.io/kubernetes/pkg/apis/core"
@@ -96,12 +95,27 @@ func TestClusterResourceOverridePluginWithLimits(t *testing.T) {
96
95
t .Errorf ("limit-with-default: CPU req did not match expected 250 mcore: %v" , cpu )
97
96
}
98
97
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 )
105
119
}
106
120
}
107
121
0 commit comments