@@ -2899,6 +2899,106 @@ properties:
28992899 }).Should (Succeed ())
29002900 })
29012901 })
2902+
2903+ It ("should support switching from one package to another" , func () {
2904+ kubeClient := ctx .Ctx ().KubeClient ()
2905+ crClient := ctx .Ctx ().OperatorClient ()
2906+
2907+ // Create CRDs for testing.
2908+ // Both packages share the same CRD.
2909+ crd := newCRD (genName ("package1-crd" ))
2910+
2911+ // Create two packages
2912+ packageName1 := "package1"
2913+ packageName2 := "package2"
2914+
2915+ // Create CSVs for each package
2916+ csvPackage1 := newCSV ("package1.v1.0.0" , generatedNamespace .GetName (), "" , semver .MustParse ("1.0.0" ), []apiextensionsv1.CustomResourceDefinition {crd }, nil , nil )
2917+ csvPackage2 := newCSV ("package2.v1.0.0" , generatedNamespace .GetName (), "package1.v1.0.0" , semver .MustParse ("1.0.0" ), []apiextensionsv1.CustomResourceDefinition {crd }, nil , nil )
2918+
2919+ // Create package manifests
2920+ manifests := []registry.PackageManifest {
2921+ {
2922+ PackageName : packageName1 ,
2923+ Channels : []registry.PackageChannel {
2924+ {Name : stableChannel , CurrentCSVName : csvPackage1 .GetName ()},
2925+ },
2926+ DefaultChannelName : stableChannel ,
2927+ },
2928+ {
2929+ PackageName : packageName2 ,
2930+ Channels : []registry.PackageChannel {
2931+ {Name : stableChannel , CurrentCSVName : csvPackage2 .GetName ()},
2932+ },
2933+ DefaultChannelName : stableChannel ,
2934+ },
2935+ }
2936+
2937+ By ("Creating a CatalogSource with both packages" )
2938+ catalogSourceName := genName ("catalog-" )
2939+ catsrc , cleanup := createInternalCatalogSource (kubeClient , crClient , catalogSourceName ,
2940+ generatedNamespace .GetName (), manifests ,
2941+ []apiextensionsv1.CustomResourceDefinition {crd },
2942+ []operatorsv1alpha1.ClusterServiceVersion {csvPackage1 , csvPackage2 })
2943+ defer cleanup ()
2944+
2945+ By ("Waiting for the catalog source to be ready" )
2946+ _ , err := fetchCatalogSourceOnStatus (crClient , catsrc .GetName (), generatedNamespace .GetName (), catalogSourceRegistryPodSynced ())
2947+ Expect (err ).NotTo (HaveOccurred ())
2948+
2949+ subscriptionName := genName ("test-subscription-" )
2950+ By (fmt .Sprintf ("Creating a subscription to package %q" , packageName1 ))
2951+ subscriptionSpec := & operatorsv1alpha1.SubscriptionSpec {
2952+ CatalogSource : catsrc .GetName (),
2953+ CatalogSourceNamespace : catsrc .GetNamespace (),
2954+ Package : packageName1 ,
2955+ Channel : stableChannel ,
2956+ InstallPlanApproval : operatorsv1alpha1 .ApprovalAutomatic ,
2957+ }
2958+
2959+ cleanupSubscription := createSubscriptionForCatalogWithSpec (GinkgoT (), crClient ,
2960+ generatedNamespace .GetName (), subscriptionName , subscriptionSpec )
2961+ defer cleanupSubscription ()
2962+
2963+ By (fmt .Sprintf ("Waiting for package %q to be installed" , packageName1 ))
2964+ sub , err := fetchSubscription (crClient , generatedNamespace .GetName (), subscriptionName , subscriptionStateAtLatestChecker ())
2965+ Expect (err ).NotTo (HaveOccurred ())
2966+ Expect (sub ).NotTo (BeNil ())
2967+
2968+ By (fmt .Sprintf ("Verifying that CSV %q is installed" , csvPackage1 .GetName ()))
2969+ _ , err = fetchCSV (crClient , generatedNamespace .GetName (), csvPackage1 .GetName (), csvSucceededChecker )
2970+ Expect (err ).NotTo (HaveOccurred ())
2971+
2972+ // Record the current installplan for later comparison
2973+ currentInstallPlanName := sub .Status .InstallPlanRef .Name
2974+
2975+ By (fmt .Sprintf ("Updating the subscription to point to package %q" , packageName2 ))
2976+ Eventually (func () error {
2977+ subToUpdate , err := crClient .OperatorsV1alpha1 ().Subscriptions (generatedNamespace .GetName ()).Get (context .Background (), subscriptionName , metav1.GetOptions {})
2978+ if err != nil {
2979+ return err
2980+ }
2981+
2982+ // Switch the package in the subscription spec
2983+ subToUpdate .Spec .Package = packageName2
2984+
2985+ // Update the subscription
2986+ _ , err = crClient .OperatorsV1alpha1 ().Subscriptions (generatedNamespace .GetName ()).Update (context .Background (), subToUpdate , metav1.UpdateOptions {})
2987+ return err
2988+ }).Should (Succeed ())
2989+
2990+ By ("Waiting for a new installplan to be created for the updated subscription" )
2991+ _ , err = fetchSubscription (crClient , generatedNamespace .GetName (), subscriptionName , subscriptionHasInstallPlanDifferentChecker (currentInstallPlanName ))
2992+ Expect (err ).NotTo (HaveOccurred ())
2993+
2994+ By (fmt .Sprintf ("Waiting for subscription to reach 'AtLatestKnown' state for package %q" , packageName2 ))
2995+ _ , err = fetchSubscription (crClient , generatedNamespace .GetName (), subscriptionName , subscriptionStateAtLatestChecker ())
2996+ Expect (err ).NotTo (HaveOccurred ())
2997+
2998+ By (fmt .Sprintf ("Verifying that CSV %q is installed" , csvPackage2 .GetName ()))
2999+ _ , err = fetchCSV (crClient , generatedNamespace .GetName (), csvPackage2 .GetName (), csvSucceededChecker )
3000+ Expect (err ).NotTo (HaveOccurred ())
3001+ })
29023002})
29033003
29043004const (
0 commit comments