Skip to content

Commit 917c4b3

Browse files
committed
Fix lint issues, use kuberuntime's minGracePeriod const, boost container restart wait period
1 parent d5d008a commit 917c4b3

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

pkg/kubelet/kuberuntime/kuberuntime_manager.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,15 @@ const (
7777
kubeRuntimeAPIVersion = "0.1.0"
7878
// A minimal shutdown window for avoiding unnecessary SIGKILLs
7979
minimumGracePeriodInSeconds = 2
80+
MinimumGracePeriodInSeconds = int64(minimumGracePeriodInSeconds)
8081

8182
// The expiration time of version cache.
8283
versionCacheTTL = 60 * time.Second
8384
// How frequently to report identical errors
8485
identicalErrorDelay = 1 * time.Minute
8586
// OpenTelemetry instrumentation scope name
8687
instrumentationScope = "k8s.io/kubernetes/pkg/kubelet/kuberuntime"
88+
8789
)
8890

8991
var (

test/e2e/common/node/pod_resize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ func doPodResizeErrorTests() {
14401440
// Above tests are performed by doSheduletTests() and doPodResizeResourceQuotaTests()
14411441
// in test/e2e/node/pod_resize.go
14421442

1443-
var _ = SIGDescribe("[InPlacePodResize] Pod InPlace Resize Container", feature.InPlacePodVerticalScaling, func() {
1443+
var _ = SIGDescribe("Pod InPlace Resize Container", feature.InPlacePodVerticalScaling, func() {
14441444
f := framework.NewDefaultFramework("pod-resize-tests")
14451445

14461446
ginkgo.BeforeEach(func(ctx context.Context) {

test/e2e/framework/pod/resize.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
utilerrors "k8s.io/apimachinery/pkg/util/errors"
3232
helpers "k8s.io/component-helpers/resource"
3333
kubecm "k8s.io/kubernetes/pkg/kubelet/cm"
34+
"k8s.io/kubernetes/pkg/kubelet/kuberuntime"
3435
"k8s.io/kubernetes/test/e2e/framework"
3536
imageutils "k8s.io/kubernetes/test/utils/image"
3637

@@ -49,7 +50,7 @@ const (
4950
Cgroupv2CPURequest string = "/sys/fs/cgroup/cpu.weight"
5051
CPUPeriod string = "100000"
5152
MinContainerRuntimeVersion string = "1.6.9"
52-
MinimumGracePeriodSeconds int64 = 2
53+
MinRestartWaitPeriod int = 10
5354
)
5455

5556
var (
@@ -169,7 +170,7 @@ func makeResizableContainer(tcInfo ResizableContainerInfo) v1.Container {
169170
func MakePodWithResizableContainers(ns, name, timeStamp string, tcInfo []ResizableContainerInfo) *v1.Pod {
170171
testInitContainers, testContainers := separateContainers(tcInfo)
171172

172-
var minGracePeriodSeconds int64 = MinimumGracePeriodSeconds
173+
minGracePeriodSeconds := kuberuntime.MinimumGracePeriodInSeconds
173174
pod := &v1.Pod{
174175
ObjectMeta: metav1.ObjectMeta{
175176
Name: name,
@@ -354,7 +355,8 @@ func VerifyPodContainersCgroupValues(ctx context.Context, f *framework.Framework
354355
}
355356
errs = append(errs, VerifyCgroupValue(f, pod, ci.Name, cgroupCPULimit, expectedCPULimitString))
356357
errs = append(errs, VerifyCgroupValue(f, pod, ci.Name, cgroupCPURequest, strconv.FormatInt(expectedCPUShares, 10)))
357-
//TODO(vinaykul,InPlacePodVerticalScaling): Verify oom_score_adj when runc adds support for updating it
358+
// TODO(vinaykul,InPlacePodVerticalScaling): Verify oom_score_adj when runc adds support for updating it
359+
// See https://github.com/opencontainers/runc/pull/4669
358360
}
359361
}
360362
return utilerrors.NewAggregate(errs)
@@ -425,8 +427,12 @@ func WaitForPodResizeActuation(ctx context.Context, f *framework.Framework, podC
425427
})),
426428
)
427429

428-
// Wait 2x termination grace period to catch any restarts - expected or not
429-
time.Sleep(time.Duration(*pod.Spec.TerminationGracePeriodSeconds*2) * time.Second)
430+
// Wait min(3 x termination grace period, MinRestartWaitPeriod) to catch any restarts - expected or not
431+
containerRestartWaitPeriod := int(*pod.Spec.TerminationGracePeriodSeconds) * 3
432+
if containerRestartWaitPeriod < MinRestartWaitPeriod {
433+
containerRestartWaitPeriod = MinRestartWaitPeriod
434+
}
435+
time.Sleep(time.Duration(containerRestartWaitPeriod) * time.Second)
430436
resizedPod, err := framework.GetObject(podClient.Get, pod.Name, metav1.GetOptions{})(ctx)
431437
framework.ExpectNoError(err, "failed to get resized pod")
432438
return resizedPod

test/e2e/framework/pod/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func VerifyCgroupValue(f *framework.Framework, pod *v1.Pod, cName, cgPath, expec
298298
// has the expected value in specified container of the pod. It execs into the container,
299299
// reads the oom_score_adj value from procfs, and compares it against the expected value.
300300
func VerifyOomScoreAdjValue(f *framework.Framework, pod *v1.Pod, cName, expectedOomScoreAdj string) error {
301-
cmd := fmt.Sprintf("cat /proc/1/oom_score_adj")
301+
cmd := "cat /proc/1/oom_score_adj"
302302
framework.Logf("Namespace %s Pod %s Container %s - looking for oom_score_adj value %s",
303303
pod.Namespace, pod.Name, cName, expectedOomScoreAdj)
304304
oomScoreAdj, _, err := ExecCommandInContainerWithFullOutput(f, pod.Name, cName, "/bin/sh", "-c", cmd)

0 commit comments

Comments
 (0)