@@ -7,53 +7,117 @@ import (
77 "github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config"
88)
99
10- func (impl LifecycleImplementation ) collectSidecarStartupProbeForRecoveryJob (
10+ // probeAccessor is a function type that extracts a specific probe configuration from an ObjectStore
11+ type probeAccessor func (* barmancloudv1.ObjectStore ) * barmancloudv1.ProbeConfig
12+
13+ // collectSidecarProbeForRecoveryJob is a generic function to collect probe configurations for recovery jobs
14+ func (impl LifecycleImplementation ) collectSidecarProbeForRecoveryJob (
1115 ctx context.Context ,
1216 configuration * config.PluginConfiguration ,
17+ accessor probeAccessor ,
1318) (* barmancloudv1.ProbeConfig , error ) {
1419 if len (configuration .RecoveryBarmanObjectName ) > 0 {
1520 var barmanObjectStore barmancloudv1.ObjectStore
1621 if err := impl .Client .Get (ctx , configuration .GetRecoveryBarmanObjectKey (), & barmanObjectStore ); err != nil {
1722 return nil , err
1823 }
1924
20- return barmanObjectStore . Spec . InstanceSidecarConfiguration . StartupProbe , nil
25+ return accessor ( & barmanObjectStore ) , nil
2126 }
2227
2328 return nil , nil
2429}
2530
26- func (impl LifecycleImplementation ) collectSidecarStartupProbeForInstancePod (
31+ // collectSidecarProbeForInstancePod is a generic function to collect probe configurations for instance pods
32+ func (impl LifecycleImplementation ) collectSidecarProbeForInstancePod (
2733 ctx context.Context ,
2834 configuration * config.PluginConfiguration ,
35+ accessor probeAccessor ,
36+ probeType string ,
2937) (* barmancloudv1.ProbeConfig , error ) {
3038 if len (configuration .BarmanObjectName ) > 0 {
3139 // On a replica cluster that also archives, the designated primary
3240 // will use both the replica source object store and the object store
3341 // of the cluster.
3442 // In this case, we use the cluster object store for configuring
35- // the startup probe of the sidecar container.
43+ // the probe of the sidecar container.
3644
3745 var barmanObjectStore barmancloudv1.ObjectStore
3846 if err := impl .Client .Get (ctx , configuration .GetBarmanObjectKey (), & barmanObjectStore ); err != nil {
3947 return nil , err
4048 }
4149
42- return barmanObjectStore . Spec . InstanceSidecarConfiguration . StartupProbe , nil
50+ return accessor ( & barmanObjectStore ) , nil
4351 }
4452
4553 if len (configuration .RecoveryBarmanObjectName ) > 0 {
4654 // On a replica cluster that doesn't archive, the designated primary
4755 // uses only the replica source object store.
4856 // In this case, we use the replica source object store for configuring
49- // the startup probe of the sidecar container.
57+ // the probe of the sidecar container.
5058 var barmanObjectStore barmancloudv1.ObjectStore
5159 if err := impl .Client .Get (ctx , configuration .GetRecoveryBarmanObjectKey (), & barmanObjectStore ); err != nil {
5260 return nil , err
5361 }
5462
55- return barmanObjectStore . Spec . InstanceSidecarConfiguration . StartupProbe , nil
63+ return accessor ( & barmanObjectStore ) , nil
5664 }
5765
5866 return nil , nil
5967}
68+
69+ // Specific probe collection methods that use the generic functions
70+
71+ func (impl LifecycleImplementation ) collectSidecarStartupProbeForRecoveryJob (
72+ ctx context.Context ,
73+ configuration * config.PluginConfiguration ,
74+ ) (* barmancloudv1.ProbeConfig , error ) {
75+ return impl .collectSidecarProbeForRecoveryJob (ctx , configuration , func (store * barmancloudv1.ObjectStore ) * barmancloudv1.ProbeConfig {
76+ return store .Spec .InstanceSidecarConfiguration .StartupProbe
77+ })
78+ }
79+
80+ func (impl LifecycleImplementation ) collectSidecarStartupProbeForInstancePod (
81+ ctx context.Context ,
82+ configuration * config.PluginConfiguration ,
83+ ) (* barmancloudv1.ProbeConfig , error ) {
84+ return impl .collectSidecarProbeForInstancePod (ctx , configuration , func (store * barmancloudv1.ObjectStore ) * barmancloudv1.ProbeConfig {
85+ return store .Spec .InstanceSidecarConfiguration .StartupProbe
86+ }, "startup" )
87+ }
88+
89+ func (impl LifecycleImplementation ) collectSidecarLivenessProbeForRecoveryJob (
90+ ctx context.Context ,
91+ configuration * config.PluginConfiguration ,
92+ ) (* barmancloudv1.ProbeConfig , error ) {
93+ return impl .collectSidecarProbeForRecoveryJob (ctx , configuration , func (store * barmancloudv1.ObjectStore ) * barmancloudv1.ProbeConfig {
94+ return store .Spec .InstanceSidecarConfiguration .LivenessProbe
95+ })
96+ }
97+
98+ func (impl LifecycleImplementation ) collectSidecarLivenessProbeForInstancePod (
99+ ctx context.Context ,
100+ configuration * config.PluginConfiguration ,
101+ ) (* barmancloudv1.ProbeConfig , error ) {
102+ return impl .collectSidecarProbeForInstancePod (ctx , configuration , func (store * barmancloudv1.ObjectStore ) * barmancloudv1.ProbeConfig {
103+ return store .Spec .InstanceSidecarConfiguration .LivenessProbe
104+ }, "liveness" )
105+ }
106+
107+ func (impl LifecycleImplementation ) collectSidecarReadinessProbeForRecoveryJob (
108+ ctx context.Context ,
109+ configuration * config.PluginConfiguration ,
110+ ) (* barmancloudv1.ProbeConfig , error ) {
111+ return impl .collectSidecarProbeForRecoveryJob (ctx , configuration , func (store * barmancloudv1.ObjectStore ) * barmancloudv1.ProbeConfig {
112+ return store .Spec .InstanceSidecarConfiguration .ReadinessProbe
113+ })
114+ }
115+
116+ func (impl LifecycleImplementation ) collectSidecarReadinessProbeForInstancePod (
117+ ctx context.Context ,
118+ configuration * config.PluginConfiguration ,
119+ ) (* barmancloudv1.ProbeConfig , error ) {
120+ return impl .collectSidecarProbeForInstancePod (ctx , configuration , func (store * barmancloudv1.ObjectStore ) * barmancloudv1.ProbeConfig {
121+ return store .Spec .InstanceSidecarConfiguration .ReadinessProbe
122+ }, "readiness" )
123+ }
0 commit comments