Skip to content

Commit 0a6499f

Browse files
authored
Add tests for package migration/renaming (#3547)
Tests upgrades from one package to another within the same subscription. This is useful when renaming operator package. No new features introduced: this is currently supported by OLM, but there are no tests for this.
1 parent 6056602 commit 0a6499f

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

pkg/controller/registry/resolver/step_resolver_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,30 @@ func TestResolver(t *testing.T) {
732732
},
733733
},
734734
},
735+
{
736+
// Tests the migration from one package name to another with replaces.
737+
// Useful when renaming a package or combining two packages into one.
738+
name: "InstalledSub/UpdateAvailable/FromDifferentPackage",
739+
clusterState: []runtime.Object{
740+
existingSub(namespace, "a.v1", "b", "alpha", catalog),
741+
existingOperator(namespace, "a.v1", "a", "alpha", "", Provides1, nil, nil, nil),
742+
newOperatorGroup("foo", namespace),
743+
},
744+
bundlesByCatalog: map[resolvercache.SourceKey][]*api.Bundle{
745+
catalog: {
746+
bundle("a.v1", "a", "alpha", "", Provides1, nil, nil, nil),
747+
bundle("b.v2", "b", "alpha", "a.v1", Provides1, nil, nil, nil),
748+
},
749+
},
750+
out: resolverTestOut{
751+
steps: [][]*v1alpha1.Step{
752+
bundleSteps(bundle("b.v2", "b", "alpha", "a.v1", Provides1, nil, nil, nil), namespace, "", catalog),
753+
},
754+
subs: []*v1alpha1.Subscription{
755+
updatedSub(namespace, "b.v2", "a.v1", "b", "alpha", catalog),
756+
},
757+
},
758+
},
735759
{
736760
name: "InstalledSub/UpdateAvailable/FromBundlePath",
737761
clusterState: []runtime.Object{

test/e2e/subscription_e2e_test.go

+100
Original file line numberDiff line numberDiff line change
@@ -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

29043004
const (

0 commit comments

Comments
 (0)