Skip to content

Commit

Permalink
style: Fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyno-zeta committed Feb 22, 2024
1 parent 0547649 commit 8567c44
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 8 additions & 4 deletions internal/controller/postgresql/postgresqluser_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,18 @@ func (r *PostgresqlUserReconciler) Reconcile(ctx context.Context, req ctrl.Reque
// Update status
instance.Status.LastPasswordChangedTime = time.Now().Format(time.RFC3339)
} else if !r.isSecretValid(secrFound, generatedSecret) { // Check if secret must be updated because invalid
// Update password in pg
reqLogger.Info("Updating password in Postgresql Engine")
// Update password in pg
err = pgInstance.UpdatePassword(role, password)
// Check error
if err != nil {
return r.manageError(ctx, reqLogger, instance, originalPatch, err)
}

// Need to update secret
reqLogger.Info("Updating secret because secret has changed", "Secret.Namespace", generatedSecret.Namespace, "Secret.Name", generatedSecret.Name)
// Need to update secret
err = r.updatePGUserSecret(ctx, secrFound, generatedSecret)
// Check error
if err != nil {
return r.manageError(ctx, reqLogger, instance, originalPatch, err)
}
Expand All @@ -295,22 +297,24 @@ func (r *PostgresqlUserReconciler) Reconcile(ctx context.Context, req ctrl.Reque
// Check if is time to change
now := time.Now()
lastChange, err := time.Parse(time.RFC3339, instance.Status.LastPasswordChangedTime)
// Check error
if err != nil {
return r.manageError(ctx, reqLogger, instance, originalPatch, err)
}

if now.Sub(lastChange) >= dur {
// Need to change password

// Update password in pg
reqLogger.Info("Updating password in Postgresql Engine")
// Update password in pg
err = pgInstance.UpdatePassword(role, password)
// Check error
if err != nil {
return r.manageError(ctx, reqLogger, instance, originalPatch, err)
}
// Need to update secret
reqLogger.Info("Updating secret", "Secret.Namespace", generatedSecret.Namespace, "Secret.Name", generatedSecret.Name)
err = r.updatePGUserSecret(ctx, secrFound, generatedSecret)
// Check error
if err != nil {
return r.manageError(ctx, reqLogger, instance, originalPatch, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,6 @@ func (r *PostgresqlUserRoleReconciler) createOrUpdateWorkSecretForManagedMode( /
string(workSec.Data[UsernameSecretKey]) == "" ||
string(workSec.Data[PasswordSecretKey]) == "" { // Check if role have been changed or if work secret have been edited
// Need to perform changes

// Update flags
passwordChanged = true
oldUsername = string(workSec.Data[UsernameSecretKey])
Expand Down Expand Up @@ -802,7 +801,6 @@ func (r *PostgresqlUserRoleReconciler) createOrUpdateWorkSecretForManagedMode( /

if now.Sub(lastChange) >= dur {
// Need to change username/password with a new one

// Get old username
oldUsername = string(workSec.Data[UsernameSecretKey])
// Prepare data
Expand Down Expand Up @@ -1173,7 +1171,6 @@ func (r *PostgresqlUserRoleReconciler) validateInstance(
}
} else {
// Validate Managed one

// Must have a role prefix
if instance.Spec.RolePrefix == "" {
return errors.NewBadRequest("PostgresqlUserRole is in managed mode without any RolePrefix")
Expand Down

0 comments on commit 8567c44

Please sign in to comment.