De-share the Handler struct in core API (#105979)

* De-share the Handler struct in core API

An upcoming PR adds a handler that only applies on one of these paths.
Having fields that don't work seems bad.

This never should have been shared.  Lifecycle hooks are like a "write"
while probes are more like a "read". HTTPGet and TCPSocket don't really
make sense as lifecycle hooks (but I can't take that back). When we add
gRPC, it is EXPLICITLY a health check (defined by gRPC) not an arbitrary
RPC - so a probe makes sense but a hook does not.

In the future I can also see adding lifecycle hooks that don't make
sense as probes.  E.g. 'sleep' is a common lifecycle request. The only
option is `exec`, which requires having a sleep binary in your image.

* Run update scripts
This commit is contained in:
Tim Hockin
2021-10-29 13:15:11 -07:00
committed by GitHub
parent adff4a75ad
commit 11a25bfeb6
55 changed files with 2625 additions and 2093 deletions

View File

@@ -296,7 +296,7 @@ func deployCustomResourceWebhookAndService(f *framework.Framework, image string,
fmt.Sprintf("--port=%d", containerPort),
},
ReadinessProbe: &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Scheme: v1.URISchemeHTTPS,
Port: intstr.FromInt(int(containerPort)),

View File

@@ -22,7 +22,7 @@ import (
"time"
batchv1 "k8s.io/api/batch/v1"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
@@ -52,7 +52,7 @@ func testingPod(name, value string) v1.Pod {
Image: imageutils.GetE2EImage(imageutils.Nginx),
Ports: []v1.ContainerPort{{ContainerPort: 80}},
LivenessProbe: &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Path: "/index.html",
Port: intstr.FromInt(8080),

View File

@@ -797,7 +797,7 @@ func deployWebhookAndService(f *framework.Framework, image string, certCtx *cert
fmt.Sprintf("--port=%d", containerPort),
},
ReadinessProbe: &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Scheme: v1.URISchemeHTTPS,
Port: intstr.FromInt(int(containerPort)),

View File

@@ -513,7 +513,7 @@ var _ = SIGDescribe("Daemon set [Serial]", func() {
}
// delay shutdown by 15s to allow containers to overlap in time
ds.Spec.Template.Spec.Containers[0].Lifecycle = &v1.Lifecycle{
PreStop: &v1.Handler{
PreStop: &v1.LifecycleHandler{
Exec: &v1.ExecAction{
Command: []string{"/bin/sh", "-c", "sleep 15"},
},
@@ -521,7 +521,7 @@ var _ = SIGDescribe("Daemon set [Serial]", func() {
}
// use a readiness probe that can be forced to fail (by changing the contents of /var/tmp/ready)
ds.Spec.Template.Spec.Containers[0].ReadinessProbe = &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
Exec: &v1.ExecAction{
Command: []string{"/bin/sh", "-ec", `touch /var/tmp/ready; [[ "$( cat /var/tmp/ready )" == "" ]]`},
},

View File

@@ -71,7 +71,7 @@ const (
)
var httpProbe = &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Path: "/index.html",
Port: intstr.IntOrString{IntVal: 80},

View File

@@ -123,7 +123,7 @@ var _ = SIGDescribe("Probing container", func() {
framework.ConformanceIt("should be restarted with a exec \"cat /tmp/health\" liveness probe [NodeConformance]", func() {
cmd := []string{"/bin/sh", "-c", "echo ok >/tmp/health; sleep 10; rm -rf /tmp/health; sleep 600"}
livenessProbe := &v1.Probe{
Handler: execHandler([]string{"cat", "/tmp/health"}),
ProbeHandler: execHandler([]string{"cat", "/tmp/health"}),
InitialDelaySeconds: 15,
TimeoutSeconds: 5, // default 1s can be pretty aggressive in CI environments with low resources
FailureThreshold: 1,
@@ -140,7 +140,7 @@ var _ = SIGDescribe("Probing container", func() {
framework.ConformanceIt("should *not* be restarted with a exec \"cat /tmp/health\" liveness probe [NodeConformance]", func() {
cmd := []string{"/bin/sh", "-c", "echo ok >/tmp/health; sleep 600"}
livenessProbe := &v1.Probe{
Handler: execHandler([]string{"cat", "/tmp/health"}),
ProbeHandler: execHandler([]string{"cat", "/tmp/health"}),
InitialDelaySeconds: 15,
TimeoutSeconds: 5, // default 1s can be pretty aggressive in CI environments with low resources
FailureThreshold: 1,
@@ -156,7 +156,7 @@ var _ = SIGDescribe("Probing container", func() {
*/
framework.ConformanceIt("should be restarted with a /healthz http liveness probe [NodeConformance]", func() {
livenessProbe := &v1.Probe{
Handler: httpGetHandler("/healthz", 8080),
ProbeHandler: httpGetHandler("/healthz", 8080),
InitialDelaySeconds: 15,
FailureThreshold: 1,
}
@@ -171,7 +171,7 @@ var _ = SIGDescribe("Probing container", func() {
*/
framework.ConformanceIt("should *not* be restarted with a tcp:8080 liveness probe [NodeConformance]", func() {
livenessProbe := &v1.Probe{
Handler: tcpSocketHandler(8080),
ProbeHandler: tcpSocketHandler(8080),
InitialDelaySeconds: 15,
FailureThreshold: 1,
}
@@ -186,7 +186,7 @@ var _ = SIGDescribe("Probing container", func() {
*/
framework.ConformanceIt("should have monotonically increasing restart count [NodeConformance]", func() {
livenessProbe := &v1.Probe{
Handler: httpGetHandler("/healthz", 8080),
ProbeHandler: httpGetHandler("/healthz", 8080),
InitialDelaySeconds: 5,
FailureThreshold: 1,
}
@@ -201,7 +201,7 @@ var _ = SIGDescribe("Probing container", func() {
*/
framework.ConformanceIt("should *not* be restarted with a /healthz http liveness probe [NodeConformance]", func() {
livenessProbe := &v1.Probe{
Handler: httpGetHandler("/", 80),
ProbeHandler: httpGetHandler("/", 80),
InitialDelaySeconds: 15,
TimeoutSeconds: 5,
FailureThreshold: 5, // to accommodate nodes which are slow in bringing up containers.
@@ -221,7 +221,7 @@ var _ = SIGDescribe("Probing container", func() {
e2eskipper.SkipUnlessFeatureGateEnabled(kubefeatures.ExecProbeTimeout)
cmd := []string{"/bin/sh", "-c", "sleep 600"}
livenessProbe := &v1.Probe{
Handler: execHandler([]string{"/bin/sh", "-c", "sleep 10"}),
ProbeHandler: execHandler([]string{"/bin/sh", "-c", "sleep 10"}),
InitialDelaySeconds: 15,
TimeoutSeconds: 1,
FailureThreshold: 1,
@@ -242,7 +242,7 @@ var _ = SIGDescribe("Probing container", func() {
cmd := []string{"/bin/sh", "-c", "sleep 600"}
readinessProbe := &v1.Probe{
Handler: execHandler([]string{"/bin/sh", "-c", "sleep 10"}),
ProbeHandler: execHandler([]string{"/bin/sh", "-c", "sleep 10"}),
InitialDelaySeconds: 15,
TimeoutSeconds: 1,
FailureThreshold: 1,
@@ -264,7 +264,7 @@ var _ = SIGDescribe("Probing container", func() {
cmd := []string{"/bin/sh", "-c", "sleep 600"}
livenessProbe := &v1.Probe{
Handler: execHandler([]string{"/bin/sh", "-c", "sleep 10 & exit 1"}),
ProbeHandler: execHandler([]string{"/bin/sh", "-c", "sleep 10 & exit 1"}),
InitialDelaySeconds: 15,
TimeoutSeconds: 1,
FailureThreshold: 1,
@@ -280,7 +280,7 @@ var _ = SIGDescribe("Probing container", func() {
*/
ginkgo.It("should be restarted with a local redirect http liveness probe", func() {
livenessProbe := &v1.Probe{
Handler: httpGetHandler("/redirect?loc="+url.QueryEscape("/healthz"), 8080),
ProbeHandler: httpGetHandler("/redirect?loc="+url.QueryEscape("/healthz"), 8080),
InitialDelaySeconds: 15,
FailureThreshold: 1,
}
@@ -295,7 +295,7 @@ var _ = SIGDescribe("Probing container", func() {
*/
ginkgo.It("should *not* be restarted with a non-local redirect http liveness probe", func() {
livenessProbe := &v1.Probe{
Handler: httpGetHandler("/redirect?loc="+url.QueryEscape("http://0.0.0.0/"), 8080),
ProbeHandler: httpGetHandler("/redirect?loc="+url.QueryEscape("http://0.0.0.0/"), 8080),
InitialDelaySeconds: 15,
FailureThreshold: 1,
}
@@ -320,7 +320,7 @@ var _ = SIGDescribe("Probing container", func() {
ginkgo.It("should be restarted startup probe fails", func() {
cmd := []string{"/bin/sh", "-c", "sleep 600"}
livenessProbe := &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
Exec: &v1.ExecAction{
Command: []string{"/bin/true"},
},
@@ -329,7 +329,7 @@ var _ = SIGDescribe("Probing container", func() {
FailureThreshold: 1,
}
startupProbe := &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
Exec: &v1.ExecAction{
Command: []string{"/bin/false"},
},
@@ -349,7 +349,7 @@ var _ = SIGDescribe("Probing container", func() {
ginkgo.It("should *not* be restarted by liveness probe because startup probe delays it", func() {
cmd := []string{"/bin/sh", "-c", "sleep 600"}
livenessProbe := &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
Exec: &v1.ExecAction{
Command: []string{"/bin/false"},
},
@@ -358,7 +358,7 @@ var _ = SIGDescribe("Probing container", func() {
FailureThreshold: 1,
}
startupProbe := &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
Exec: &v1.ExecAction{
Command: []string{"/bin/false"},
},
@@ -378,7 +378,7 @@ var _ = SIGDescribe("Probing container", func() {
ginkgo.It("should be restarted by liveness probe after startup probe enables it", func() {
cmd := []string{"/bin/sh", "-c", "sleep 10; echo ok >/tmp/startup; sleep 600"}
livenessProbe := &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
Exec: &v1.ExecAction{
Command: []string{"/bin/false"},
},
@@ -387,7 +387,7 @@ var _ = SIGDescribe("Probing container", func() {
FailureThreshold: 1,
}
startupProbe := &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
Exec: &v1.ExecAction{
Command: []string{"cat", "/tmp/startup"},
},
@@ -410,12 +410,12 @@ var _ = SIGDescribe("Probing container", func() {
// to avoid flakes, ensure sleep before startup (32s) > readinessProbe.PeriodSeconds
cmd := []string{"/bin/sh", "-c", "echo ok >/tmp/health; sleep 32; echo ok >/tmp/startup; sleep 600"}
readinessProbe := &v1.Probe{
Handler: execHandler([]string{"/bin/cat", "/tmp/health"}),
ProbeHandler: execHandler([]string{"/bin/cat", "/tmp/health"}),
InitialDelaySeconds: 0,
PeriodSeconds: 30,
}
startupProbe := &v1.Probe{
Handler: execHandler([]string{"/bin/cat", "/tmp/startup"}),
ProbeHandler: execHandler([]string{"/bin/cat", "/tmp/startup"}),
InitialDelaySeconds: 0,
FailureThreshold: 120,
PeriodSeconds: 5,
@@ -465,7 +465,7 @@ var _ = SIGDescribe("Probing container", func() {
// probe will fail since pod has no http endpoints
shortGracePeriod := int64(5)
pod.Spec.Containers[0].LivenessProbe = &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Path: "/healthz",
Port: intstr.FromInt(8080),
@@ -493,14 +493,14 @@ var _ = SIGDescribe("Probing container", func() {
// startup probe will fail since pod will sleep for 1000s before becoming ready
shortGracePeriod := int64(5)
pod.Spec.Containers[0].StartupProbe = &v1.Probe{
Handler: execHandler([]string{"/bin/cat", "/tmp/startup"}),
ProbeHandler: execHandler([]string{"/bin/cat", "/tmp/startup"}),
InitialDelaySeconds: 10,
FailureThreshold: 1,
TerminationGracePeriodSeconds: &shortGracePeriod,
}
// liveness probe always succeeds
pod.Spec.Containers[0].LivenessProbe = &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
Exec: &v1.ExecAction{
Command: []string{"/bin/true"},
},
@@ -613,16 +613,16 @@ func startupPodSpec(startupProbe, readinessProbe, livenessProbe *v1.Probe, cmd [
}
}
func execHandler(cmd []string) v1.Handler {
return v1.Handler{
func execHandler(cmd []string) v1.ProbeHandler {
return v1.ProbeHandler{
Exec: &v1.ExecAction{
Command: cmd,
},
}
}
func httpGetHandler(path string, port int) v1.Handler {
return v1.Handler{
func httpGetHandler(path string, port int) v1.ProbeHandler {
return v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Path: path,
Port: intstr.FromInt(port),
@@ -630,8 +630,8 @@ func httpGetHandler(path string, port int) v1.Handler {
}
}
func tcpSocketHandler(port int) v1.Handler {
return v1.Handler{
func tcpSocketHandler(port int) v1.ProbeHandler {
return v1.ProbeHandler{
TCPSocket: &v1.TCPSocketAction{
Port: intstr.FromInt(port),
},
@@ -655,7 +655,7 @@ func (b webserverProbeBuilder) withInitialDelay() webserverProbeBuilder {
func (b webserverProbeBuilder) build() *v1.Probe {
probe := &v1.Probe{
Handler: httpGetHandler("/", 80),
ProbeHandler: httpGetHandler("/", 80),
}
if b.initialDelay {
probe.InitialDelaySeconds = probeTestInitialDelaySeconds

View File

@@ -94,7 +94,7 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
*/
framework.ConformanceIt("should execute poststart exec hook properly [NodeConformance]", func() {
lifecycle := &v1.Lifecycle{
PostStart: &v1.Handler{
PostStart: &v1.LifecycleHandler{
Exec: &v1.ExecAction{
Command: []string{"sh", "-c", "curl http://" + targetURL + ":8080/echo?msg=poststart"},
},
@@ -111,7 +111,7 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
*/
framework.ConformanceIt("should execute prestop exec hook properly [NodeConformance]", func() {
lifecycle := &v1.Lifecycle{
PreStop: &v1.Handler{
PreStop: &v1.LifecycleHandler{
Exec: &v1.ExecAction{
Command: []string{"sh", "-c", "curl http://" + targetURL + ":8080/echo?msg=prestop"},
},
@@ -127,7 +127,7 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
*/
framework.ConformanceIt("should execute poststart http hook properly [NodeConformance]", func() {
lifecycle := &v1.Lifecycle{
PostStart: &v1.Handler{
PostStart: &v1.LifecycleHandler{
HTTPGet: &v1.HTTPGetAction{
Path: "/echo?msg=poststart",
Host: targetIP,
@@ -149,7 +149,7 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
*/
framework.ConformanceIt("should execute prestop http hook properly [NodeConformance]", func() {
lifecycle := &v1.Lifecycle{
PreStop: &v1.Handler{
PreStop: &v1.LifecycleHandler{
HTTPGet: &v1.HTTPGetAction{
Path: "/echo?msg=prestop",
Host: targetIP,

View File

@@ -558,7 +558,7 @@ func (config *NetworkingTestConfig) createNetShellPodSpec(podName, hostname stri
PeriodSeconds: 10,
SuccessThreshold: 1,
FailureThreshold: 3,
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Path: "/healthz",
Port: intstr.IntOrString{IntVal: EndpointHTTPPort},

View File

@@ -646,7 +646,7 @@ func (j *TestJig) newRCTemplate() *v1.ReplicationController {
Args: []string{"netexec", "--http-port=80", "--udp-port=80"},
ReadinessProbe: &v1.Probe{
PeriodSeconds: 3,
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Port: intstr.FromInt(80),
Path: "/hostName",

View File

@@ -117,7 +117,7 @@ func hasPauseProbe(pod *v1.Pod) bool {
}
var pauseProbe = &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
Exec: &v1.ExecAction{Command: []string{"test", "-f", "/data/statefulset-continue"}},
},
PeriodSeconds: 1,

View File

@@ -74,7 +74,7 @@ func pfPod(expectedClientData, chunks, chunkSize, chunkIntervalMillis string, bi
Image: imageutils.GetE2EImage(imageutils.Agnhost),
Args: []string{"netexec"},
ReadinessProbe: &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
Exec: &v1.ExecAction{
Command: []string{
"sh", "-c", "netstat -na | grep LISTEN | grep -v 8080 | grep 80",

View File

@@ -174,7 +174,7 @@ func createHostPortPodOnNode(f *framework.Framework, podName, ns, hostIP string,
},
},
ReadinessProbe: &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Path: "/hostname",
Port: intstr.IntOrString{

View File

@@ -2045,7 +2045,7 @@ func createServerPodAndService(f *framework.Framework, namespace *v1.Namespace,
},
},
ReadinessProbe: &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
Exec: &v1.ExecAction{
Command: []string{"/agnhost", "connect", fmt.Sprintf("--protocol=%s", connectProtocol), "--timeout=1s", fmt.Sprintf("127.0.0.1:%d", portProtocol.port)},
},

View File

@@ -163,7 +163,7 @@ var _ = common.SIGDescribe("Proxy", func() {
"tlsdest2": 462,
},
ReadinessProbe: &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Port: intstr.FromInt(80),
},

View File

@@ -463,7 +463,7 @@ func generateScaleTestBackendDeploymentSpec(numReplicas int32) *appsv1.Deploymen
Image: imageutils.GetE2EImage(imageutils.EchoServer),
Ports: []v1.ContainerPort{{ContainerPort: 8080}},
ReadinessProbe: &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Port: intstr.FromInt(8080),
Path: "/healthz",

View File

@@ -1684,14 +1684,14 @@ var _ = common.SIGDescribe("Services", func() {
Image: t.Image,
Ports: []v1.ContainerPort{{ContainerPort: int32(port), Protocol: v1.ProtocolTCP}},
ReadinessProbe: &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
Exec: &v1.ExecAction{
Command: []string{"/bin/false"},
},
},
},
Lifecycle: &v1.Lifecycle{
PreStop: &v1.Handler{
PreStop: &v1.LifecycleHandler{
Exec: &v1.ExecAction{
Command: []string{"/bin/sleep", fmt.Sprintf("%d", terminateSeconds)},
},

View File

@@ -77,7 +77,7 @@ func testPreStop(c clientset.Interface, ns string) {
Image: imageutils.GetE2EImage(imageutils.BusyBox),
Command: []string{"sleep", "600"},
Lifecycle: &v1.Lifecycle{
PreStop: &v1.Handler{
PreStop: &v1.LifecycleHandler{
Exec: &v1.ExecAction{
Command: []string{
"wget", "-O-", "--post-data=" + val, fmt.Sprintf("http://%s/write", podURL),
@@ -225,7 +225,7 @@ func getPodWithpreStopLifeCycle(name string) *v1.Pod {
Name: "nginx",
Image: imageutils.GetE2EImage(imageutils.Nginx),
Lifecycle: &v1.Lifecycle{
PreStop: &v1.Handler{
PreStop: &v1.LifecycleHandler{
Exec: &v1.ExecAction{
Command: []string{"sh", "-c", "while true; do echo preStop; sleep 1; done"},
},

View File

@@ -1045,7 +1045,7 @@ func createHostPortPodOnNode(f *framework.Framework, podName, ns, hostIP string,
},
},
ReadinessProbe: &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Path: "/hostname",
Port: intstr.IntOrString{

View File

@@ -341,7 +341,7 @@ var _ = utils.SIGDescribe("PersistentVolumes", func() {
writeCmd += "&& sleep 10000"
probe := &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
Exec: &v1.ExecAction{
// Check that the last file got created
Command: []string{"test", "-f", getVolumeFile(numVols - 1)},

View File

@@ -882,7 +882,7 @@ func testPodContainerRestart(f *framework.Framework, pod *v1.Pod) {
testPodContainerRestartWithHooks(f, pod, &podContainerRestartHooks{
AddLivenessProbeFunc: func(p *v1.Pod, probeFilePath string) {
p.Spec.Containers[0].LivenessProbe = &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
Exec: &v1.ExecAction{
Command: []string{"cat", probeFilePath},
},
@@ -936,7 +936,7 @@ func TestPodContainerRestartWithConfigmapModified(f *framework.Framework, origin
testPodContainerRestartWithHooks(f, pod, &podContainerRestartHooks{
AddLivenessProbeFunc: func(p *v1.Pod, probeFilePath string) {
p.Spec.Containers[0].LivenessProbe = &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
Exec: &v1.ExecAction{
// Expect probe file exist or configmap mounted file has been modified.
Command: []string{"sh", "-c", fmt.Sprintf("cat %s || test `cat %s` = '%s'", probeFilePath, volumePath, modifiedValue)},