@@ -326,6 +326,19 @@ func subscriptionHasCurrentCSV(currentCSV string) subscriptionStateChecker {
326
326
}
327
327
}
328
328
329
+ func subscriptionHasCondition (condType v1alpha1.SubscriptionConditionType , status corev1.ConditionStatus , reason , message string ) subscriptionStateChecker {
330
+ return func (subscription * v1alpha1.Subscription ) bool {
331
+ cond := subscription .Status .GetCondition (condType )
332
+ if cond .Status == status && cond .Reason == reason && cond .Message == message {
333
+ fmt .Printf ("subscription condition met %v\n " , cond )
334
+ return true
335
+ }
336
+
337
+ fmt .Printf ("subscription condition not met: %v\n " , cond )
338
+ return false
339
+ }
340
+ }
341
+
329
342
func fetchSubscription (t * testing.T , crc versioned.Interface , namespace , name string , checker subscriptionStateChecker ) (* v1alpha1.Subscription , error ) {
330
343
var fetchedSubscription * v1alpha1.Subscription
331
344
var err error
@@ -842,6 +855,48 @@ func TestSubscriptionUpdatesMultipleIntermediates(t *testing.T) {
842
855
// TODO: check installplans, subscription status, etc
843
856
}
844
857
858
+ // TestSubscriptionStatusMissingTargetCatalogSource ensures that a Subscription has the appropriate status condition when
859
+ // its target catalog is missing.
860
+ //
861
+ // Steps:
862
+ // 1. Generate an initial CatalogSource in the target namespace
863
+ // 2. Generate Subscription, "sub", targetting non-existent CatalogSource, "missing"
864
+ // 3. Wait for sub status to show SubscriptionCatalogSourcesUnhealthy with status True, reason CatalogSourcesUpdated, and appropriate missing message
865
+ // 4. Update sub's spec to target the "mysubscription"
866
+ // 5. Wait for sub's status to show SubscriptionCatalogSourcesUnhealthy with status False, reason AllCatalogSourcesHealthy, and reason "all available catalogsources are healthy"
867
+ // 6. Wait for sub to succeed
868
+ func TestSubscriptionStatusMissingTargetCatalogSource (t * testing.T ) {
869
+ defer cleaner .NotifyTestComplete (t , true )
870
+
871
+ c := newKubeClient (t )
872
+ crc := newCRClient (t )
873
+ defer func () {
874
+ require .NoError (t , crc .OperatorsV1alpha1 ().Subscriptions (testNamespace ).DeleteCollection (& metav1.DeleteOptions {}, metav1.ListOptions {}))
875
+ }()
876
+ require .NoError (t , initCatalog (t , c , crc ))
877
+
878
+ missingName := "missing"
879
+ cleanup := createSubscriptionForCatalog (t , crc , testNamespace , testSubscriptionName , missingName , testPackageName , betaChannel , "" , v1alpha1 .ApprovalAutomatic )
880
+ defer cleanup ()
881
+
882
+ sub , err := fetchSubscription (t , crc , testNamespace , testSubscriptionName , subscriptionHasCondition (v1alpha1 .SubscriptionCatalogSourcesUnhealthy , corev1 .ConditionTrue , v1alpha1 .UnhealthyCatalogSourceFound , fmt .Sprintf ("targeted catalogsource %s/%s missing" , testNamespace , missingName )))
883
+ require .NoError (t , err )
884
+ require .NotNil (t , sub )
885
+
886
+ // Update sub to target an existing CatalogSource
887
+ sub .Spec .CatalogSource = catalogSourceName
888
+ _ , err = crc .OperatorsV1alpha1 ().Subscriptions (testNamespace ).Update (sub )
889
+ require .NoError (t , err )
890
+
891
+ // Wait for SubscriptionCatalogSourcesUnhealthy to be false
892
+ _ , err = fetchSubscription (t , crc , testNamespace , testSubscriptionName , subscriptionHasCondition (v1alpha1 .SubscriptionCatalogSourcesUnhealthy , corev1 .ConditionFalse , v1alpha1 .AllCatalogSourcesHealthy , "all available catalogsources are healthy" ))
893
+ require .NoError (t , err )
894
+
895
+ // Wait for success
896
+ _ , err = fetchSubscription (t , crc , testNamespace , testSubscriptionName , subscriptionStateAtLatestChecker )
897
+ require .NoError (t , err )
898
+ }
899
+
845
900
func updateInternalCatalog (t * testing.T , c operatorclient.ClientInterface , crc versioned.Interface , catalogSourceName , namespace string , crds []apiextensions.CustomResourceDefinition , csvs []v1alpha1.ClusterServiceVersion , packages []registry.PackageManifest ) {
846
901
fetchedInitialCatalog , err := fetchCatalogSource (t , crc , catalogSourceName , namespace , catalogSourceRegistryPodSynced )
847
902
require .NoError (t , err )
0 commit comments