Skip to content

Commit

Permalink
Add additional configuration files to the restore Job Pod
Browse files Browse the repository at this point in the history
To support necessary TDE configurations, this commit adds any
configured items, such as ConfigMaps or Secrets, from the `config`
field to be mounted at `/etc/postgres` in the restore Job Pod's
'pgbackrest-restore' Container.

Issue: PGO-909
  • Loading branch information
tjmoore4 committed Feb 5, 2024
1 parent 89bfbe9 commit 6bcbbfd
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
17 changes: 17 additions & 0 deletions internal/pgbackrest/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,23 @@ func AddConfigToRestorePod(
cluster.Spec.DataSource.PGBackRest.Configuration...)
}

// mount any provided configuration files to the restore Job Pod
if len(cluster.Spec.Config.Files) != 0 {
additionalConfigVolumeMount := postgres.AdditionalConfigVolumeMount()
additionalConfigVolume := corev1.Volume{Name: additionalConfigVolumeMount.Name}
additionalConfigVolume.Projected = &corev1.ProjectedVolumeSource{
Sources: append(sources, cluster.Spec.Config.Files...),
}
for i := range pod.Containers {
container := &pod.Containers[i]

if container.Name == naming.PGBackRestRestoreContainerName {
container.VolumeMounts = append(container.VolumeMounts, additionalConfigVolumeMount)
}
}
pod.Volumes = append(pod.Volumes, additionalConfigVolume)
}

addConfigVolumeAndMounts(pod, append(sources, configmap, secret))
}

Expand Down
45 changes: 45 additions & 0 deletions internal/pgbackrest/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,51 @@ func TestAddConfigToRestorePod(t *testing.T) {
optional: true
`))
})

t.Run("CustomFiles", func(t *testing.T) {
custom := corev1.ConfigMapProjection{}
custom.Name = "custom-configmap-files"

cluster := cluster.DeepCopy()
cluster.Spec.Config.Files = []corev1.VolumeProjection{
{ConfigMap: &custom},
}

sourceCluster := cluster.DeepCopy()

out := pod.DeepCopy()
AddConfigToRestorePod(cluster, sourceCluster, out)
alwaysExpect(t, out)

// Instance configuration files and optional configuration files
// after custom projections.
assert.Assert(t, marshalMatches(out.Volumes, `
- name: postgres-config
projected:
sources:
- configMap:
name: custom-configmap-files
- name: pgbackrest-config
projected:
sources:
- configMap:
items:
- key: pgbackrest_instance.conf
path: pgbackrest_instance.conf
name: source-pgbackrest-config
- secret:
items:
- key: pgbackrest.ca-roots
path: ~postgres-operator/tls-ca.crt
- key: pgbackrest-client.crt
path: ~postgres-operator/client-tls.crt
- key: pgbackrest-client.key
mode: 384
path: ~postgres-operator/client-tls.key
name: source-pgbackrest
optional: true
`))
})
}

func TestAddServerToInstancePod(t *testing.T) {
Expand Down

0 comments on commit 6bcbbfd

Please sign in to comment.