util/kubernetes: add readiness check to deployments (#1923)

This commit is contained in:
ben-toogood 2020-08-11 08:38:30 +01:00 committed by GitHub
parent 959407bad9
commit 1263806a39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 7 deletions

View File

@ -321,6 +321,13 @@ func NewDeployment(name, version, typ, namespace string) *Deployment {
Name: "service-port",
ContainerPort: 8080,
}},
ReadinessProbe: &Probe{
TCPSocket: TCPSocketAction{
Port: 8080,
},
PeriodSeconds: 10,
InitialDelaySeconds: 10,
},
}},
},
},

View File

@ -92,8 +92,22 @@ spec:
name: {{ .Name }}
{{- end}}
{{- end}}
{{- if .ReadinessProbe }}
{{- with .ReadinessProbe }}
readinessProbe:
{{- with .TCPSocket }}
tcpSocket:
{{- if .Host }}
host: {{ .Host }}
{{- end }}
port: {{ .Port }}
{{- end }}
initialDelaySeconds: {{ .InitialDelaySeconds }}
periodSeconds: {{ .PeriodSeconds }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end}}
`
var serviceTmpl = `

View File

@ -35,12 +35,13 @@ type Condition struct {
// Container defined container runtime values
type Container struct {
Name string `json:"name"`
Image string `json:"image"`
Env []EnvVar `json:"env,omitempty"`
Command []string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Ports []ContainerPort `json:"ports,omitempty"`
Name string `json:"name"`
Image string `json:"image"`
Env []EnvVar `json:"env,omitempty"`
Command []string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Ports []ContainerPort `json:"ports,omitempty"`
ReadinessProbe *Probe `json:"readinessProbe,omitempty"`
}
// DeploymentSpec defines micro deployment spec
@ -220,3 +221,16 @@ type ServiceAccount struct {
Metadata *Metadata `json:"metadata,omitempty"`
ImagePullSecrets []ImagePullSecret `json:"imagePullSecrets,omitempty"`
}
// 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 {
TCPSocket TCPSocketAction `json:"tcpSocket,omitempty"`
PeriodSeconds int `json:"periodSeconds"`
InitialDelaySeconds int `json:"initialDelaySeconds"`
}
// TCPSocketAction describes an action based on opening a socket
type TCPSocketAction struct {
Host string `json:"host,omitempty"`
Port int `json:"port,omitempty"`
}