Skip to content

Commit 66ea1e1

Browse files
Cleanup Bootstrap Secret When rmdata Runs
When a rmdata Job is run to delete a PG cluster, it will now attempt to remove the pgBackRest bootstrap Secret (if present). This ensures that the bootstrap Secret is properly removed after a failed bootstrap attempt, i.e. when the cluster is deleted and then created again to reattempt creation of the PG cluster. Issue: [ch12505]
1 parent 3940cd2 commit 66ea1e1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cmd/pgo-rmdata/process.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ func Delete(request Request) {
159159
removeBackupSecrets(request)
160160
removeAllBackupPVCs(request)
161161
}
162+
// remove the bootstrap secret if present
163+
removeBootstrapSecret(request)
162164
}
163165

164166
// removeBackRestRepo removes the pgBackRest repo that is associated with the
@@ -219,6 +221,20 @@ func removeBackupSecrets(request Request) {
219221
}
220222
}
221223

224+
// removeBootstrapSecret removes the pgbackrest bootstrap secret. Specifically, if a
225+
// cluster is being deleted after a failed bootstrap attempt using a "pgDataSource", a
226+
// "bootstrap" pgBackRest secret might still be present. Therefore, attempt to remove
227+
// it here, but ignore any "does not exist" errors since it typically will not be present.
228+
func removeBootstrapSecret(request Request) {
229+
ctx := context.TODO()
230+
if err := request.Clientset.CoreV1().Secrets(request.Namespace).Delete(ctx,
231+
fmt.Sprintf(util.BootstrapConfigPrefix, request.ClusterName,
232+
config.LABEL_BACKREST_REPO_SECRET),
233+
metav1.DeleteOptions{}); err != nil && !kerror.IsNotFound(err) {
234+
log.Error(err)
235+
}
236+
}
237+
222238
// removeClusterConfigmaps deletes the configmaps that are created for each
223239
// cluster. The first two are created by Patroni when it initializes a new cluster:
224240
// <cluster-name>-leader (stores data pertinent to the leader election process)

0 commit comments

Comments
 (0)