Skip to content

Commit 9f23e0b

Browse files
authored
Allow to set a livenessProbe for the sidecar (FoundationDB#666)
1 parent 1005b0e commit 9f23e0b

File tree

5 files changed

+43
-0
lines changed

5 files changed

+43
-0
lines changed

api/v1beta1/foundationdbcluster_types.go

+4
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,10 @@ type FoundationDBStatusBackupTag struct {
18821882
// ContainerOverrides provides options for customizing a container created by
18831883
// the operator.
18841884
type ContainerOverrides struct {
1885+
// EnableLivenessProbe defines if the sidecar should have a livenessProbe in addition
1886+
// to the readinessProbe. This setting will be enabled per default in the 1.0.0 release.
1887+
// This setting will be ignored on the main container.
1888+
EnableLivenessProbe bool `json:"enableLivenessProbe,omitempty"`
18851889

18861890
// EnableTLS controls whether we should be listening on a TLS connection.
18871891
EnableTLS bool `json:"enableTls,omitempty"`

config/crd/bases/apps.foundationdb.org_foundationdbclusters.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,8 @@ spec:
12951295
type: string
12961296
mainContainer:
12971297
properties:
1298+
enableLivenessProbe:
1299+
type: boolean
12981300
enableTls:
12991301
type: boolean
13001302
env:
@@ -7433,6 +7435,8 @@ spec:
74337435
type: object
74347436
sidecarContainer:
74357437
properties:
7438+
enableLivenessProbe:
7439+
type: boolean
74367440
enableTls:
74377441
type: boolean
74387442
env:

controllers/pod_models.go

+15
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,21 @@ func configureSidecarContainer(container *corev1.Container, initMode bool, insta
518518
}
519519

520520
sidecarEnv = append(sidecarEnv, corev1.EnvVar{Name: "FDB_INSTANCE_ID", Value: instanceID})
521+
522+
if !initMode && cluster.Spec.SidecarContainer.EnableLivenessProbe && container.LivenessProbe == nil {
523+
// We can't use a HTTP handler here since the server
524+
// requires a client certificate
525+
container.LivenessProbe = &corev1.Probe{
526+
Handler: corev1.Handler{
527+
TCPSocket: &corev1.TCPSocketAction{
528+
Port: intstr.IntOrString{IntVal: 8080},
529+
},
530+
},
531+
TimeoutSeconds: 1,
532+
PeriodSeconds: 30,
533+
FailureThreshold: 5,
534+
}
535+
}
521536
}
522537

523538
if version.PrefersCommandLineArgumentsInSidecar() && initMode {

controllers/pod_models_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,25 @@ var _ = Describe("pod_models", func() {
320320
It("should have no affinity rules", func() {
321321
Expect(spec.Affinity).To(BeNil())
322322
})
323+
324+
Context("with the livenessProbe enabled", func() {
325+
BeforeEach(func() {
326+
cluster.Spec.SidecarContainer.EnableLivenessProbe = true
327+
spec, err = GetPodSpec(cluster, fdbtypes.ProcessClassStorage, 1)
328+
})
329+
330+
It("should have a livenessProbe for the sidecar", func() {
331+
sidecarContainer := spec.Containers[1]
332+
Expect(sidecarContainer.Name).To(Equal("foundationdb-kubernetes-sidecar"))
333+
Expect(sidecarContainer.LivenessProbe).NotTo(BeNil())
334+
})
335+
336+
It("should not have a livenessProbe for the init container", func() {
337+
sidecarContainer := spec.InitContainers[0]
338+
Expect(sidecarContainer.Name).To(Equal("foundationdb-kubernetes-init"))
339+
Expect(sidecarContainer.LivenessProbe).To(BeNil())
340+
})
341+
})
323342
})
324343

325344
Context("with an instance that is crash looping", func() {

docs/cluster_spec.md

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ ContainerOverrides provides options for customizing a container created by the o
126126

127127
| Field | Description | Scheme | Required |
128128
| ----- | ----------- | ------ | -------- |
129+
| enableLivenessProbe | EnableLivenessProbe defines if the sidecar should have a livenessProbe in addition to the readinessProbe. This setting will be enabled per default in the 1.0.0 release. This setting will be ignored on the main container. | bool | false |
129130
| enableTls | EnableTLS controls whether we should be listening on a TLS connection. | bool | false |
130131
| peerVerificationRules | PeerVerificationRules provides the rules for what client certificates the process should accept. | string | false |
131132
| env | Env provides environment variables. **Deprecated: Use the PodTemplate field instead.** | [][corev1.EnvVar](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#envvar-v1-core) | false |

0 commit comments

Comments
 (0)