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

@@ -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