Skip to content

Commit 4bcaa51

Browse files
authored
Merge pull request kubernetes#131267 from tallclair/resize-helpers
Move pod resize e2e utilities out of e2e/framework
2 parents 62129df + 947a9f2 commit 4bcaa51

File tree

6 files changed

+332
-332
lines changed

6 files changed

+332
-332
lines changed

test/e2e/framework/pod/resize.go renamed to test/e2e/common/node/framework/podresize/resize.go

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package pod
17+
package podresize
1818

1919
import (
2020
"context"
@@ -33,6 +33,7 @@ import (
3333
kubecm "k8s.io/kubernetes/pkg/kubelet/cm"
3434
kubeqos "k8s.io/kubernetes/pkg/kubelet/qos"
3535
"k8s.io/kubernetes/test/e2e/framework"
36+
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
3637
imageutils "k8s.io/kubernetes/test/utils/image"
3738

3839
"github.com/onsi/ginkgo/v2"
@@ -302,7 +303,7 @@ func verifyPodContainersStatusResources(gotCtrStatuses []v1.ContainerStatus, wan
302303
func VerifyPodContainersCgroupValues(ctx context.Context, f *framework.Framework, pod *v1.Pod, tcInfo []ResizableContainerInfo) error {
303304
ginkgo.GinkgoHelper()
304305
if podOnCgroupv2Node == nil {
305-
value := IsPodOnCgroupv2Node(f, pod)
306+
value := e2epod.IsPodOnCgroupv2Node(f, pod)
306307
podOnCgroupv2Node = &value
307308
}
308309
cgroupMemLimit := Cgroupv2MemLimit
@@ -344,10 +345,10 @@ func VerifyPodContainersCgroupValues(ctx context.Context, f *framework.Framework
344345
}
345346

346347
if expectedMemLimitString != "0" {
347-
errs = append(errs, VerifyCgroupValue(f, pod, ci.Name, cgroupMemLimit, expectedMemLimitString))
348+
errs = append(errs, e2epod.VerifyCgroupValue(f, pod, ci.Name, cgroupMemLimit, expectedMemLimitString))
348349
}
349-
errs = append(errs, VerifyCgroupValue(f, pod, ci.Name, cgroupCPULimit, expectedCPULimits...))
350-
errs = append(errs, VerifyCgroupValue(f, pod, ci.Name, cgroupCPURequest, strconv.FormatInt(expectedCPUShares, 10)))
350+
errs = append(errs, e2epod.VerifyCgroupValue(f, pod, ci.Name, cgroupCPULimit, expectedCPULimits...))
351+
errs = append(errs, e2epod.VerifyCgroupValue(f, pod, ci.Name, cgroupCPURequest, strconv.FormatInt(expectedCPUShares, 10)))
351352
// TODO(vinaykul,InPlacePodVerticalScaling): Verify oom_score_adj when runc adds support for updating it
352353
// See https://github.com/opencontainers/runc/pull/4669
353354
}
@@ -393,7 +394,7 @@ func verifyContainerRestarts(f *framework.Framework, pod *v1.Pod, gotStatuses []
393394
}
394395

395396
func verifyOomScoreAdj(f *framework.Framework, pod *v1.Pod, containerName string) error {
396-
container := FindContainerInPod(pod, containerName)
397+
container := e2epod.FindContainerInPod(pod, containerName)
397398
if container == nil {
398399
return fmt.Errorf("failed to find container %s in pod %s", containerName, pod.Name)
399400
}
@@ -407,10 +408,10 @@ func verifyOomScoreAdj(f *framework.Framework, pod *v1.Pod, containerName string
407408
oomScoreAdj := kubeqos.GetContainerOOMScoreAdjust(pod, container, int64(nodeMemoryCapacity.Value()))
408409
expectedOomScoreAdj := strconv.FormatInt(int64(oomScoreAdj), 10)
409410

410-
return VerifyOomScoreAdjValue(f, pod, container.Name, expectedOomScoreAdj)
411+
return e2epod.VerifyOomScoreAdjValue(f, pod, container.Name, expectedOomScoreAdj)
411412
}
412413

413-
func WaitForPodResizeActuation(ctx context.Context, f *framework.Framework, podClient *PodClient, pod *v1.Pod, expectedContainers []ResizableContainerInfo) *v1.Pod {
414+
func WaitForPodResizeActuation(ctx context.Context, f *framework.Framework, podClient *e2epod.PodClient, pod *v1.Pod, expectedContainers []ResizableContainerInfo) *v1.Pod {
414415
ginkgo.GinkgoHelper()
415416
// Wait for resize to complete.
416417

@@ -535,3 +536,35 @@ func formatErrors(err error) error {
535536
}
536537
return fmt.Errorf("[\n%s\n]", strings.Join(errStrings, ",\n"))
537538
}
539+
540+
// TODO: Remove the rounded cpu limit values when https://github.com/opencontainers/runc/issues/4622
541+
// is fixed.
542+
func GetCPULimitCgroupExpectations(cpuLimit *resource.Quantity) []string {
543+
var expectedCPULimits []string
544+
milliCPULimit := cpuLimit.MilliValue()
545+
546+
cpuQuota := kubecm.MilliCPUToQuota(milliCPULimit, kubecm.QuotaPeriod)
547+
if cpuLimit.IsZero() {
548+
cpuQuota = -1
549+
}
550+
expectedCPULimits = append(expectedCPULimits, getExpectedCPULimitFromCPUQuota(cpuQuota))
551+
552+
if milliCPULimit%10 != 0 && cpuQuota != -1 {
553+
roundedCPULimit := (milliCPULimit/10 + 1) * 10
554+
cpuQuotaRounded := kubecm.MilliCPUToQuota(roundedCPULimit, kubecm.QuotaPeriod)
555+
expectedCPULimits = append(expectedCPULimits, getExpectedCPULimitFromCPUQuota(cpuQuotaRounded))
556+
}
557+
558+
return expectedCPULimits
559+
}
560+
561+
func getExpectedCPULimitFromCPUQuota(cpuQuota int64) string {
562+
expectedCPULimitString := strconv.FormatInt(cpuQuota, 10)
563+
if *podOnCgroupv2Node {
564+
if expectedCPULimitString == "-1" {
565+
expectedCPULimitString = "max"
566+
}
567+
expectedCPULimitString = fmt.Sprintf("%s %s", expectedCPULimitString, CPUPeriod)
568+
}
569+
return expectedCPULimitString
570+
}

test/e2e/framework/pod/utils_linux_test.go renamed to test/e2e/common/node/framework/podresize/resize_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ See the License for the specific language governing permissions and
1717
limitations under the License.
1818
*/
1919

20-
package pod
20+
package podresize
2121

2222
import (
2323
"testing"

test/e2e/common/node/pod_level_resources.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131
utilerrors "k8s.io/apimachinery/pkg/util/errors"
3232
kubecm "k8s.io/kubernetes/pkg/kubelet/cm"
33+
"k8s.io/kubernetes/test/e2e/common/node/framework/podresize"
3334
"k8s.io/kubernetes/test/e2e/feature"
3435
"k8s.io/kubernetes/test/e2e/framework"
3536
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
@@ -44,7 +45,6 @@ const (
4445
cgroupv2CPULimit string = "cpu.max"
4546
cgroupv2MemLimit string = "memory.max"
4647
cgroupFsPath string = "/sys/fs/cgroup"
47-
CPUPeriod string = "100000"
4848
mountPath string = "/sysfscgroup"
4949
)
5050

@@ -233,7 +233,7 @@ func verifyPodCgroups(ctx context.Context, f *framework.Framework, pod *v1.Pod,
233233
}
234234

235235
cpuLimCgPath := fmt.Sprintf("%s/%s", podCgPath, cgroupv2CPULimit)
236-
expectedCPULimits := e2epod.GetCPULimitCgroupExpectations(expectedResources.Limits.Cpu())
236+
expectedCPULimits := podresize.GetCPULimitCgroupExpectations(expectedResources.Limits.Cpu())
237237

238238
err = e2epod.VerifyCgroupValue(f, pod, pod.Spec.Containers[0].Name, cpuLimCgPath, expectedCPULimits...)
239239
if err != nil {
@@ -394,7 +394,7 @@ func verifyContainersCgroupLimits(f *framework.Framework, pod *v1.Pod) error {
394394

395395
if pod.Spec.Resources != nil && pod.Spec.Resources.Limits.Cpu() != nil &&
396396
container.Resources.Limits.Cpu() == nil {
397-
expectedCPULimits := e2epod.GetCPULimitCgroupExpectations(pod.Spec.Resources.Limits.Cpu())
397+
expectedCPULimits := podresize.GetCPULimitCgroupExpectations(pod.Spec.Resources.Limits.Cpu())
398398
err := e2epod.VerifyCgroupValue(f, pod, container.Name, fmt.Sprintf("%s/%s", cgroupFsPath, cgroupv2CPULimit), expectedCPULimits...)
399399
if err != nil {
400400
errs = append(errs, fmt.Errorf("failed to verify cpu limit cgroup value: %w", err))

0 commit comments

Comments
 (0)