Skip to content

Commit

Permalink
Allow simultaneous creation of Component and ImageRepository
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rcerven committed Jul 12, 2024
1 parent e138500 commit 82d7892
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 0 additions & 2 deletions controllers/imagerepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions controllers/imagerepository_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})

Expand Down

0 comments on commit 82d7892

Please sign in to comment.