@@ -123,15 +123,29 @@ func (impl LifecycleImplementation) reconcileJob(
123123 return nil , err
124124 }
125125
126- return reconcileJob (ctx , cluster , request , env , certificates )
126+ resources , err := impl .collectSidecarResourcesForRecoveryJob (ctx , pluginConfiguration )
127+ if err != nil {
128+ return nil , err
129+ }
130+
131+ return reconcileJob (ctx , cluster , request , sidecarConfiguration {
132+ env : env ,
133+ certificates : certificates ,
134+ resources : resources ,
135+ })
136+ }
137+
138+ type sidecarConfiguration struct {
139+ env []corev1.EnvVar
140+ certificates []corev1.VolumeProjection
141+ resources corev1.ResourceRequirements
127142}
128143
129144func reconcileJob (
130145 ctx context.Context ,
131146 cluster * cnpgv1.Cluster ,
132147 request * lifecycle.OperatorLifecycleRequest ,
133- env []corev1.EnvVar ,
134- certificates []corev1.VolumeProjection ,
148+ config sidecarConfiguration ,
135149) (* lifecycle.OperatorLifecycleResponse , error ) {
136150 contextLogger := log .FromContext (ctx ).WithName ("lifecycle" )
137151 if pluginConfig := cluster .GetRecoverySourcePlugin (); pluginConfig == nil || pluginConfig .Name != metadata .PluginName {
@@ -169,8 +183,7 @@ func reconcileJob(
169183 corev1.Container {
170184 Args : []string {"restore" },
171185 },
172- env ,
173- certificates ,
186+ config ,
174187 ); err != nil {
175188 return nil , fmt .Errorf ("while reconciling pod spec for job: %w" , err )
176189 }
@@ -202,16 +215,24 @@ func (impl LifecycleImplementation) reconcilePod(
202215 return nil , err
203216 }
204217
205- return reconcilePod (ctx , cluster , request , pluginConfiguration , env , certificates )
218+ resources , err := impl .collectSidecarResourcesForPod (ctx , pluginConfiguration )
219+ if err != nil {
220+ return nil , err
221+ }
222+
223+ return reconcilePod (ctx , cluster , request , pluginConfiguration , sidecarConfiguration {
224+ env : env ,
225+ certificates : certificates ,
226+ resources : resources ,
227+ })
206228}
207229
208230func reconcilePod (
209231 ctx context.Context ,
210232 cluster * cnpgv1.Cluster ,
211233 request * lifecycle.OperatorLifecycleRequest ,
212234 pluginConfiguration * config.PluginConfiguration ,
213- env []corev1.EnvVar ,
214- certificates []corev1.VolumeProjection ,
235+ config sidecarConfiguration ,
215236) (* lifecycle.OperatorLifecycleResponse , error ) {
216237 pod , err := decoder .DecodePodJSON (request .GetObjectDefinition ())
217238 if err != nil {
@@ -232,8 +253,7 @@ func reconcilePod(
232253 corev1.Container {
233254 Args : []string {"instance" },
234255 },
235- env ,
236- certificates ,
256+ config ,
237257 ); err != nil {
238258 return nil , fmt .Errorf ("while reconciling pod spec for pod: %w" , err )
239259 }
@@ -256,9 +276,8 @@ func reconcilePodSpec(
256276 cluster * cnpgv1.Cluster ,
257277 spec * corev1.PodSpec ,
258278 mainContainerName string ,
259- sidecarConfig corev1.Container ,
260- additionalEnvs []corev1.EnvVar ,
261- certificates []corev1.VolumeProjection ,
279+ sidecarTemplate corev1.Container ,
280+ config sidecarConfiguration ,
262281) error {
263282 envs := []corev1.EnvVar {
264283 {
@@ -285,7 +304,7 @@ func reconcilePodSpec(
285304 },
286305 }
287306
288- envs = append (envs , additionalEnvs ... )
307+ envs = append (envs , config . env ... )
289308
290309 baseProbe := & corev1.Probe {
291310 FailureThreshold : 10 ,
@@ -298,11 +317,11 @@ func reconcilePodSpec(
298317 }
299318
300319 // fixed values
301- sidecarConfig .Name = "plugin-barman-cloud"
302- sidecarConfig .Image = viper .GetString ("sidecar-image" )
303- sidecarConfig .ImagePullPolicy = cluster .Spec .ImagePullPolicy
304- sidecarConfig .StartupProbe = baseProbe .DeepCopy ()
305- sidecarConfig .SecurityContext = & corev1.SecurityContext {
320+ sidecarTemplate .Name = "plugin-barman-cloud"
321+ sidecarTemplate .Image = viper .GetString ("sidecar-image" )
322+ sidecarTemplate .ImagePullPolicy = cluster .Spec .ImagePullPolicy
323+ sidecarTemplate .StartupProbe = baseProbe .DeepCopy ()
324+ sidecarTemplate .SecurityContext = & corev1.SecurityContext {
306325 AllowPrivilegeEscalation : ptr .To (false ),
307326 RunAsNonRoot : ptr .To (true ),
308327 Privileged : ptr .To (false ),
@@ -314,20 +333,21 @@ func reconcilePodSpec(
314333 Drop : []corev1.Capability {"ALL" },
315334 },
316335 }
336+ sidecarTemplate .Resources = config .resources
317337
318338 // merge the main container envs if they aren't already set
319339 for _ , container := range spec .Containers {
320340 if container .Name == mainContainerName {
321341 for _ , env := range container .Env {
322342 found := false
323- for _ , existingEnv := range sidecarConfig .Env {
343+ for _ , existingEnv := range sidecarTemplate .Env {
324344 if existingEnv .Name == env .Name {
325345 found = true
326346 break
327347 }
328348 }
329349 if ! found {
330- sidecarConfig .Env = append (sidecarConfig .Env , env )
350+ sidecarTemplate .Env = append (sidecarTemplate .Env , env )
331351 }
332352 }
333353 break
@@ -337,18 +357,18 @@ func reconcilePodSpec(
337357 // merge the default envs if they aren't already set
338358 for _ , env := range envs {
339359 found := false
340- for _ , existingEnv := range sidecarConfig .Env {
360+ for _ , existingEnv := range sidecarTemplate .Env {
341361 if existingEnv .Name == env .Name {
342362 found = true
343363 break
344364 }
345365 }
346366 if ! found {
347- sidecarConfig .Env = append (sidecarConfig .Env , env )
367+ sidecarTemplate .Env = append (sidecarTemplate .Env , env )
348368 }
349369 }
350370
351- if err := injectPluginSidecarPodSpec (spec , & sidecarConfig , mainContainerName ); err != nil {
371+ if err := injectPluginSidecarPodSpec (spec , & sidecarTemplate , mainContainerName ); err != nil {
352372 return err
353373 }
354374
@@ -358,7 +378,7 @@ func reconcilePodSpec(
358378 Name : barmanCertificatesVolumeName ,
359379 VolumeSource : corev1.VolumeSource {
360380 Projected : & corev1.ProjectedVolumeSource {
361- Sources : certificates ,
381+ Sources : config . certificates ,
362382 },
363383 },
364384 })
0 commit comments