Skip to content

Commit

Permalink
fix created by and pointor (#47)
Browse files Browse the repository at this point in the history
Co-authored-by: Lemaitre Jacques <R9OH5F@ad.insee.intra>
  • Loading branch information
JackLemaitre and Lemaitre Jacques authored Jul 26, 2024
1 parent ccd36fa commit 78ab524
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions controllers/user_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func handleReconcileS3User(ctx context.Context, err error, r *S3UserReconciler,
uiid := userResource.GetUID()
secretNameFromUser := userResource.Spec.SecretName

err = r.List(ctx, secretsList, client.InNamespace(userResource.Namespace), client.MatchingLabels{"app.kubernetes.io/created-by": "s3-operator"}) // Use r.Client.List instead of r.List
err = r.List(ctx, secretsList, client.InNamespace(userResource.Namespace))

if err != nil && (errors.IsNotFound(err) || len(secretsList.Items) == 0) {
logger.Info("Secret associated to user not found, user will be deleted and recreated", "user", userResource.Name)
Expand All @@ -150,8 +150,9 @@ func handleReconcileS3User(ctx context.Context, err error, r *S3UserReconciler,
fmt.Sprintf("Cannot locate k8s secrets [%s]", userResource.Name), err)
}

secretToTest := &corev1.Secret{}
secretToTest := corev1.Secret{}
for _, secret := range secretsList.Items {

for _, ref := range secret.OwnerReferences {
if ref.UID == uiid {
// i do have a spec.secretName i compar with the secret Name
Expand All @@ -160,15 +161,15 @@ func handleReconcileS3User(ctx context.Context, err error, r *S3UserReconciler,
deleteSecret(ctx, r, secret, logger)
} else {
logger.Info("A secret named after the userResource.Spec.SecretName was found " + secret.Name)
secretToTest = &secret
secretToTest = secret
}
// else old case i dont have a spec.SecretName i compar with the s3user.name
} else {
if secret.Name != userResource.Name {
deleteSecret(ctx, r, secret, logger)
} else {
logger.Info("A secret named after the userResource.Spec.SecretName was found " + secret.Name)
secretToTest = &secret
logger.Info("A secret named after the userResource.name was found " + secret.Name)
secretToTest = secret
}
}
}
Expand Down

0 comments on commit 78ab524

Please sign in to comment.