Skip to content

Commit

Permalink
PTEUDO-2177: verify active db before secret creation
Browse files Browse the repository at this point in the history
  • Loading branch information
bfabricio committed Dec 17, 2024
1 parent b94deca commit 0d7c125
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions pkg/databaseclaim/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (r *DatabaseClaimReconciler) createOrUpdateSecret(ctx context.Context, dbCl
Name: secretName,
}, gs)

if dbClaim.Status.ActiveDB.ConnectionInfo == nil && err == nil {
return fmt.Errorf("secret %s already exists in namespace %s, but no active database connection info is available", secretName, dbClaim.Namespace)
}

if err != nil && errors.IsNotFound(err) {
if err := r.createSecret(ctx, dbClaim, dsn, dsnURI, replicaDsnURI, connInfo); err != nil {
return err
Expand All @@ -59,14 +63,6 @@ func (r *DatabaseClaimReconciler) createSecret(ctx context.Context, dbClaim *v1.
logr := log.FromContext(ctx)
secretName := dbClaim.Spec.SecretName

if dbClaim.Status.ActiveDB.ConnectionInfo == nil {
existingSecret := &corev1.Secret{}
err := r.Client.Get(ctx, client.ObjectKey{Namespace: dbClaim.Namespace, Name: secretName}, existingSecret)
if err == nil {
return fmt.Errorf("secret %s already exists in namespace %s, but no active database connection info is available", secretName, dbClaim.Namespace)
}
}

secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: dbClaim.Namespace,
Expand Down

0 comments on commit 0d7c125

Please sign in to comment.