From 9789a3bbf33597df8ef06763b4bc38095d06e62c Mon Sep 17 00:00:00 2001 From: David Colburn Date: Mon, 29 Mar 2021 17:57:31 -1000 Subject: [PATCH 1/6] Add option for initial probe delay --- builtin/k8s/platform.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/builtin/k8s/platform.go b/builtin/k8s/platform.go index 4d4064ed7ee..a2293afbee4 100644 --- a/builtin/k8s/platform.go +++ b/builtin/k8s/platform.go @@ -248,6 +248,11 @@ func (p *Platform) Deploy( // assume the first port defined is the 'main' port to use defaultPort := int(containerPorts[0].ContainerPort) + initialDelaySeconds := int32(5) + if p.config.ProbeDelay != 0 { + initialDelaySeconds = int32(p.config.ProbeDelay) + } + // Update the deployment with our spec deployment.Spec.Template.Spec = corev1.PodSpec{ Containers: []corev1.Container{ @@ -262,7 +267,7 @@ func (p *Platform) Deploy( Port: intstr.FromInt(defaultPort), }, }, - InitialDelaySeconds: 5, + InitialDelaySeconds: initialDelaySeconds, TimeoutSeconds: 5, FailureThreshold: 5, }, @@ -272,7 +277,7 @@ func (p *Platform) Deploy( Port: intstr.FromInt(defaultPort), }, }, - InitialDelaySeconds: 5, + InitialDelaySeconds: initialDelaySeconds, TimeoutSeconds: 5, }, Env: env, @@ -290,7 +295,7 @@ func (p *Platform) Deploy( Port: intstr.FromInt(defaultPort), }, }, - InitialDelaySeconds: 5, + InitialDelaySeconds: initialDelaySeconds, TimeoutSeconds: 5, FailureThreshold: 5, } @@ -302,7 +307,7 @@ func (p *Platform) Deploy( Port: intstr.FromInt(defaultPort), }, }, - InitialDelaySeconds: 5, + InitialDelaySeconds: initialDelaySeconds, TimeoutSeconds: 5, } } @@ -547,6 +552,10 @@ type Config struct { // made to the port. ProbePath string `hcl:"probe_path,optional"` + // Time in seconds to delay the initial liveness and readiness probes. + // Defaults to 5 seconds. + ProbeDelay uint `hcl:"probe_delay,optional"` + // Optionally define various resources limits for kubernetes pod containers // such as memory and cpu. Resources map[string]string `hcl:"resources,optional"` @@ -636,6 +645,12 @@ deploy "kubernetes" { ), ) + doc.SetField( + "probe_delay", + "time in seconds to delay the initial liveness and readiness probes", + docs.Default("5"), + ) + doc.SetField( "scratch_path", "a path for the service to store temporary data", From 71a5046af458019f21b9d413d0f079d418c94066 Mon Sep 17 00:00:00 2001 From: David Colburn Date: Tue, 30 Mar 2021 16:03:31 -1000 Subject: [PATCH 2/6] add the other probe fields --- builtin/k8s/platform.go | 72 +++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 14 deletions(-) diff --git a/builtin/k8s/platform.go b/builtin/k8s/platform.go index a2293afbee4..cc5e23591e3 100644 --- a/builtin/k8s/platform.go +++ b/builtin/k8s/platform.go @@ -249,8 +249,18 @@ func (p *Platform) Deploy( defaultPort := int(containerPorts[0].ContainerPort) initialDelaySeconds := int32(5) - if p.config.ProbeDelay != 0 { - initialDelaySeconds = int32(p.config.ProbeDelay) + timeoutSeconds := int32(5) + failureThreshold := int32(5) + if p.config.Probe != nil { + if p.config.Probe.InitialDelaySeconds != 0 { + initialDelaySeconds = int32(p.config.Probe.InitialDelaySeconds) + } + if p.config.Probe.TimeoutSeconds != 0 { + timeoutSeconds = int32(p.config.Probe.TimeoutSeconds) + } + if p.config.Probe.FailureThreshold != 0 { + failureThreshold = int32(p.config.Probe.FailureThreshold) + } } // Update the deployment with our spec @@ -268,8 +278,8 @@ func (p *Platform) Deploy( }, }, InitialDelaySeconds: initialDelaySeconds, - TimeoutSeconds: 5, - FailureThreshold: 5, + TimeoutSeconds: timeoutSeconds, + FailureThreshold: failureThreshold, }, ReadinessProbe: &corev1.Probe{ Handler: corev1.Handler{ @@ -278,7 +288,7 @@ func (p *Platform) Deploy( }, }, InitialDelaySeconds: initialDelaySeconds, - TimeoutSeconds: 5, + TimeoutSeconds: timeoutSeconds, }, Env: env, Resources: resourceRequirements, @@ -296,8 +306,8 @@ func (p *Platform) Deploy( }, }, InitialDelaySeconds: initialDelaySeconds, - TimeoutSeconds: 5, - FailureThreshold: 5, + TimeoutSeconds: timeoutSeconds, + FailureThreshold: failureThreshold, } deployment.Spec.Template.Spec.Containers[0].ReadinessProbe = &corev1.Probe{ @@ -308,7 +318,7 @@ func (p *Platform) Deploy( }, }, InitialDelaySeconds: initialDelaySeconds, - TimeoutSeconds: 5, + TimeoutSeconds: timeoutSeconds, } } @@ -552,9 +562,8 @@ type Config struct { // made to the port. ProbePath string `hcl:"probe_path,optional"` - // Time in seconds to delay the initial liveness and readiness probes. - // Defaults to 5 seconds. - ProbeDelay uint `hcl:"probe_delay,optional"` + // Probe details + Probe *Probe `hcl:"probe,block"` // Optionally define various resources limits for kubernetes pod containers // such as memory and cpu. @@ -580,6 +589,21 @@ type Config struct { StaticEnvVars map[string]string `hcl:"static_environment,optional"` } +type Probe struct { + // Time in seconds to wait before performing the initial liveness and readiness probes. + // Defaults to 5 seconds. + InitialDelaySeconds uint `hcl:"initial_delay,optional"` + + // Time in seconds before the probe fails. + // Defaults to 5 seconds. + TimeoutSeconds uint `hcl:"timeout,optional"` + + // Number of times a liveness probe can fail before the container is killed. + // FailureThreshold * TimeoutSeconds should be long enough to cover your worst + // case startup times. Defaults to 5 failures. + FailureThreshold uint `hcl:"failure_threshold,optional"` +} + func (p *Platform) Documentation() (*docs.Documentation, error) { doc, err := docs.New(docs.FromConfig(&Config{}), docs.FromFunc(p.DeployFunc())) if err != nil { @@ -646,9 +670,8 @@ deploy "kubernetes" { ) doc.SetField( - "probe_delay", - "time in seconds to delay the initial liveness and readiness probes", - docs.Default("5"), + "probe", + "configuration to control liveness and readiness probes", ) doc.SetField( @@ -721,6 +744,27 @@ deploy "kubernetes" { ), ) + doc.SetField( + "probe.initial_delay", + "time in seconds to wait before performing the initial liveness and readiness probes", + docs.Default("5"), + ) + + doc.SetField( + "probe.timeout", + "time in seconds before the probe fails", + docs.Default("5"), + ) + + doc.SetField( + "probe.failure_threshold", + "number of times a liveness probe can fail before the container is killed", + docs.Summary( + "failureThreshold * TimeoutSeconds should be long enough to cover your worst case startup times", + ), + docs.Default("5"), + ) + return doc, nil } From 74638be5cc80dbf896d70471696b3828e3ba40d1 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 31 Mar 2021 10:30:38 -0700 Subject: [PATCH 3/6] Add CHANGELOG entry --- .changelog/1246.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/1246.txt diff --git a/.changelog/1246.txt b/.changelog/1246.txt new file mode 100644 index 00000000000..1d286003cc1 --- /dev/null +++ b/.changelog/1246.txt @@ -0,0 +1,3 @@ +```release-note:improvement +plugin/k8s: Add new probe configuration options +``` From 74106710103c6ab545833ad03cbfb354c57a0af3 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 31 Mar 2021 11:23:02 -0700 Subject: [PATCH 4/6] Regroup probe field docs --- builtin/k8s/platform.go | 42 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/builtin/k8s/platform.go b/builtin/k8s/platform.go index cc5e23591e3..7f1d4d393bc 100644 --- a/builtin/k8s/platform.go +++ b/builtin/k8s/platform.go @@ -674,6 +674,27 @@ deploy "kubernetes" { "configuration to control liveness and readiness probes", ) + doc.SetField( + "probe.initial_delay", + "time in seconds to wait before performing the initial liveness and readiness probes", + docs.Default("5"), + ) + + doc.SetField( + "probe.timeout", + "time in seconds before the probe fails", + docs.Default("5"), + ) + + doc.SetField( + "probe.failure_threshold", + "number of times a liveness probe can fail before the container is killed", + docs.Summary( + "failureThreshold * TimeoutSeconds should be long enough to cover your worst case startup times", + ), + docs.Default("5"), + ) + doc.SetField( "scratch_path", "a path for the service to store temporary data", @@ -744,27 +765,6 @@ deploy "kubernetes" { ), ) - doc.SetField( - "probe.initial_delay", - "time in seconds to wait before performing the initial liveness and readiness probes", - docs.Default("5"), - ) - - doc.SetField( - "probe.timeout", - "time in seconds before the probe fails", - docs.Default("5"), - ) - - doc.SetField( - "probe.failure_threshold", - "number of times a liveness probe can fail before the container is killed", - docs.Summary( - "failureThreshold * TimeoutSeconds should be long enough to cover your worst case startup times", - ), - docs.Default("5"), - ) - return doc, nil } From 015cf35e75d67866c0154f853ff2d4080cc5625f Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 31 Mar 2021 11:37:38 -0700 Subject: [PATCH 5/6] Move probe options into subfields for docs --- builtin/k8s/platform.go | 45 ++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/builtin/k8s/platform.go b/builtin/k8s/platform.go index 7f1d4d393bc..98fa0596069 100644 --- a/builtin/k8s/platform.go +++ b/builtin/k8s/platform.go @@ -672,27 +672,30 @@ deploy "kubernetes" { doc.SetField( "probe", "configuration to control liveness and readiness probes", - ) - - doc.SetField( - "probe.initial_delay", - "time in seconds to wait before performing the initial liveness and readiness probes", - docs.Default("5"), - ) - - doc.SetField( - "probe.timeout", - "time in seconds before the probe fails", - docs.Default("5"), - ) - - doc.SetField( - "probe.failure_threshold", - "number of times a liveness probe can fail before the container is killed", - docs.Summary( - "failureThreshold * TimeoutSeconds should be long enough to cover your worst case startup times", - ), - docs.Default("5"), + docs.Summary(), + docs.SubFields(func(doc *docs.SubFieldDoc) { + doc.SetField( + "initial_delay", + "time in seconds to wait before performing the initial liveness and readiness probes", + docs.Default("5"), + ) + + doc.SetField( + "timeout", + "time in seconds before the probe fails", + docs.Default("5"), + ) + + doc.SetField( + "failure_threshold", + "number of times a liveness probe can fail before the container is killed", + docs.Summary( + "failureThreshold * TimeoutSeconds should be long enough to cover your worst case startup times", + ), + docs.Default("5"), + ) + + }), ) doc.SetField( From 3e8bcd25500c496cb6a0fc3260baba6c2b4079da Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 31 Mar 2021 11:45:29 -0700 Subject: [PATCH 6/6] Add probe comments --- builtin/k8s/platform.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/builtin/k8s/platform.go b/builtin/k8s/platform.go index 98fa0596069..c70cac0c484 100644 --- a/builtin/k8s/platform.go +++ b/builtin/k8s/platform.go @@ -562,7 +562,7 @@ type Config struct { // made to the port. ProbePath string `hcl:"probe_path,optional"` - // Probe details + // Probe details for describing a health check to be performed against a container. Probe *Probe `hcl:"probe,block"` // Optionally define various resources limits for kubernetes pod containers @@ -589,6 +589,8 @@ type Config struct { StaticEnvVars map[string]string `hcl:"static_environment,optional"` } +// Probe describes a health check to be performed against a container to determine whether it is +// alive or ready to receive traffic. type Probe struct { // Time in seconds to wait before performing the initial liveness and readiness probes. // Defaults to 5 seconds. @@ -672,7 +674,8 @@ deploy "kubernetes" { doc.SetField( "probe", "configuration to control liveness and readiness probes", - docs.Summary(), + docs.Summary("Probe describes a health check to be performed against a ", + "container to determine whether it is alive or ready to receive traffic."), docs.SubFields(func(doc *docs.SubFieldDoc) { doc.SetField( "initial_delay",