mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Make e2e node tests more resiliant by ensuring the SIGTERM trap is registered
This commit is contained in:
parent
3ec6a38795
commit
dccb775d6e
@ -20,7 +20,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@ -163,11 +162,20 @@ var _ = SIGDescribe("Deleted pods handling", framework.WithNodeConformance(), fu
|
|||||||
}
|
}
|
||||||
|
|
||||||
trap _term SIGTERM
|
trap _term SIGTERM
|
||||||
|
touch /tmp/trap-marker
|
||||||
wait $PID
|
wait $PID
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
ReadinessProbe: &v1.Probe{
|
||||||
|
PeriodSeconds: 1,
|
||||||
|
ProbeHandler: v1.ProbeHandler{
|
||||||
|
Exec: &v1.ExecAction{
|
||||||
|
Command: []string{"/bin/sh", "-c", "cat /tmp/trap-marker"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -178,13 +186,11 @@ var _ = SIGDescribe("Deleted pods handling", framework.WithNodeConformance(), fu
|
|||||||
ginkgo.By("set up cleanup of the finalizer")
|
ginkgo.By("set up cleanup of the finalizer")
|
||||||
ginkgo.DeferCleanup(e2epod.NewPodClient(f).RemoveFinalizer, pod.Name, testFinalizer)
|
ginkgo.DeferCleanup(e2epod.NewPodClient(f).RemoveFinalizer, pod.Name, testFinalizer)
|
||||||
|
|
||||||
ginkgo.By("Waiting for the pod to be running")
|
ginkgo.By(fmt.Sprintf("Waiting for the pod (%v/%v) to be running and with the SIGTERM trap registered", pod.Namespace, pod.Name))
|
||||||
err := e2epod.WaitForPodNameRunningInNamespace(ctx, f.ClientSet, pod.Name, f.Namespace.Name)
|
err := e2epod.WaitTimeoutForPodReadyInNamespace(ctx, f.ClientSet, pod.Name, f.Namespace.Name, f.Timeouts.PodStart)
|
||||||
framework.ExpectNoError(err, "Failed to await for the pod to be running: %q", pod.Name)
|
framework.ExpectNoError(err, "Failed to await for the pod to be running: %q", pod.Name)
|
||||||
|
|
||||||
ginkgo.By(fmt.Sprintf("Deleting the pod (%v/%v) to set a deletion timestamp", pod.Namespace, pod.Name))
|
ginkgo.By(fmt.Sprintf("Deleting the pod (%v/%v) to set a deletion timestamp", pod.Namespace, pod.Name))
|
||||||
// wait a little bit to make sure the we are inside the while and that the trap is registered
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
err = e2epod.NewPodClient(f).Delete(ctx, pod.Name, metav1.DeleteOptions{})
|
err = e2epod.NewPodClient(f).Delete(ctx, pod.Name, metav1.DeleteOptions{})
|
||||||
framework.ExpectNoError(err, "Failed to delete the pod: %q", pod.Name)
|
framework.ExpectNoError(err, "Failed to delete the pod: %q", pod.Name)
|
||||||
|
|
||||||
|
@ -296,6 +296,8 @@ var _ = SIGDescribe("Restart", framework.WithSerial(), framework.WithSlow(), fra
|
|||||||
}
|
}
|
||||||
|
|
||||||
trap _term SIGTERM
|
trap _term SIGTERM
|
||||||
|
touch /tmp/trap-marker
|
||||||
|
|
||||||
wait $PID
|
wait $PID
|
||||||
trap - TERM
|
trap - TERM
|
||||||
|
|
||||||
@ -305,6 +307,14 @@ var _ = SIGDescribe("Restart", framework.WithSerial(), framework.WithSlow(), fra
|
|||||||
exit 0
|
exit 0
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
ReadinessProbe: &v1.Probe{
|
||||||
|
PeriodSeconds: 1,
|
||||||
|
ProbeHandler: v1.ProbeHandler{
|
||||||
|
Exec: &v1.ExecAction{
|
||||||
|
Command: []string{"/bin/sh", "-c", "cat /tmp/trap-marker"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -312,8 +322,8 @@ var _ = SIGDescribe("Restart", framework.WithSerial(), framework.WithSlow(), fra
|
|||||||
ginkgo.By(fmt.Sprintf("Creating a pod (%v/%v) with restart policy: %v", f.Namespace.Name, podName, podSpec.Spec.RestartPolicy))
|
ginkgo.By(fmt.Sprintf("Creating a pod (%v/%v) with restart policy: %v", f.Namespace.Name, podName, podSpec.Spec.RestartPolicy))
|
||||||
pod := e2epod.NewPodClient(f).Create(ctx, podSpec)
|
pod := e2epod.NewPodClient(f).Create(ctx, podSpec)
|
||||||
|
|
||||||
ginkgo.By(fmt.Sprintf("Waiting for the pod (%v/%v) to be running", f.Namespace.Name, pod.Name))
|
ginkgo.By(fmt.Sprintf("Waiting for the pod (%v/%v) to be running, and with the SIGTERM trap registered", f.Namespace.Name, pod.Name))
|
||||||
err := e2epod.WaitForPodNameRunningInNamespace(ctx, f.ClientSet, pod.Name, f.Namespace.Name)
|
err := e2epod.WaitTimeoutForPodReadyInNamespace(ctx, f.ClientSet, pod.Name, f.Namespace.Name, f.Timeouts.PodStart)
|
||||||
framework.ExpectNoError(err, "Failed to await for the pod to be running: (%v/%v)", f.Namespace.Name, pod.Name)
|
framework.ExpectNoError(err, "Failed to await for the pod to be running: (%v/%v)", f.Namespace.Name, pod.Name)
|
||||||
|
|
||||||
w := &cache.ListWatch{
|
w := &cache.ListWatch{
|
||||||
@ -326,7 +336,6 @@ var _ = SIGDescribe("Restart", framework.WithSerial(), framework.WithSlow(), fra
|
|||||||
framework.ExpectNoError(err, "Failed to list pods in namespace: %s", f.Namespace.Name)
|
framework.ExpectNoError(err, "Failed to list pods in namespace: %s", f.Namespace.Name)
|
||||||
|
|
||||||
ginkgo.By(fmt.Sprintf("Deleting the pod (%v/%v) to set a deletion timestamp", pod.Namespace, pod.Name))
|
ginkgo.By(fmt.Sprintf("Deleting the pod (%v/%v) to set a deletion timestamp", pod.Namespace, pod.Name))
|
||||||
time.Sleep(time.Second)
|
|
||||||
err = e2epod.NewPodClient(f).Delete(ctx, pod.Name, metav1.DeleteOptions{GracePeriodSeconds: &gracePeriod})
|
err = e2epod.NewPodClient(f).Delete(ctx, pod.Name, metav1.DeleteOptions{GracePeriodSeconds: &gracePeriod})
|
||||||
framework.ExpectNoError(err, "Failed to delete the pod: %q", pod.Name)
|
framework.ExpectNoError(err, "Failed to delete the pod: %q", pod.Name)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user