diff --git a/internal/controllers/clusterextension_controller.go b/internal/controllers/clusterextension_controller.go index af6c67b65..20bfd8837 100644 --- a/internal/controllers/clusterextension_controller.go +++ b/internal/controllers/clusterextension_controller.go @@ -291,6 +291,10 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp // to ensure exponential backoff can occur: // - Permission errors (it is not possible to watch changes to permissions. // The only way to eventually recover from permission errors is to keep retrying). + installedBundle = &InstalledBundle{ + BundleMetadata: resolvedBundleMetadata, + Image: resolvedBundle.Image, + } managedObjs, _, err := r.Applier.Apply(ctx, unpackResult.Bundle, ext, objLbls, storeLbls) if err != nil { setStatusProgressing(ext, wrapErrorWithResolutionInfo(resolvedBundleMetadata, err)) @@ -299,10 +303,6 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp return ctrl.Result{}, err } - installedBundle = &InstalledBundle{ - BundleMetadata: resolvedBundleMetadata, - Image: resolvedBundle.Image, - } // Successful install setInstalledStatusFromBundle(ext, installedBundle, nil) diff --git a/internal/controllers/clusterextension_controller_test.go b/internal/controllers/clusterextension_controller_test.go index a8ea2192b..e4cfa4444 100644 --- a/internal/controllers/clusterextension_controller_test.go +++ b/internal/controllers/clusterextension_controller_test.go @@ -322,7 +322,7 @@ func TestClusterExtensionResolutionAndUnpackSuccessfulApplierFails(t *testing.T) t.Log("By checking the status fields") expectedBundleMetadata := ocv1alpha1.BundleMetadata{Name: "prometheus.v1.0.0", Version: "1.0.0"} - require.Empty(t, clusterExtension.Status.Install) + require.NotEmpty(t, clusterExtension.Status.Install) t.Log("By checking the expected installed conditions") installedCond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1alpha1.TypeInstalled) @@ -428,8 +428,8 @@ func TestClusterExtensionApplierFailsWithBundleInstalled(t *testing.T) { t.Log("By checking the expected installed conditions") installedCond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1alpha1.TypeInstalled) require.NotNil(t, installedCond) - require.Equal(t, metav1.ConditionTrue, installedCond.Status) - require.Equal(t, ocv1alpha1.ReasonSucceeded, installedCond.Reason) + require.Equal(t, metav1.ConditionFalse, installedCond.Status) + require.Equal(t, ocv1alpha1.ReasonFailed, installedCond.Reason) t.Log("By checking the expected progressing conditions") progressingCond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1alpha1.TypeProgressing) diff --git a/internal/controllers/common_controller.go b/internal/controllers/common_controller.go index 2509266ae..a2f529171 100644 --- a/internal/controllers/common_controller.go +++ b/internal/controllers/common_controller.go @@ -35,7 +35,12 @@ func setInstalledStatusFromBundle(ext *ocv1alpha1.ClusterExtension, installedBun Bundle: installedBundle.BundleMetadata, } setInstallStatus(ext, installStatus) - setInstalledStatusConditionSuccess(ext, fmt.Sprintf("Installed bundle %s successfully", installedBundle.Image)) + // If both conditions occur, this is a failed Apply when a bundle was already installed + if err != nil { + setInstalledStatusConditionFailed(ext, err.Error()) + } else { + setInstalledStatusConditionSuccess(ext, fmt.Sprintf("Installed bundle %s successfully", installedBundle.Image)) + } return } // Nothing is installed, if there's no error, it means no installed bundle was found