Skip to content

Commit c349bb5

Browse files
author
Joshua Sierles
committed
Allow initcontainers on repo host
1 parent 32d5f54 commit c349bb5

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

internal/controller/postgrescluster/pgbackrest.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,35 @@ func (r *Reconciler) generateRestoreJobIntent(cluster *v1beta1.PostgresCluster,
13671367
},
13681368
}
13691369

1370+
// Add init containers from RepoHost.InitContainers if provided
1371+
if cluster.Spec.Backups.PGBackRest.RepoHost != nil &&
1372+
cluster.Spec.Backups.PGBackRest.RepoHost.InitContainers != nil {
1373+
1374+
// Get the init containers from RepoHost
1375+
initContainers := cluster.Spec.Backups.PGBackRest.RepoHost.InitContainers
1376+
1377+
// If EnvFromSecret is specified, add the reference to each init container
1378+
if cluster.Spec.Backups.PGBackRest.RepoHost.EnvFromSecret != nil {
1379+
secretName := *cluster.Spec.Backups.PGBackRest.RepoHost.EnvFromSecret
1380+
1381+
// Add the envFrom reference to each init container
1382+
for i := range initContainers {
1383+
initContainers[i].EnvFrom = append(
1384+
initContainers[i].EnvFrom,
1385+
corev1.EnvFromSource{
1386+
SecretRef: &corev1.SecretEnvSource{
1387+
LocalObjectReference: corev1.LocalObjectReference{
1388+
Name: secretName,
1389+
},
1390+
},
1391+
})
1392+
}
1393+
}
1394+
1395+
// Add the init containers to the job's pod spec
1396+
job.Spec.Template.Spec.InitContainers = initContainers
1397+
}
1398+
13701399
// Add environment variables from the pgBackRest.RepoHost.EnvFromSecret if provided
13711400
// This allows for environment variables to be set on the restore job from a Secret
13721401
if cluster.Spec.Backups.PGBackRest.RepoHost != nil &&

pkg/apis/postgres-operator.crunchydata.com/v1beta1/pgbackrest_types.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,12 @@ type PGBackRestRepoHost struct {
217217
// +optional
218218
Affinity *corev1.Affinity `json:"affinity,omitempty"`
219219

220-
// Custom sidecars for the pgBackRest repository host. Changing this value causes
220+
// Custom init containers for the pgBackRest repository host. These containers run to completion
221+
// before the main containers start. Changing this value causes the pgBackRest repository host to restart.
222+
// +optional
223+
InitContainers []corev1.Container `json:"initContainers,omitempty"`
224+
225+
// Custom sidecars for the pgBackRest repository host. Changing this value causes
221226
// the pgBackRest repository host to restart.
222227
// +optional
223228
Containers []corev1.Container `json:"containers,omitempty"`

0 commit comments

Comments
 (0)