From f035e37c4bffce0f838631bca0ddedf0a38ac956 Mon Sep 17 00:00:00 2001 From: Sreeram Date: Tue, 25 Mar 2025 02:05:30 +0530 Subject: [PATCH] Added e2e test and fixed existing pod test --- pkg/util/pod/pod_test.go | 9 +++--- test/e2e/common/node/lifecycle_hook.go | 41 ++++++++++++++++++++++++++ test/e2e/feature/feature.go | 4 +++ 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/pkg/util/pod/pod_test.go b/pkg/util/pod/pod_test.go index c24a18923ef..fe1849ff910 100644 --- a/pkg/util/pod/pod_test.go +++ b/pkg/util/pod/pod_test.go @@ -18,7 +18,6 @@ package pod import ( "context" - "fmt" "testing" "reflect" @@ -52,7 +51,7 @@ func TestPatchPodStatus(t *testing.T) { "no change", func(input v1.PodStatus) v1.PodStatus { return input }, true, - []byte(fmt.Sprintf(`{"metadata":{"uid":"myuid"}}`)), + []byte(`{"metadata":{"uid":"myuid"}}`), }, { "message change", @@ -61,7 +60,7 @@ func TestPatchPodStatus(t *testing.T) { return input }, false, - []byte(fmt.Sprintf(`{"metadata":{"uid":"myuid"},"status":{"message":"random message"}}`)), + []byte(`{"metadata":{"uid":"myuid"},"status":{"message":"random message"}}`), }, { "pod condition change", @@ -70,7 +69,7 @@ func TestPatchPodStatus(t *testing.T) { return input }, false, - []byte(fmt.Sprintf(`{"metadata":{"uid":"myuid"},"status":{"$setElementOrder/conditions":[{"type":"Ready"},{"type":"PodScheduled"}],"conditions":[{"status":"False","type":"Ready"}]}}`)), + []byte(`{"metadata":{"uid":"myuid"},"status":{"$setElementOrder/conditions":[{"type":"Ready"},{"type":"PodScheduled"}],"conditions":[{"status":"False","type":"Ready"}]}}`), }, { "additional init container condition", @@ -84,7 +83,7 @@ func TestPatchPodStatus(t *testing.T) { return input }, false, - []byte(fmt.Sprintf(`{"metadata":{"uid":"myuid"},"status":{"initContainerStatuses":[{"image":"","imageID":"","lastState":{},"name":"init-container","ready":true,"restartCount":0,"state":{}}]}}`)), + []byte(`{"metadata":{"uid":"myuid"},"status":{"initContainerStatuses":[{"image":"","imageID":"","lastState":{},"name":"init-container","ready":true,"restartCount":0,"state":{}}]}}`), }, } for _, tc := range testCases { diff --git a/test/e2e/common/node/lifecycle_hook.go b/test/e2e/common/node/lifecycle_hook.go index 7359a963403..a666b87f1ff 100644 --- a/test/e2e/common/node/lifecycle_hook.go +++ b/test/e2e/common/node/lifecycle_hook.go @@ -25,6 +25,7 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" + utilrand "k8s.io/apimachinery/pkg/util/rand" "k8s.io/kubernetes/test/e2e/feature" "k8s.io/kubernetes/test/e2e/framework" e2enode "k8s.io/kubernetes/test/e2e/framework/node" @@ -661,3 +662,43 @@ var _ = SIGDescribe(feature.PodLifecycleSleepActionAllowZero, func() { }) }) + +var _ = SIGDescribe(feature.ContainerStopSignals, func() { + f := framework.NewDefaultFramework("container-stop-signals") + f.NamespacePodSecurityLevel = admissionapi.LevelBaseline + var podClient *e2epod.PodClient + sigterm := v1.SIGTERM + podName := "pod-" + utilrand.String(5) + + ginkgo.Context("when create a pod with a StopSignal lifecycle", func() { + ginkgo.BeforeEach(func(ctx context.Context) { + podClient = e2epod.NewPodClient(f) + }) + ginkgo.It("StopSignal defined with pod.OS", func(ctx context.Context) { + + testPod := e2epod.MustMixinRestrictedPodSecurity(&v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: podName, + }, + Spec: v1.PodSpec{ + OS: &v1.PodOS{ + Name: v1.Linux, + }, + Containers: []v1.Container{ + { + Name: "test", + Image: imageutils.GetPauseImageName(), + Lifecycle: &v1.Lifecycle{ + StopSignal: &sigterm, + }, + }, + }, + }, + }) + + ginkgo.By("submitting the pod to kubernetes") + pod := podClient.CreateSync(ctx, testPod) + framework.ExpectNoError(e2epod.WaitForPodRunningInNamespace(ctx, f.ClientSet, pod), "Pod didn't start when custom StopSignal was passed in Lifecycle") + }) + }) +}) diff --git a/test/e2e/feature/feature.go b/test/e2e/feature/feature.go index b785aeee439..7eea6759c5f 100644 --- a/test/e2e/feature/feature.go +++ b/test/e2e/feature/feature.go @@ -66,6 +66,10 @@ var ( // TODO: document the feature (owning SIG, when to use this feature for a test) ComprehensiveNamespaceDraining = framework.WithFeature(framework.ValidFeatures.Add("ComprehensiveNamespaceDraining")) + // Owner: sig-node + // Enables configuring custom stop signals for containers from container lifecycle + ContainerStopSignals = framework.WithFeature(framework.ValidFeatures.Add("ContainerStopSignals")) + // Owner: sig-api-machinery // Marks tests that require coordinated leader election CoordinatedLeaderElection = framework.WithFeature(framework.ValidFeatures.Add("CoordinatedLeaderElection"))