MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / AddConfigToRestorePod

Function AddConfigToRestorePod

internal/pgbackrest/reconcile.go:190–260  ·  view source on GitHub ↗

AddConfigToRestorePod adds and mounts the pgBackRest configuration volume for the restore job of cluster to pod. The pgBackRest containers must already be in pod.

(
	cluster *v1beta1.PostgresCluster, sourceCluster *v1beta1.PostgresCluster, pod *corev1.PodSpec,
)

Source from the content-addressed store, hash-verified

188// for the restore job of cluster to pod. The pgBackRest containers must
189// already be in pod.
190func AddConfigToRestorePod(
191 cluster *v1beta1.PostgresCluster, sourceCluster *v1beta1.PostgresCluster, pod *corev1.PodSpec,
192) {
193 configmap := corev1.VolumeProjection{ConfigMap: &corev1.ConfigMapProjection{}}
194 configmap.ConfigMap.Name = naming.PGBackRestConfig(cluster).Name
195 configmap.ConfigMap.Items = []corev1.KeyToPath{
196 // TODO(cbandy): This may be the instance configuration of a cluster
197 // different from the one we are building/creating. For now the
198 // stanza options are "pg1-path", "pg1-port", and "pg1-socket-path"
199 // and these are safe enough to use across different clusters running
200 // the same PostgreSQL version. When that list grows, consider changing
201 // this to use local stanza options and remote repository options.
202 // See also [RestoreConfig].
203 {Key: CMInstanceKey, Path: CMInstanceKey},
204 }
205
206 // Mount client certificates of the source cluster if they exist.
207 secret := corev1.VolumeProjection{Secret: &corev1.SecretProjection{}}
208 secret.Secret.Name = naming.PGBackRestSecret(cluster).Name
209 secret.Secret.Items = append(secret.Secret.Items, clientCertificates()...)
210 secret.Secret.Optional = initialize.Bool(true)
211
212 // Start with a copy of projections specified in the cluster. Items later in
213 // the list take precedence over earlier items (that is, last write wins).
214 // - https://kubernetes.io/docs/concepts/storage/volumes/#projected
215 sources := append([]corev1.VolumeProjection{},
216 cluster.Spec.Backups.PGBackRest.Configuration...)
217
218 // For a PostgresCluster restore, append all pgBackRest configuration from
219 // the source cluster for the restore.
220 if sourceCluster != nil {
221 sources = append(sources, sourceCluster.Spec.Backups.PGBackRest.Configuration...)
222 }
223
224 // Currently the spec accepts a dataSource with both a PostgresCluster and
225 // a PGBackRest section. In that case only the PostgresCluster is honored (see
226 // internal/controller/postgrescluster/cluster.go, reconcileDataSource).
227 //
228 // `sourceCluster` is always nil for a cloud based restore (see
229 // internal/controller/postgrescluster/pgbackrest.go, reconcileCloudBasedDataSource).
230 //
231 // So, if `sourceCluster` is nil and `DataSource.PGBackRest` is not,
232 // this is a cloud based datasource restore and only the configuration from
233 // `dataSource.pgbackrest` section should be included.
234 if sourceCluster == nil &&
235 cluster.Spec.DataSource != nil &&
236 cluster.Spec.DataSource.PGBackRest != nil {
237
238 sources = append([]corev1.VolumeProjection{},
239 cluster.Spec.DataSource.PGBackRest.Configuration...)
240 }
241
242 // mount any provided configuration files to the restore Job Pod
243 if cluster.Spec.Config != nil && len(cluster.Spec.Config.Files) != 0 {
244 additionalConfigVolumeMount := postgres.ConfigVolumeMount()
245 additionalConfigVolume := corev1.Volume{Name: additionalConfigVolumeMount.Name}
246 additionalConfigVolume.Projected = &corev1.ProjectedVolumeSource{
247 Sources: append(sources, cluster.Spec.Config.Files...),

Callers 3

reconcileRestoreJobMethod · 0.92

Calls 6

PGBackRestConfigFunction · 0.92
PGBackRestSecretFunction · 0.92
BoolFunction · 0.92
ConfigVolumeMountFunction · 0.92
clientCertificatesFunction · 0.85
addConfigVolumeAndMountsFunction · 0.85

Tested by 1