From 185163251d83935cbb29f7aea86cad099c6f9ef8 Mon Sep 17 00:00:00 2001 From: rcerven Date: Tue, 16 Jul 2024 14:14:25 +0200 Subject: [PATCH] Allow simultaneous creation of Component and ImageRepository (#137) if component doesn't exist yet while image-controller trying to get it, fail but don't set state failed, so it acts as transient error and retries STONEBLD-2619 Signed-off-by: Robert Cerven --- controllers/imagerepository_controller.go | 2 -- controllers/imagerepository_controller_test.go | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/controllers/imagerepository_controller.go b/controllers/imagerepository_controller.go index 6a73561..726132c 100644 --- a/controllers/imagerepository_controller.go +++ b/controllers/imagerepository_controller.go @@ -268,14 +268,12 @@ func (r *ImageRepositoryReconciler) ProvisionImageRepository(ctx context.Context componentKey := types.NamespacedName{Namespace: imageRepository.Namespace, Name: componentName} if err := r.Client.Get(ctx, componentKey, component); err != nil { if errors.IsNotFound(err) { - imageRepository.Status.State = imagerepositoryv1alpha1.ImageRepositoryStateFailed imageRepository.Status.Message = fmt.Sprintf("Component '%s' does not exist", componentName) if err := r.Client.Status().Update(ctx, imageRepository); err != nil { log.Error(err, "failed to update imageRepository status", l.Action, l.ActionUpdate) return err } log.Info("attempt to create image repository related to non existing component", "Component", componentName) - return nil } log.Error(err, "failed to get component", "ComponentName", componentName, l.Action, l.ActionView) return err diff --git a/controllers/imagerepository_controller_test.go b/controllers/imagerepository_controller_test.go index c81aed2..69db2da 100644 --- a/controllers/imagerepository_controller_test.go +++ b/controllers/imagerepository_controller_test.go @@ -1175,10 +1175,10 @@ var _ = Describe("Image repository controller", func() { }) defer deleteImageRepository(resourceKey) + errorMessage := fmt.Sprintf("Component '%s' does not exist", defaultComponentName) Eventually(func() bool { imageRepository := getImageRepository(resourceKey) - return imageRepository.Status.State == imagerepositoryv1alpha1.ImageRepositoryStateFailed && - imageRepository.Status.Message != "" + return imageRepository.Status.Message == errorMessage }, timeout, interval).Should(BeTrue()) })