Skip to content

Commit ce7d8e9

Browse files
committed
Make also the liveness and readyness probes configurable
Signed-off-by: Tudor Golubenco <tudor@xata.io>
1 parent 8c2e72a commit ce7d8e9

File tree

8 files changed

+442
-34
lines changed

8 files changed

+442
-34
lines changed

api/v1/objectstore_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ type InstanceSidecarConfiguration struct {
7070
// StartupProbe defines the configuration for the startup probe of the sidecar container.
7171
// +optional
7272
StartupProbe *ProbeConfig `json:"startupProbe,omitempty"`
73+
74+
// LivenessProbe defines the configuration for the liveness probe of the sidecar container.
75+
// +optional
76+
LivenessProbe *ProbeConfig `json:"livenessProbe,omitempty"`
77+
78+
// ReadinessProbe defines the configuration for the readiness probe of the sidecar container.
79+
// +optional
80+
ReadinessProbe *ProbeConfig `json:"readinessProbe,omitempty"`
7381
}
7482

7583
// ObjectStoreSpec defines the desired state of ObjectStore.

api/v1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/barmancloud.cnpg.io_objectstores.yaml

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.18.0
6+
controller-gen.kubebuilder.io/version: v0.16.1
77
name: objectstores.barmancloud.cnpg.io
88
spec:
99
group: barmancloud.cnpg.io
@@ -511,6 +511,78 @@ spec:
511511
- name
512512
type: object
513513
type: array
514+
livenessProbe:
515+
description: LivenessProbe defines the configuration for the liveness
516+
probe of the sidecar container.
517+
properties:
518+
failureThreshold:
519+
default: 10
520+
description: FailureThreshold is the minimum consecutive failures
521+
for the probe to be considered failed.
522+
format: int32
523+
type: integer
524+
initialDelaySeconds:
525+
default: 0
526+
description: InitialDelaySeconds is the number of seconds
527+
after the container has started before startup probes are
528+
initiated.
529+
format: int32
530+
type: integer
531+
periodSeconds:
532+
default: 10
533+
description: PeriodSeconds is how often (in seconds) to perform
534+
the probe.
535+
format: int32
536+
type: integer
537+
successThreshold:
538+
default: 1
539+
description: SuccessThreshold is the minimum consecutive successes
540+
for the probe to be considered successful.
541+
format: int32
542+
type: integer
543+
timeoutSeconds:
544+
default: 10
545+
description: TimeoutSeconds is the number of seconds after
546+
which the probe times out.
547+
format: int32
548+
type: integer
549+
type: object
550+
readinessProbe:
551+
description: ReadinessProbe defines the configuration for the
552+
readiness probe of the sidecar container.
553+
properties:
554+
failureThreshold:
555+
default: 10
556+
description: FailureThreshold is the minimum consecutive failures
557+
for the probe to be considered failed.
558+
format: int32
559+
type: integer
560+
initialDelaySeconds:
561+
default: 0
562+
description: InitialDelaySeconds is the number of seconds
563+
after the container has started before startup probes are
564+
initiated.
565+
format: int32
566+
type: integer
567+
periodSeconds:
568+
default: 10
569+
description: PeriodSeconds is how often (in seconds) to perform
570+
the probe.
571+
format: int32
572+
type: integer
573+
successThreshold:
574+
default: 1
575+
description: SuccessThreshold is the minimum consecutive successes
576+
for the probe to be considered successful.
577+
format: int32
578+
type: integer
579+
timeoutSeconds:
580+
default: 10
581+
description: TimeoutSeconds is the number of seconds after
582+
which the probe times out.
583+
format: int32
584+
type: integer
585+
type: object
514586
resources:
515587
description: Resources define cpu/memory requests and limits for
516588
the sidecar that runs in the instance pods.

hack/examples/minio-store.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ spec:
1919
periodSeconds: 1
2020
failureThreshold: 10
2121
successThreshold: 1
22+
livenessProbe:
23+
initialDelaySeconds: 30
24+
timeoutSeconds: 5
25+
periodSeconds: 10
26+
failureThreshold: 3
27+
successThreshold: 1
28+
readinessProbe:
29+
initialDelaySeconds: 5
30+
timeoutSeconds: 5
31+
periodSeconds: 5
32+
failureThreshold: 3
33+
successThreshold: 1
2234
configuration:
2335
endpointCA:
2436
name: minio-server-tls

internal/cnpgi/operator/lifecycle.go

Lines changed: 94 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,33 @@ func (impl LifecycleImplementation) reconcileJob(
131131
return nil, err
132132
}
133133

134+
livenessProbe, err := impl.collectSidecarLivenessProbeForRecoveryJob(ctx, pluginConfiguration)
135+
if err != nil {
136+
return nil, err
137+
}
138+
139+
readinessProbe, err := impl.collectSidecarReadinessProbeForRecoveryJob(ctx, pluginConfiguration)
140+
if err != nil {
141+
return nil, err
142+
}
143+
134144
return reconcileJob(ctx, cluster, request, sidecarConfiguration{
135-
env: env,
136-
certificates: certificates,
137-
resources: resources,
138-
startupProbe: startupProbe,
145+
env: env,
146+
certificates: certificates,
147+
resources: resources,
148+
startupProbe: startupProbe,
149+
livenessProbe: livenessProbe,
150+
readinessProbe: readinessProbe,
139151
})
140152
}
141153

142154
type sidecarConfiguration struct {
143-
env []corev1.EnvVar
144-
certificates []corev1.VolumeProjection
145-
resources corev1.ResourceRequirements
146-
startupProbe *barmancloudv1.ProbeConfig
155+
env []corev1.EnvVar
156+
certificates []corev1.VolumeProjection
157+
resources corev1.ResourceRequirements
158+
startupProbe *barmancloudv1.ProbeConfig
159+
livenessProbe *barmancloudv1.ProbeConfig
160+
readinessProbe *barmancloudv1.ProbeConfig
147161
}
148162

149163
func reconcileJob(
@@ -230,11 +244,23 @@ func (impl LifecycleImplementation) reconcilePod(
230244
return nil, err
231245
}
232246

247+
livenessProbe, err := impl.collectSidecarLivenessProbeForInstancePod(ctx, pluginConfiguration)
248+
if err != nil {
249+
return nil, err
250+
}
251+
252+
readinessProbe, err := impl.collectSidecarReadinessProbeForInstancePod(ctx, pluginConfiguration)
253+
if err != nil {
254+
return nil, err
255+
}
256+
233257
return reconcilePod(ctx, cluster, request, pluginConfiguration, sidecarConfiguration{
234-
env: env,
235-
certificates: certificates,
236-
resources: resources,
237-
startupProbe: startupProbe,
258+
env: env,
259+
certificates: certificates,
260+
resources: resources,
261+
startupProbe: startupProbe,
262+
livenessProbe: livenessProbe,
263+
readinessProbe: readinessProbe,
238264
})
239265
}
240266

@@ -325,25 +351,37 @@ func reconcilePodSpec(
325351
},
326352
}
327353

328-
// Apply configurable probe settings if available
329-
if config.startupProbe != nil {
330-
// Copy timing and threshold settings from user configuration
331-
baseProbe.InitialDelaySeconds = config.startupProbe.InitialDelaySeconds
332-
baseProbe.TimeoutSeconds = config.startupProbe.TimeoutSeconds
333-
baseProbe.PeriodSeconds = config.startupProbe.PeriodSeconds
334-
baseProbe.FailureThreshold = config.startupProbe.FailureThreshold
335-
baseProbe.SuccessThreshold = config.startupProbe.SuccessThreshold
336-
} else {
337-
// Fallback to default values
338-
baseProbe.FailureThreshold = 10
339-
baseProbe.TimeoutSeconds = 10
340-
}
354+
startupProbe := createProbe(baseProbe, config.startupProbe, &barmancloudv1.ProbeConfig{
355+
FailureThreshold: 10,
356+
TimeoutSeconds: 10,
357+
InitialDelaySeconds: 0,
358+
SuccessThreshold: 1,
359+
PeriodSeconds: 10,
360+
})
361+
362+
livenessProbe := createProbe(baseProbe, config.livenessProbe, &barmancloudv1.ProbeConfig{
363+
FailureThreshold: 3,
364+
TimeoutSeconds: 10,
365+
InitialDelaySeconds: 0,
366+
SuccessThreshold: 1,
367+
PeriodSeconds: 10,
368+
})
369+
370+
readinessProbe := createProbe(baseProbe, config.readinessProbe, &barmancloudv1.ProbeConfig{
371+
FailureThreshold: 3,
372+
TimeoutSeconds: 10,
373+
InitialDelaySeconds: 0,
374+
SuccessThreshold: 1,
375+
PeriodSeconds: 10,
376+
})
341377

342378
// fixed values
343379
sidecarTemplate.Name = "plugin-barman-cloud"
344380
sidecarTemplate.Image = viper.GetString("sidecar-image")
345381
sidecarTemplate.ImagePullPolicy = cluster.Spec.ImagePullPolicy
346-
sidecarTemplate.StartupProbe = baseProbe.DeepCopy()
382+
sidecarTemplate.StartupProbe = startupProbe
383+
sidecarTemplate.LivenessProbe = livenessProbe
384+
sidecarTemplate.ReadinessProbe = readinessProbe
347385
sidecarTemplate.SecurityContext = &corev1.SecurityContext{
348386
AllowPrivilegeEscalation: ptr.To(false),
349387
RunAsNonRoot: ptr.To(true),
@@ -567,3 +605,33 @@ func getCNPGJobRole(job *batchv1.Job) string {
567605

568606
return ""
569607
}
608+
609+
// createProbe creates a probe using the base probe's handler and applies configuration or default values
610+
func createProbe(baseProbe *corev1.Probe, config *barmancloudv1.ProbeConfig, defaults *barmancloudv1.ProbeConfig) *corev1.Probe {
611+
probe := baseProbe.DeepCopy()
612+
probe.FailureThreshold = defaults.FailureThreshold
613+
probe.TimeoutSeconds = defaults.TimeoutSeconds
614+
probe.InitialDelaySeconds = defaults.InitialDelaySeconds
615+
probe.SuccessThreshold = defaults.SuccessThreshold
616+
probe.PeriodSeconds = defaults.PeriodSeconds
617+
618+
if config != nil {
619+
if config.InitialDelaySeconds != 0 {
620+
probe.InitialDelaySeconds = config.InitialDelaySeconds
621+
}
622+
if config.TimeoutSeconds != 0 {
623+
probe.TimeoutSeconds = config.TimeoutSeconds
624+
}
625+
if config.PeriodSeconds != 0 {
626+
probe.PeriodSeconds = config.PeriodSeconds
627+
}
628+
if config.SuccessThreshold != 0 {
629+
probe.SuccessThreshold = config.SuccessThreshold
630+
}
631+
if config.FailureThreshold != 0 {
632+
probe.FailureThreshold = config.FailureThreshold
633+
}
634+
}
635+
636+
return probe
637+
}

0 commit comments

Comments
 (0)