AddConfigToInstancePod adds and mounts the pgBackRest configuration volumes for an instance of cluster to pod. The database container and any pgBackRest containers must already be in pod.
( cluster *v1beta1.PostgresCluster, pod *corev1.PodSpec, )
| 96 | // for an instance of cluster to pod. The database container and any pgBackRest |
| 97 | // containers must already be in pod. |
| 98 | func AddConfigToInstancePod( |
| 99 | cluster *v1beta1.PostgresCluster, pod *corev1.PodSpec, |
| 100 | ) { |
| 101 | configmap := corev1.VolumeProjection{ConfigMap: &corev1.ConfigMapProjection{}} |
| 102 | configmap.ConfigMap.Name = naming.PGBackRestConfig(cluster).Name |
| 103 | configmap.ConfigMap.Items = []corev1.KeyToPath{ |
| 104 | {Key: CMInstanceKey, Path: CMInstanceKey}, |
| 105 | {Key: ConfigHashKey, Path: ConfigHashKey}, |
| 106 | {Key: serverConfigMapKey, Path: serverConfigProjectionPath}, |
| 107 | } |
| 108 | |
| 109 | // As the cluster transitions from having a repository host to having none, |
| 110 | // PostgreSQL instances that have not rolled out expect to mount client |
| 111 | // certificates. Specify those files are optional so the configuration |
| 112 | // volumes stay valid and Kubernetes propagates their contents to those pods. |
| 113 | secret := corev1.VolumeProjection{Secret: &corev1.SecretProjection{}} |
| 114 | secret.Secret.Name = naming.PGBackRestSecret(cluster).Name |
| 115 | secret.Secret.Items = append(secret.Secret.Items, clientCertificates()...) |
| 116 | secret.Secret.Optional = initialize.Bool(true) |
| 117 | |
| 118 | // Start with a copy of projections specified in the cluster. Items later in |
| 119 | // the list take precedence over earlier items (that is, last write wins). |
| 120 | // - https://kubernetes.io/docs/concepts/storage/volumes/#projected |
| 121 | sources := append([]corev1.VolumeProjection{}, |
| 122 | cluster.Spec.Backups.PGBackRest.Configuration...) |
| 123 | |
| 124 | if len(secret.Secret.Items) > 0 { |
| 125 | sources = append(sources, configmap, secret) |
| 126 | } else { |
| 127 | sources = append(sources, configmap) |
| 128 | } |
| 129 | |
| 130 | addConfigVolumeAndMounts(pod, sources) |
| 131 | } |
| 132 | |
| 133 | // AddConfigToRepoPod adds and mounts the pgBackRest configuration volumes for |
| 134 | // the dedicated repository host of cluster to pod. The pgBackRest containers |