diff --git a/internal/controllers/core/clustercatalog_controller_test.go b/internal/controllers/core/clustercatalog_controller_test.go index 62cc66ad..86aa8a32 100644 --- a/internal/controllers/core/clustercatalog_controller_test.go +++ b/internal/controllers/core/clustercatalog_controller_test.go @@ -736,6 +736,172 @@ func TestCatalogdControllerReconcile(t *testing.T) { }, }, }, + { + name: "after catalog availability set to enable, finalizer should be added", + source: &MockSource{ + result: &source.Result{ + State: source.StateUnpacked, + FS: &fstest.MapFS{}, + }, + }, + store: &MockStore{}, + catalog: &catalogdv1alpha1.ClusterCatalog{ + ObjectMeta: metav1.ObjectMeta{ + Name: "catalog", + Finalizers: []string{}, + }, + Spec: catalogdv1alpha1.ClusterCatalogSpec{ + Source: catalogdv1alpha1.CatalogSource{ + Type: catalogdv1alpha1.SourceTypeImage, + Image: &catalogdv1alpha1.ImageSource{ + Ref: "my.org/someimage:latest", + }, + }, + Availability: "Enabled", + }, + Status: catalogdv1alpha1.ClusterCatalogStatus{ + URLs: &catalogdv1alpha1.ClusterCatalogURLs{Base: "URL"}, + LastUnpacked: metav1.Time{}, + ResolvedSource: &catalogdv1alpha1.ResolvedCatalogSource{ + Type: catalogdv1alpha1.SourceTypeImage, + Image: &catalogdv1alpha1.ResolvedImageSource{ + Ref: "", + }, + }, + Conditions: []metav1.Condition{ + { + Type: catalogdv1alpha1.TypeServing, + Status: metav1.ConditionFalse, + Reason: catalogdv1alpha1.ReasonUnavailable, + }, + { + Type: catalogdv1alpha1.TypeProgressing, + Status: metav1.ConditionFalse, + Reason: catalogdv1alpha1.ReasonDisabled, + }, + }, + }, + }, + expectedCatalog: &catalogdv1alpha1.ClusterCatalog{ + ObjectMeta: metav1.ObjectMeta{ + Name: "catalog", + Finalizers: []string{fbcDeletionFinalizer}, + }, + Spec: catalogdv1alpha1.ClusterCatalogSpec{ + Source: catalogdv1alpha1.CatalogSource{ + Type: catalogdv1alpha1.SourceTypeImage, + Image: &catalogdv1alpha1.ImageSource{ + Ref: "my.org/someimage:latest", + }, + }, + Availability: "Enabled", + }, + Status: catalogdv1alpha1.ClusterCatalogStatus{ + URLs: &catalogdv1alpha1.ClusterCatalogURLs{Base: "URL"}, + ResolvedSource: &catalogdv1alpha1.ResolvedCatalogSource{ + Type: catalogdv1alpha1.SourceTypeImage, + Image: &catalogdv1alpha1.ResolvedImageSource{ + Ref: "", + }, + }, + Conditions: []metav1.Condition{ + { + Type: catalogdv1alpha1.TypeServing, + Status: metav1.ConditionFalse, + Reason: catalogdv1alpha1.ReasonUnavailable, + }, + { + Type: catalogdv1alpha1.TypeProgressing, + Status: metav1.ConditionFalse, + Reason: catalogdv1alpha1.ReasonDisabled, + }, + }, + }, + }, + }, + { + name: "after catalog availability set to enable and finalizer added, the status should get updated", + source: &MockSource{ + result: &source.Result{ + State: source.StateUnpacked, + FS: &fstest.MapFS{}, + }, + }, + store: &MockStore{}, + catalog: &catalogdv1alpha1.ClusterCatalog{ + ObjectMeta: metav1.ObjectMeta{ + Name: "catalog", + Finalizers: []string{fbcDeletionFinalizer}, + }, + Spec: catalogdv1alpha1.ClusterCatalogSpec{ + Source: catalogdv1alpha1.CatalogSource{ + Type: catalogdv1alpha1.SourceTypeImage, + Image: &catalogdv1alpha1.ImageSource{ + Ref: "my.org/someimage:latest", + }, + }, + Availability: "Enabled", + }, + Status: catalogdv1alpha1.ClusterCatalogStatus{ + URLs: &catalogdv1alpha1.ClusterCatalogURLs{Base: "URL"}, + LastUnpacked: metav1.Time{}, + ResolvedSource: &catalogdv1alpha1.ResolvedCatalogSource{ + Type: catalogdv1alpha1.SourceTypeImage, + Image: &catalogdv1alpha1.ResolvedImageSource{ + Ref: "", + }, + }, + Conditions: []metav1.Condition{ + { + Type: catalogdv1alpha1.TypeServing, + Status: metav1.ConditionFalse, + Reason: catalogdv1alpha1.ReasonUnavailable, + }, + { + Type: catalogdv1alpha1.TypeProgressing, + Status: metav1.ConditionFalse, + Reason: catalogdv1alpha1.ReasonDisabled, + }, + }, + }, + }, + expectedCatalog: &catalogdv1alpha1.ClusterCatalog{ + ObjectMeta: metav1.ObjectMeta{ + Name: "catalog", + Finalizers: []string{fbcDeletionFinalizer}, + }, + Spec: catalogdv1alpha1.ClusterCatalogSpec{ + Source: catalogdv1alpha1.CatalogSource{ + Type: catalogdv1alpha1.SourceTypeImage, + Image: &catalogdv1alpha1.ImageSource{ + Ref: "my.org/someimage:latest", + }, + }, + Availability: "Enabled", + }, + Status: catalogdv1alpha1.ClusterCatalogStatus{ + URLs: &catalogdv1alpha1.ClusterCatalogURLs{Base: "URL"}, + ResolvedSource: &catalogdv1alpha1.ResolvedCatalogSource{ + Type: catalogdv1alpha1.SourceTypeImage, + Image: &catalogdv1alpha1.ResolvedImageSource{ + Ref: "", + }, + }, + Conditions: []metav1.Condition{ + { + Type: catalogdv1alpha1.TypeServing, + Status: metav1.ConditionFalse, + Reason: catalogdv1alpha1.ReasonUnavailable, + }, + { + Type: catalogdv1alpha1.TypeProgressing, + Status: metav1.ConditionFalse, + Reason: catalogdv1alpha1.ReasonDisabled, + }, + }, + }, + }, + }, } { t.Run(tt.name, func(t *testing.T) { reconciler := &ClusterCatalogReconciler{