Skip to content

Commit f035e37

Browse files
Added e2e test and fixed existing pod test
1 parent 94ddb3a commit f035e37

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

pkg/util/pod/pod_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package pod
1818

1919
import (
2020
"context"
21-
"fmt"
2221
"testing"
2322

2423
"reflect"
@@ -52,7 +51,7 @@ func TestPatchPodStatus(t *testing.T) {
5251
"no change",
5352
func(input v1.PodStatus) v1.PodStatus { return input },
5453
true,
55-
[]byte(fmt.Sprintf(`{"metadata":{"uid":"myuid"}}`)),
54+
[]byte(`{"metadata":{"uid":"myuid"}}`),
5655
},
5756
{
5857
"message change",
@@ -61,7 +60,7 @@ func TestPatchPodStatus(t *testing.T) {
6160
return input
6261
},
6362
false,
64-
[]byte(fmt.Sprintf(`{"metadata":{"uid":"myuid"},"status":{"message":"random message"}}`)),
63+
[]byte(`{"metadata":{"uid":"myuid"},"status":{"message":"random message"}}`),
6564
},
6665
{
6766
"pod condition change",
@@ -70,7 +69,7 @@ func TestPatchPodStatus(t *testing.T) {
7069
return input
7170
},
7271
false,
73-
[]byte(fmt.Sprintf(`{"metadata":{"uid":"myuid"},"status":{"$setElementOrder/conditions":[{"type":"Ready"},{"type":"PodScheduled"}],"conditions":[{"status":"False","type":"Ready"}]}}`)),
72+
[]byte(`{"metadata":{"uid":"myuid"},"status":{"$setElementOrder/conditions":[{"type":"Ready"},{"type":"PodScheduled"}],"conditions":[{"status":"False","type":"Ready"}]}}`),
7473
},
7574
{
7675
"additional init container condition",
@@ -84,7 +83,7 @@ func TestPatchPodStatus(t *testing.T) {
8483
return input
8584
},
8685
false,
87-
[]byte(fmt.Sprintf(`{"metadata":{"uid":"myuid"},"status":{"initContainerStatuses":[{"image":"","imageID":"","lastState":{},"name":"init-container","ready":true,"restartCount":0,"state":{}}]}}`)),
86+
[]byte(`{"metadata":{"uid":"myuid"},"status":{"initContainerStatuses":[{"image":"","imageID":"","lastState":{},"name":"init-container","ready":true,"restartCount":0,"state":{}}]}}`),
8887
},
8988
}
9089
for _, tc := range testCases {

test/e2e/common/node/lifecycle_hook.go

+41
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
v1 "k8s.io/api/core/v1"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"k8s.io/apimachinery/pkg/util/intstr"
28+
utilrand "k8s.io/apimachinery/pkg/util/rand"
2829
"k8s.io/kubernetes/test/e2e/feature"
2930
"k8s.io/kubernetes/test/e2e/framework"
3031
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
@@ -661,3 +662,43 @@ var _ = SIGDescribe(feature.PodLifecycleSleepActionAllowZero, func() {
661662

662663
})
663664
})
665+
666+
var _ = SIGDescribe(feature.ContainerStopSignals, func() {
667+
f := framework.NewDefaultFramework("container-stop-signals")
668+
f.NamespacePodSecurityLevel = admissionapi.LevelBaseline
669+
var podClient *e2epod.PodClient
670+
sigterm := v1.SIGTERM
671+
podName := "pod-" + utilrand.String(5)
672+
673+
ginkgo.Context("when create a pod with a StopSignal lifecycle", func() {
674+
ginkgo.BeforeEach(func(ctx context.Context) {
675+
podClient = e2epod.NewPodClient(f)
676+
})
677+
ginkgo.It("StopSignal defined with pod.OS", func(ctx context.Context) {
678+
679+
testPod := e2epod.MustMixinRestrictedPodSecurity(&v1.Pod{
680+
ObjectMeta: metav1.ObjectMeta{
681+
Name: podName,
682+
},
683+
Spec: v1.PodSpec{
684+
OS: &v1.PodOS{
685+
Name: v1.Linux,
686+
},
687+
Containers: []v1.Container{
688+
{
689+
Name: "test",
690+
Image: imageutils.GetPauseImageName(),
691+
Lifecycle: &v1.Lifecycle{
692+
StopSignal: &sigterm,
693+
},
694+
},
695+
},
696+
},
697+
})
698+
699+
ginkgo.By("submitting the pod to kubernetes")
700+
pod := podClient.CreateSync(ctx, testPod)
701+
framework.ExpectNoError(e2epod.WaitForPodRunningInNamespace(ctx, f.ClientSet, pod), "Pod didn't start when custom StopSignal was passed in Lifecycle")
702+
})
703+
})
704+
})

test/e2e/feature/feature.go

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ var (
6666
// TODO: document the feature (owning SIG, when to use this feature for a test)
6767
ComprehensiveNamespaceDraining = framework.WithFeature(framework.ValidFeatures.Add("ComprehensiveNamespaceDraining"))
6868

69+
// Owner: sig-node
70+
// Enables configuring custom stop signals for containers from container lifecycle
71+
ContainerStopSignals = framework.WithFeature(framework.ValidFeatures.Add("ContainerStopSignals"))
72+
6973
// Owner: sig-api-machinery
7074
// Marks tests that require coordinated leader election
7175
CoordinatedLeaderElection = framework.WithFeature(framework.ValidFeatures.Add("CoordinatedLeaderElection"))

0 commit comments

Comments
 (0)