Skip to content

Commit bf2de82

Browse files
committed
Add e2e tests for installplan failed on invalid operatorgroups
1 parent 7f91c16 commit bf2de82

File tree

1 file changed

+112
-5
lines changed

1 file changed

+112
-5
lines changed

test/e2e/installplan_e2e_test.go

Lines changed: 112 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,7 +2650,7 @@ var _ = Describe("Install Plan", func() {
26502650
require.Equal(GinkgoT(), 1, len(ips.Items), "If this test fails it should be taken seriously and not treated as a flake. \n%v", ips.Items)
26512651
})
26522652

2653-
It("without an operatorgroup", func() {
2653+
It("should fail an InstallPlan when no operatorgroup is present", func() {
26542654

26552655
log := func(s string) {
26562656
GinkgoT().Logf("%s: %s", time.Now().Format("15:04:05.9999"), s)
@@ -2708,13 +2708,96 @@ var _ = Describe("Install Plan", func() {
27082708

27092709
installPlanName := subscription.Status.InstallPlanRef.Name
27102710

2711-
fetchedInstallPlan, err := fetchInstallPlanWithNamespace(GinkgoT(), crc, installPlanName, ns.GetName(), buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseInstalling))
2711+
fetchedInstallPlan, err := fetchInstallPlanWithNamespace(GinkgoT(), crc, installPlanName, ns.GetName(), buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseFailed))
27122712
require.NoError(GinkgoT(), err)
2713-
log(fmt.Sprintf("Install plan %s fetched with status %s", fetchedInstallPlan.GetName(), fetchedInstallPlan.Status.Phase))
2713+
log(fmt.Sprintf("Install plan %s fetched with phase %s", fetchedInstallPlan.GetName(), fetchedInstallPlan.Status.Phase))
2714+
log(fmt.Sprintf("Install plan %s fetched with conditions %+v", fetchedInstallPlan.GetName(), fetchedInstallPlan.Status.Conditions))
2715+
})
2716+
2717+
It("should fail an InstallPlan when multiple operatorgroups are present", func() {
2718+
2719+
log := func(s string) {
2720+
GinkgoT().Logf("%s: %s", time.Now().Format("15:04:05.9999"), s)
2721+
}
2722+
2723+
ns := &corev1.Namespace{}
2724+
ns.SetName(genName("ns-"))
2725+
2726+
c := newKubeClient()
2727+
crc := newCRClient()
2728+
2729+
// Create a namespace
2730+
ns, err := c.KubernetesInterface().CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{})
2731+
require.NoError(GinkgoT(), err)
2732+
deleteOpts := &metav1.DeleteOptions{}
2733+
defer func() {
2734+
require.NoError(GinkgoT(), c.KubernetesInterface().CoreV1().Namespaces().Delete(context.TODO(), ns.GetName(), *deleteOpts))
2735+
}()
2736+
2737+
mainPackageName := genName("nginx-")
2738+
mainPackageStable := fmt.Sprintf("%s-stable", mainPackageName)
2739+
stableChannel := "stable"
2740+
mainCSV := newCSV(mainPackageStable, ns.GetName(), "", semver.MustParse("0.1.0"), nil, nil, nil)
2741+
2742+
defer func() {
2743+
require.NoError(GinkgoT(), crc.OperatorsV1alpha1().Subscriptions(ns.GetName()).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{}))
2744+
}()
2745+
2746+
mainCatalogName := genName("mock-ocs-main-")
2747+
mainManifests := []registry.PackageManifest{
2748+
{
2749+
PackageName: mainPackageName,
2750+
Channels: []registry.PackageChannel{
2751+
{Name: stableChannel, CurrentCSVName: mainPackageStable},
2752+
},
2753+
DefaultChannelName: stableChannel,
2754+
},
2755+
}
2756+
2757+
// Create the main catalog source
2758+
_, cleanupMainCatalogSource := createInternalCatalogSource(c, crc, mainCatalogName, ns.GetName(), mainManifests, nil, []operatorsv1alpha1.ClusterServiceVersion{mainCSV})
2759+
defer cleanupMainCatalogSource()
2760+
2761+
// Attempt to get the catalog source before creating install plan
2762+
_, err = fetchCatalogSourceOnStatus(crc, mainCatalogName, ns.GetName(), catalogSourceRegistryPodSynced)
2763+
require.NoError(GinkgoT(), err)
2764+
2765+
// Create 2 operatorgroups in the same namespace
2766+
og1 := &operatorsv1.OperatorGroup{
2767+
ObjectMeta: metav1.ObjectMeta{
2768+
Name: "og1",
2769+
},
2770+
Spec: operatorsv1.OperatorGroupSpec{
2771+
TargetNamespaces: []string{ns.GetName()},
2772+
},
2773+
}
2774+
og2 := &operatorsv1.OperatorGroup{
2775+
ObjectMeta: metav1.ObjectMeta{
2776+
Name: "og2",
2777+
},
2778+
Spec: operatorsv1.OperatorGroupSpec{
2779+
TargetNamespaces: []string{ns.GetName()},
2780+
},
2781+
}
2782+
_, err = crc.OperatorsV1().OperatorGroups(ns.GetName()).Create(context.TODO(), og1, metav1.CreateOptions{})
2783+
Expect(err).ToNot(HaveOccurred())
2784+
_, err = crc.OperatorsV1().OperatorGroups(ns.GetName()).Create(context.TODO(), og2, metav1.CreateOptions{})
2785+
Expect(err).ToNot(HaveOccurred())
27142786

2715-
fetchedInstallPlan, err = fetchInstallPlanWithNamespace(GinkgoT(), crc, installPlanName, ns.GetName(), buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseInstalling))
2787+
subscriptionName := genName("sub-nginx-")
2788+
subscriptionCleanup := createSubscriptionForCatalog(crc, ns.GetName(), subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
2789+
defer subscriptionCleanup()
2790+
2791+
subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionHasInstallPlanChecker)
2792+
require.NoError(GinkgoT(), err)
2793+
require.NotNil(GinkgoT(), subscription)
2794+
2795+
installPlanName := subscription.Status.InstallPlanRef.Name
2796+
2797+
fetchedInstallPlan, err := fetchInstallPlanWithNamespace(GinkgoT(), crc, installPlanName, ns.GetName(), buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseFailed))
27162798
require.NoError(GinkgoT(), err)
27172799
log(fmt.Sprintf("Install plan %s fetched with status %s", fetchedInstallPlan.GetName(), fetchedInstallPlan.Status.Phase))
2800+
log(fmt.Sprintf("Install plan %s fetched with conditions %+v", fetchedInstallPlan.GetName(), fetchedInstallPlan.Status.Conditions))
27182801
})
27192802

27202803
It("compresses installplan step resource manifests to configmap references", func() {
@@ -2809,7 +2892,7 @@ var _ = Describe("Install Plan", func() {
28092892
c := newKubeClient()
28102893
crc := newCRClient()
28112894

2812-
By("creating a scoped serviceaccount specifified in the operatorgroup")
2895+
By("creating a scoped serviceaccount specified in the operatorgroup")
28132896
ns, err := c.KubernetesInterface().CoreV1().Namespaces().Create(context.TODO(), &corev1.Namespace{
28142897
ObjectMeta: metav1.ObjectMeta{
28152898
Name: genName("ns-"),
@@ -2873,6 +2956,18 @@ var _ = Describe("Install Plan", func() {
28732956
_, err = crc.OperatorsV1().OperatorGroups(ns.GetName()).Create(context.TODO(), og, metav1.CreateOptions{})
28742957
Expect(err).ToNot(HaveOccurred())
28752958

2959+
// Wait for the OperatorGroup to be synced and have a status.ServiceAccountRef
2960+
// before moving on. Otherwise the catalog operator treats it as an invalid OperatorGroup
2961+
// and fails the InstallPlan
2962+
Eventually(func() (bool, error) {
2963+
outOG, err := crc.OperatorsV1().OperatorGroups(ns.GetName()).Get(context.TODO(), og.Name, metav1.GetOptions{})
2964+
if err != nil {
2965+
return false, err
2966+
}
2967+
fmt.Fprintf(GinkgoWriter, "[DEBUG] Operator Group Status: %+v\n", outOG.Status)
2968+
return outOG.Status.ServiceAccountRef != nil, nil
2969+
}).Should(BeTrue())
2970+
28762971
crd := apiextensionsv1.CustomResourceDefinition{
28772972
ObjectMeta: metav1.ObjectMeta{
28782973
Name: "ins" + ".cluster.com",
@@ -3122,6 +3217,18 @@ var _ = Describe("Install Plan", func() {
31223217
_, err = crc.OperatorsV1().OperatorGroups(ns.GetName()).Create(context.TODO(), og, metav1.CreateOptions{})
31233218
Expect(err).ToNot(HaveOccurred())
31243219

3220+
// Wait for the OperatorGroup to be synced and have a status.ServiceAccountRef
3221+
// before moving on. Otherwise the catalog operator treats it as an invalid OperatorGroup
3222+
// and fails the InstallPlan
3223+
Eventually(func() (bool, error) {
3224+
outOG, err := crc.OperatorsV1().OperatorGroups(ns.GetName()).Get(context.TODO(), og.Name, metav1.GetOptions{})
3225+
if err != nil {
3226+
return false, err
3227+
}
3228+
fmt.Fprintf(GinkgoWriter, "[DEBUG] Operator Group Status: %+v\n", outOG.Status)
3229+
return outOG.Status.ServiceAccountRef != nil, nil
3230+
}).Should(BeTrue())
3231+
31253232
By("using the OLM client to install CRDs from the installplan and the scoped client for other resources")
31263233

31273234
crd := apiextensionsv1.CustomResourceDefinition{

0 commit comments

Comments
 (0)