Skip to content

Commit 8c2e72a

Browse files
committed
Move the startup probe configuration for the sidecar in the ObjectStore config
Signed-off-by: Tudor Golubenco <tudor@xata.io>
1 parent ab6b7a6 commit 8c2e72a

File tree

8 files changed

+179
-75
lines changed

8 files changed

+179
-75
lines changed

api/v1/objectstore_types.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,35 @@ import (
2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323
)
2424

25+
// ProbeConfig holds configuration for probe timing and thresholds
26+
// This is a subset of the corev1.Probe type, with only the fields that we want to expose as configuration.
27+
type ProbeConfig struct {
28+
// InitialDelaySeconds is the number of seconds after the container has started before startup probes are initiated.
29+
// +kubebuilder:default:=0
30+
// +optional
31+
InitialDelaySeconds int32 `json:"initialDelaySeconds,omitempty"`
32+
33+
// TimeoutSeconds is the number of seconds after which the probe times out.
34+
// +kubebuilder:default:=10
35+
// +optional
36+
TimeoutSeconds int32 `json:"timeoutSeconds,omitempty"`
37+
38+
// PeriodSeconds is how often (in seconds) to perform the probe.
39+
// +kubebuilder:default:=10
40+
// +optional
41+
PeriodSeconds int32 `json:"periodSeconds,omitempty"`
42+
43+
// SuccessThreshold is the minimum consecutive successes for the probe to be considered successful.
44+
// +kubebuilder:default:=1
45+
// +optional
46+
SuccessThreshold int32 `json:"successThreshold,omitempty"`
47+
48+
// FailureThreshold is the minimum consecutive failures for the probe to be considered failed.
49+
// +kubebuilder:default:=10
50+
// +optional
51+
FailureThreshold int32 `json:"failureThreshold,omitempty"`
52+
}
53+
2554
// InstanceSidecarConfiguration defines the configuration for the sidecar that runs in the instance pods.
2655
type InstanceSidecarConfiguration struct {
2756
// The environment to be explicitly passed to the sidecar
@@ -37,6 +66,10 @@ type InstanceSidecarConfiguration struct {
3766
// Resources define cpu/memory requests and limits for the sidecar that runs in the instance pods.
3867
// +optional
3968
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
69+
70+
// StartupProbe defines the configuration for the startup probe of the sidecar container.
71+
// +optional
72+
StartupProbe *ProbeConfig `json:"startupProbe,omitempty"`
4073
}
4174

4275
// ObjectStoreSpec defines the desired state of ObjectStore.

api/v1/zz_generated.deepcopy.go

Lines changed: 20 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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,42 @@ spec:
577577
The retentionCheckInterval defines the frequency at which the
578578
system checks and enforces retention policies.
579579
type: integer
580+
startupProbe:
581+
description: StartupProbe defines the configuration for the startup
582+
probe of the sidecar container.
583+
properties:
584+
failureThreshold:
585+
default: 10
586+
description: FailureThreshold is the minimum consecutive failures
587+
for the probe to be considered failed.
588+
format: int32
589+
type: integer
590+
initialDelaySeconds:
591+
default: 0
592+
description: InitialDelaySeconds is the number of seconds
593+
after the container has started before startup probes are
594+
initiated.
595+
format: int32
596+
type: integer
597+
periodSeconds:
598+
default: 10
599+
description: PeriodSeconds is how often (in seconds) to perform
600+
the probe.
601+
format: int32
602+
type: integer
603+
successThreshold:
604+
default: 1
605+
description: SuccessThreshold is the minimum consecutive successes
606+
for the probe to be considered successful.
607+
format: int32
608+
type: integer
609+
timeoutSeconds:
610+
default: 10
611+
description: TimeoutSeconds is the number of seconds after
612+
which the probe times out.
613+
format: int32
614+
type: integer
615+
type: object
580616
type: object
581617
retentionPolicy:
582618
description: |-

hack/examples/minio-store.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ spec:
1313
limits:
1414
memory: "512Mi"
1515
cpu: "500m"
16+
startupProbe:
17+
initialDelaySeconds: 1
18+
timeoutSeconds: 10
19+
periodSeconds: 1
20+
failureThreshold: 10
21+
successThreshold: 1
1622
configuration:
1723
endpointCA:
1824
name: minio-server-tls

internal/cnpgi/operator/config/config.go

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package config
22

33
import (
4-
"strconv"
54
"strings"
65

76
cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
@@ -58,29 +57,6 @@ type PluginConfiguration struct {
5857

5958
ReplicaSourceBarmanObjectName string
6059
ReplicaSourceServerName string
61-
62-
// Probe configuration
63-
StartupProbeConfig *ProbeConfig
64-
}
65-
66-
// ProbeConfig holds configuration for Kubernetes probes
67-
type ProbeConfig struct {
68-
InitialDelaySeconds int32
69-
TimeoutSeconds int32
70-
PeriodSeconds int32
71-
FailureThreshold int32
72-
SuccessThreshold int32
73-
}
74-
75-
// DefaultProbeConfig returns the default probe configuration
76-
func DefaultProbeConfig() *ProbeConfig {
77-
return &ProbeConfig{
78-
InitialDelaySeconds: 0,
79-
TimeoutSeconds: 10,
80-
PeriodSeconds: 10,
81-
FailureThreshold: 10,
82-
SuccessThreshold: 1,
83-
}
8460
}
8561

8662
// GetBarmanObjectKey gets the namespaced name of the barman object
@@ -190,50 +166,11 @@ func NewFromCluster(cluster *cnpgv1.Cluster) *PluginConfiguration {
190166
// used for wal_restore in the designed primary of a replica cluster
191167
ReplicaSourceServerName: replicaSourceServerName,
192168
ReplicaSourceBarmanObjectName: replicaSourceBarmanObjectName,
193-
// probe configuration
194-
StartupProbeConfig: parseProbeConfig(helper.Parameters),
195169
}
196170

197171
return result
198172
}
199173

200-
// parseProbeConfig parses probe configuration from plugin parameters
201-
func parseProbeConfig(parameters map[string]string) *ProbeConfig {
202-
config := DefaultProbeConfig()
203-
204-
if val, ok := parameters["startupProbe.initialDelaySeconds"]; ok {
205-
if parsed, err := strconv.ParseInt(val, 10, 32); err == nil {
206-
config.InitialDelaySeconds = int32(parsed)
207-
}
208-
}
209-
210-
if val, ok := parameters["startupProbe.timeoutSeconds"]; ok {
211-
if parsed, err := strconv.ParseInt(val, 10, 32); err == nil {
212-
config.TimeoutSeconds = int32(parsed)
213-
}
214-
}
215-
216-
if val, ok := parameters["startupProbe.periodSeconds"]; ok {
217-
if parsed, err := strconv.ParseInt(val, 10, 32); err == nil {
218-
config.PeriodSeconds = int32(parsed)
219-
}
220-
}
221-
222-
if val, ok := parameters["startupProbe.failureThreshold"]; ok {
223-
if parsed, err := strconv.ParseInt(val, 10, 32); err == nil {
224-
config.FailureThreshold = int32(parsed)
225-
}
226-
}
227-
228-
if val, ok := parameters["startupProbe.successThreshold"]; ok {
229-
if parsed, err := strconv.ParseInt(val, 10, 32); err == nil {
230-
config.SuccessThreshold = int32(parsed)
231-
}
232-
}
233-
234-
return config
235-
}
236-
237174
func getRecoveryParameters(cluster *cnpgv1.Cluster) map[string]string {
238175
recoveryPluginConfiguration := getRecoverySourcePlugin(cluster)
239176
if recoveryPluginConfiguration == nil {

internal/cnpgi/operator/lifecycle.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"k8s.io/utils/ptr"
1818
"sigs.k8s.io/controller-runtime/pkg/client"
1919

20+
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
2021
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
2122
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config"
2223
)
@@ -125,19 +126,24 @@ func (impl LifecycleImplementation) reconcileJob(
125126
return nil, err
126127
}
127128

129+
startupProbe, err := impl.collectSidecarStartupProbeForRecoveryJob(ctx, pluginConfiguration)
130+
if err != nil {
131+
return nil, err
132+
}
133+
128134
return reconcileJob(ctx, cluster, request, sidecarConfiguration{
129135
env: env,
130136
certificates: certificates,
131137
resources: resources,
132-
probeConfig: pluginConfiguration.StartupProbeConfig,
138+
startupProbe: startupProbe,
133139
})
134140
}
135141

136142
type sidecarConfiguration struct {
137143
env []corev1.EnvVar
138144
certificates []corev1.VolumeProjection
139145
resources corev1.ResourceRequirements
140-
probeConfig *config.ProbeConfig
146+
startupProbe *barmancloudv1.ProbeConfig
141147
}
142148

143149
func reconcileJob(
@@ -219,11 +225,16 @@ func (impl LifecycleImplementation) reconcilePod(
219225
return nil, err
220226
}
221227

228+
startupProbe, err := impl.collectSidecarStartupProbeForInstancePod(ctx, pluginConfiguration)
229+
if err != nil {
230+
return nil, err
231+
}
232+
222233
return reconcilePod(ctx, cluster, request, pluginConfiguration, sidecarConfiguration{
223234
env: env,
224235
certificates: certificates,
225236
resources: resources,
226-
probeConfig: pluginConfiguration.StartupProbeConfig,
237+
startupProbe: startupProbe,
227238
})
228239
}
229240

@@ -315,12 +326,13 @@ func reconcilePodSpec(
315326
}
316327

317328
// Apply configurable probe settings if available
318-
if config.probeConfig != nil {
319-
baseProbe.InitialDelaySeconds = config.probeConfig.InitialDelaySeconds
320-
baseProbe.TimeoutSeconds = config.probeConfig.TimeoutSeconds
321-
baseProbe.PeriodSeconds = config.probeConfig.PeriodSeconds
322-
baseProbe.FailureThreshold = config.probeConfig.FailureThreshold
323-
baseProbe.SuccessThreshold = config.probeConfig.SuccessThreshold
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
324336
} else {
325337
// Fallback to default values
326338
baseProbe.FailureThreshold = 10
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package operator
2+
3+
import (
4+
"context"
5+
6+
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
7+
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config"
8+
)
9+
10+
func (impl LifecycleImplementation) collectSidecarStartupProbeForRecoveryJob(
11+
ctx context.Context,
12+
configuration *config.PluginConfiguration,
13+
) (*barmancloudv1.ProbeConfig, error) {
14+
if len(configuration.RecoveryBarmanObjectName) > 0 {
15+
var barmanObjectStore barmancloudv1.ObjectStore
16+
if err := impl.Client.Get(ctx, configuration.GetRecoveryBarmanObjectKey(), &barmanObjectStore); err != nil {
17+
return nil, err
18+
}
19+
20+
return barmanObjectStore.Spec.InstanceSidecarConfiguration.StartupProbe, nil
21+
}
22+
23+
return nil, nil
24+
}
25+
26+
func (impl LifecycleImplementation) collectSidecarStartupProbeForInstancePod(
27+
ctx context.Context,
28+
configuration *config.PluginConfiguration,
29+
) (*barmancloudv1.ProbeConfig, error) {
30+
if len(configuration.BarmanObjectName) > 0 {
31+
// On a replica cluster that also archives, the designated primary
32+
// will use both the replica source object store and the object store
33+
// of the cluster.
34+
// In this case, we use the cluster object store for configuring
35+
// the startup probe of the sidecar container.
36+
37+
var barmanObjectStore barmancloudv1.ObjectStore
38+
if err := impl.Client.Get(ctx, configuration.GetBarmanObjectKey(), &barmanObjectStore); err != nil {
39+
return nil, err
40+
}
41+
42+
return barmanObjectStore.Spec.InstanceSidecarConfiguration.StartupProbe, nil
43+
}
44+
45+
if len(configuration.RecoveryBarmanObjectName) > 0 {
46+
// On a replica cluster that doesn't archive, the designated primary
47+
// uses only the replica source object store.
48+
// In this case, we use the replica source object store for configuring
49+
// the startup probe of the sidecar container.
50+
var barmanObjectStore barmancloudv1.ObjectStore
51+
if err := impl.Client.Get(ctx, configuration.GetRecoveryBarmanObjectKey(), &barmanObjectStore); err != nil {
52+
return nil, err
53+
}
54+
55+
return barmanObjectStore.Spec.InstanceSidecarConfiguration.StartupProbe, nil
56+
}
57+
58+
return nil, nil
59+
}

internal/cnpgi/operator/lifecycle_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
corev1 "k8s.io/api/core/v1"
1111
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1212

13+
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
1314
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config"
1415

1516
. "github.com/onsi/ginkgo/v2"
@@ -173,8 +174,8 @@ var _ = Describe("LifecycleImplementation", func() {
173174

174175
Describe("reconcilePod", func() {
175176
It("returns a patch for a valid pod with probe configuration", func(ctx SpecContext) {
176-
// Configure plugin with custom probe settings
177-
pluginConfiguration.StartupProbeConfig = &config.ProbeConfig{
177+
// Configure sidecar with custom probe settings
178+
startupProbeConfig := &barmancloudv1.ProbeConfig{
178179
InitialDelaySeconds: 1,
179180
TimeoutSeconds: 15,
180181
PeriodSeconds: 2,
@@ -204,7 +205,7 @@ var _ = Describe("LifecycleImplementation", func() {
204205
}
205206

206207
response, err := reconcilePod(ctx, cluster, request, pluginConfiguration, sidecarConfiguration{
207-
probeConfig: pluginConfiguration.StartupProbeConfig,
208+
startupProbe: startupProbeConfig,
208209
})
209210
Expect(err).NotTo(HaveOccurred())
210211
Expect(response).NotTo(BeNil())

0 commit comments

Comments
 (0)