@@ -36,6 +36,7 @@ import (
3636 "k8s.io/apimachinery/pkg/fields"
3737 "k8s.io/client-go/kubernetes"
3838 "k8s.io/client-go/rest"
39+ "sigs.k8s.io/yaml"
3940)
4041
4142// Store image names as constants to use later
@@ -297,9 +298,6 @@ func deleteBeforeUpgrade(clientset *kubernetes.Clientset, restclient *rest.RESTC
297298 // delete the '<cluster-name>-pgha-default-config' configmap, if it exists so the config syncer
298299 // will not try to use it instead of '<cluster-name>-pgha-config'
299300 checkDeleteConfigmap (clientset , clusterName + "-pgha-default-config" , namespace )
300-
301- // delete the backrest repo config secret, since key encryption has been updated from RSA to EdDSA
302- kubeapi .DeleteSecret (clientset , clusterName + "-backrest-repo-config" , namespace )
303301}
304302
305303// deploymentWait is modified from cluster.waitForDeploymentDelete. It simply waits for the current primary deployment
@@ -403,17 +401,52 @@ func createUpgradePGHAConfigMap(clientset *kubernetes.Clientset, cluster *crv1.P
403401 return nil
404402}
405403
406- // recreateBackrestRepoSecret deletes and recreates the secret for the pgBackRest repo. This is needed
404+ // recreateBackrestRepoSecret overwrites the secret for the pgBackRest repo. This is needed
407405// because the key encryption algorithm has been updated from RSA to EdDSA
408406func recreateBackrestRepoSecret (clientset * kubernetes.Clientset , clustername , namespace , operatorNamespace string ) {
409- if err := util .CreateBackrestRepoSecrets (clientset ,
410- util.BackrestRepoConfig {
411- BackrestS3Key : "" , // these are set to empty so that it can be generated
412- BackrestS3KeySecret : "" ,
413- ClusterName : clustername ,
414- ClusterNamespace : namespace ,
415- OperatorNamespace : operatorNamespace ,
416- }); err != nil {
407+ config := util.BackrestRepoConfig {
408+ ClusterName : clustername ,
409+ ClusterNamespace : namespace ,
410+ OperatorNamespace : operatorNamespace ,
411+ }
412+
413+ secretName := clustername + "-backrest-repo-config"
414+ secret , err := clientset .CoreV1 ().Secrets (namespace ).Get (secretName , meta_v1.GetOptions {})
415+
416+ // 4.1, 4.2
417+ if err == nil {
418+ if b , ok := secret .Data ["aws-s3-ca.crt" ]; ok {
419+ config .BackrestS3CA = b
420+ }
421+ if b , ok := secret .Data ["aws-s3-credentials.yaml" ]; ok {
422+ var parsed struct {
423+ Key string `yaml:"aws-s3-key"`
424+ KeySecret string `yaml:"aws-s3-key-secret"`
425+ }
426+ if err = yaml .Unmarshal (b , & parsed ); err == nil {
427+ config .BackrestS3Key = parsed .Key
428+ config .BackrestS3KeySecret = parsed .KeySecret
429+ }
430+ }
431+ }
432+
433+ // >= 4.3
434+ if err == nil {
435+ if b , ok := secret .Data ["aws-s3-ca.crt" ]; ok {
436+ config .BackrestS3CA = b
437+ }
438+ if b , ok := secret .Data ["aws-s3-key" ]; ok {
439+ config .BackrestS3Key = string (b )
440+ }
441+ if b , ok := secret .Data ["aws-s3-key-secret" ]; ok {
442+ config .BackrestS3KeySecret = string (b )
443+ }
444+ }
445+
446+ if err == nil {
447+ err = util .CreateBackrestRepoSecrets (clientset , config )
448+ }
449+ if err != nil {
417450 log .Errorf ("error generating new backrest repo secrets during pgcluster upgrade: %v" , err )
418451 }
419452}
0 commit comments