Skip to content

Commit 639324a

Browse files
andrewlecuyercbandy
authored andcommitted
Default URI Style for S3 Bootstrap
The proper default S3 URI style is now set when generating the pgBackRest S3 environment variables for a bootstrap Job (i.e. a Job created to bootstrap a cluster from an existing backup, such as when using the '--restore-from' flag with the 'pgo' client). Specifically, if an empty string is detected in the 's3-uri-style' annotation for the pgBackRest repo secret for the cluster being bootstrapped/restored from, a proper default value of 'host' is now set. This ensures there is never an empty value for the PGBACKREST_REPO1_S3_URI_STYLE environment variable in a bootstrap Pod, which can lead to problems when running various pgBackRest commands. Additionally, tests have been created to verify the output of the GetPgbackrestBootstrapS3EnvVars function that is utilized to populate the proper S3 environment variables for a bootstrap Job (specifically using the pgBackRest repo secret from the cluster being bootstrapped from). This includes ensuring the proper default URI style is set when the 's3-uri-style' annotation is empty, as well as ensuring all annotation values are properly reflected in the final S3 environment variable output. In support of these tests, a NewFakePGOClient function has also been created in the 'fake' package (underneath 'kubeapi'). This is needed to create a fake client containing the proper resources (i.e. a mock 'pgo-config' ConfigMap) as need to initialize the Operator and therefore the various templates needed to properly call the GetPgbackrestBootstrapS3EnvVars function for these tests (PGOROOT must be properly set in the environment when running tests so that the proper default template files and pgo.yaml file can be found as needed to create the mock 'pgo-config' ConfigMap). Issue: [ch8915] See: c503b9d
1 parent 04b6c48 commit 639324a

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

internal/operator/backrest/repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ func setBootstrapRepoOverrides(clientset kubernetes.Interface, cluster *crv1.Pgc
191191
s3Restore := S3RepoTypeCLIOptionExists(cluster.Spec.PGDataSource.RestoreOpts)
192192
if s3Restore {
193193
// Now override any backrest S3 env vars for the bootstrap job
194-
repoFields.PgbackrestS3EnvVars = operator.GetPgbackrestBootstrapS3EnvVars(cluster,
195-
restoreFromSecret)
194+
repoFields.PgbackrestS3EnvVars = operator.GetPgbackrestBootstrapS3EnvVars(
195+
cluster.Spec.PGDataSource.RestoreFrom, restoreFromSecret)
196196
} else {
197197
repoFields.PgbackrestS3EnvVars = ""
198198
}

internal/operator/cluster/clusterlogic.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ func getBootstrapJobFields(clientset kubernetes.Interface, client *rest.RESTClie
246246
s3Restore := backrest.S3RepoTypeCLIOptionExists(cluster.Spec.PGDataSource.RestoreOpts)
247247
if s3Restore {
248248
// Now override any backrest S3 env vars for the bootstrap job
249-
bootstrapFields.PgbackrestS3EnvVars = operator.GetPgbackrestBootstrapS3EnvVars(cluster,
250-
restoreFromSecret)
249+
bootstrapFields.PgbackrestS3EnvVars = operator.GetPgbackrestBootstrapS3EnvVars(
250+
cluster.Spec.PGDataSource.RestoreFrom, restoreFromSecret)
251251
} else {
252252
bootstrapFields.PgbackrestS3EnvVars = ""
253253
}

internal/operator/clusterutilities.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ const (
5757
PGHAConfigReplicaBootstrapRepoType = "replica-bootstrap-repo-type"
5858
)
5959

60+
// defaultPGBackRestS3URIStyle is the default pgBackRest S3 URI style to use if a specific style is
61+
// not provided
62+
const defaultPGBackRestS3URIStyle = "host"
63+
6064
// affinityType represents the two affinity types provided by Kubernetes, specifically
6165
// either preferredDuringSchedulingIgnoredDuringExecution or
6266
// requiredDuringSchedulingIgnoredDuringExecution
@@ -779,7 +783,7 @@ func GetPgbackrestS3EnvVars(cluster crv1.Pgcluster, clientset kubernetes.Interfa
779783

780784
// if the URI style is not configured, set to the default value
781785
if s3EnvVars.PgbackrestS3URIStyle == "" {
782-
s3EnvVars.PgbackrestS3URIStyle = "host"
786+
s3EnvVars.PgbackrestS3URIStyle = defaultPGBackRestS3URIStyle
783787
}
784788
// if set, pgBackRest URI style must be set to either 'path' or 'host'. If it is neither,
785789
// log an error and stop the cluster from being created.
@@ -828,18 +832,23 @@ func GetS3VerifyTLSSetting(cluster *crv1.Pgcluster) string {
828832
// pgBackRest environment variables required to enable S3 support for the boostrap job. After
829833
// the template has been executed with the proper values, the result is then returned a string
830834
// for inclusion in the PG and pgBackRest deployments.
831-
func GetPgbackrestBootstrapS3EnvVars(cluster *crv1.Pgcluster, restoreFromSecret *v1.Secret) string {
835+
func GetPgbackrestBootstrapS3EnvVars(pgDataSourceRestoreFrom string,
836+
restoreFromSecret *v1.Secret) string {
832837

833838
s3EnvVars := PgbackrestS3EnvVarsTemplateFields{
834-
PgbackrestS3Key: util.BackRestRepoSecretKeyAWSS3KeyAWSS3Key,
835-
PgbackrestS3KeySecret: util.BackRestRepoSecretKeyAWSS3KeyAWSS3KeySecret,
836-
PgbackrestS3Bucket: restoreFromSecret.Annotations[config.ANNOTATION_S3_BUCKET],
837-
PgbackrestS3Endpoint: restoreFromSecret.Annotations[config.ANNOTATION_S3_ENDPOINT],
838-
PgbackrestS3Region: restoreFromSecret.Annotations[config.ANNOTATION_S3_REGION],
839-
PgbackrestS3URIStyle: restoreFromSecret.Annotations[config.ANNOTATION_S3_URI_STYLE],
840-
PgbackrestS3VerifyTLS: restoreFromSecret.Annotations[config.ANNOTATION_S3_VERIFY_TLS],
841-
PgbackrestS3SecretName: fmt.Sprintf(util.BackrestRepoSecretName,
842-
cluster.Spec.PGDataSource.RestoreFrom),
839+
PgbackrestS3Key: util.BackRestRepoSecretKeyAWSS3KeyAWSS3Key,
840+
PgbackrestS3KeySecret: util.BackRestRepoSecretKeyAWSS3KeyAWSS3KeySecret,
841+
PgbackrestS3Bucket: restoreFromSecret.Annotations[config.ANNOTATION_S3_BUCKET],
842+
PgbackrestS3Endpoint: restoreFromSecret.Annotations[config.ANNOTATION_S3_ENDPOINT],
843+
PgbackrestS3Region: restoreFromSecret.Annotations[config.ANNOTATION_S3_REGION],
844+
PgbackrestS3SecretName: fmt.Sprintf(util.BackrestRepoSecretName, pgDataSourceRestoreFrom),
845+
}
846+
847+
// if the URI style annotation is empty then set the proper default
848+
if restoreFromSecret.Annotations[config.ANNOTATION_S3_URI_STYLE] != "" {
849+
s3EnvVars.PgbackrestS3URIStyle = restoreFromSecret.Annotations[config.ANNOTATION_S3_URI_STYLE]
850+
} else {
851+
s3EnvVars.PgbackrestS3URIStyle = defaultPGBackRestS3URIStyle
843852
}
844853

845854
verifyTLS := restoreFromSecret.Annotations[config.ANNOTATION_S3_VERIFY_TLS]

0 commit comments

Comments
 (0)