Skip to content

Commit 655cf2b

Browse files
Jonathan S. Katzjkatz
authored andcommitted
Ensure Kubernetes Secrets associated with backups are deleted when specified.
During a PostgreSQL delete operation where the user explicitly specifies to delete the backups `e.g. pgo delete cluster clustername --delete-backups`, the `<clustername>-pgbackrest-repo-config` secret was not being deleted. Given all the backups for that cluster are destroyed, the secret is effectively moot and should be removed. This ensures that the `<clustername>-pgbackrest-repo-config` secret is removed when `--delete-backups` is specified. However, if only `--delete-data` is specified but not `--delete-backups`, the aforementioned secret remains. Issue: [ch6254]
1 parent 945a009 commit 655cf2b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pgo-rmdata/rmdata/process.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717

1818
import (
1919
"errors"
20+
"fmt"
21+
2022
crv1 "github.com/crunchydata/postgres-operator/apis/cr/v1"
2123
"github.com/crunchydata/postgres-operator/config"
2224
"github.com/crunchydata/postgres-operator/kubeapi"
@@ -99,6 +101,7 @@ func Delete(request Request) {
99101
removeBackrestRepo(request)
100102
removeBackupJobs(request)
101103
removeBackups(request)
104+
removeBackupSecrets(request)
102105
}
103106

104107
//handle the case of 'pgo delete cluster mycluster'
@@ -157,6 +160,31 @@ func removeBackups(request Request) {
157160

158161
}
159162

163+
// removeBackupSecrets removes any secrets that are associated with backups
164+
// for this cluster, in particular, the secret that is used by the pgBackRest
165+
// repository that is available for this cluster.
166+
func removeBackupSecrets(request Request) {
167+
// first, derive the secrename of the pgBackRest repo, which is the
168+
// "`clusterName`-`LABEL_BACKREST_REPO_SECRET`"
169+
secretName := fmt.Sprintf("%s-%s",
170+
request.ClusterName, config.LABEL_BACKREST_REPO_SECRET)
171+
log.Debugf("removeBackupSecrets: %s", secretName)
172+
173+
// we can attempt to delete the secret directly without making any further
174+
// API calls. Even if we did a "get", there could still be a race with some
175+
// independent process (e.g. an external user) deleting the secret before we
176+
// get to it. The main goal is to have the secret deleted
177+
//
178+
// we'll also check to see if there was an error, but if there is we'll only
179+
// log the fact there was an error; this function is just a pass through
180+
if err := kubeapi.DeleteSecret(request.Clientset, secretName, request.Namespace); err != nil {
181+
log.Error(err)
182+
}
183+
184+
// and done!
185+
return
186+
}
187+
160188
func removeData(request Request) {
161189
//get the replicas
162190
selector := config.LABEL_PG_CLUSTER + "=" + request.ClusterName + "," + config.LABEL_SERVICE_NAME + "=" + request.ClusterName + "-replica"

0 commit comments

Comments
 (0)