Skip to content

Commit b851a57

Browse files
committed
test(operatorgroups): add installmode support e2e test
- Add installmode support e2e test - Remove old version of supports logic
1 parent de0586d commit b851a57

File tree

2 files changed

+221
-28
lines changed

2 files changed

+221
-28
lines changed

pkg/api/apis/operators/v1alpha1/clusterserviceversion.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -94,34 +94,6 @@ func NewInstallModeSet(modes []InstallMode) (InstallModeSet, error) {
9494
return set, nil
9595
}
9696

97-
// Supports returns an error if the InstallModeSet does not support configuration for
98-
// the given operatorNamespace and list of target namespaces.
99-
func (set InstallModeSet) SupportsOld(operatorNamespace string, namespaces []string) error {
100-
numNamespaces := len(namespaces)
101-
if !set[InstallModeTypeAllNamespaces] && numNamespaces == 1 && namespaces[0] == v1.NamespaceAll {
102-
return fmt.Errorf("%s InstallModeType not supported, cannot configure to watch all namespaces", InstallModeTypeAllNamespaces)
103-
}
104-
105-
if !set[InstallModeTypeSingleNamespace] && !set[InstallModeTypeMultiNamespace] && numNamespaces == 1 && namespaces[0] != v1.NamespaceAll {
106-
return fmt.Errorf("%s InstallModeType not supported, cannot configure to watch one namespace", InstallModeTypeSingleNamespace)
107-
}
108-
109-
if !set[InstallModeTypeMultiNamespace] && numNamespaces > 1 {
110-
return fmt.Errorf("%s InstallModeType not supported, cannot configure to watch %d namespaces", InstallModeTypeMultiNamespace, numNamespaces)
111-
}
112-
113-
for i, namespace := range namespaces {
114-
if !set[InstallModeTypeOwnNamespace] && namespace == operatorNamespace {
115-
return fmt.Errorf("%s InstallModeType not supported, cannot configure to watch own namespace", InstallModeTypeOwnNamespace)
116-
}
117-
if i > 0 && namespace == v1.NamespaceAll {
118-
return fmt.Errorf("invalid selected namespaces, NamespaceAll found when |selected namespaces| > 1")
119-
}
120-
}
121-
122-
return nil
123-
}
124-
12597
// Supports returns an error if the InstallModeSet does not support configuration for
12698
// the given operatorNamespace and list of target namespaces.
12799
func (set InstallModeSet) Supports(operatorNamespace string, namespaces []string) error {

test/e2e/operator_groups_e2e_test.go

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,227 @@ func TestOperatorGroup(t *testing.T) {
449449
require.NoError(t, err)
450450
}
451451

452+
func TestOperatorGroupInstallModeSupport(t *testing.T) {
453+
// Generate namespaceA
454+
// Generate namespaceB
455+
// Create operatorGroupA in namespaceA that selects namespaceA
456+
// Generate csvA with an unfulfilled required CRD and no supported InstallModes in namespaceA
457+
// Ensure csvA transitions to Failed with reason "UnsupportedOperatorGroup"
458+
// Update csvA to have OwnNamespace supported=true
459+
// Ensure csvA transitions to Pending
460+
// Update operatorGroupA's target namespaces to select namespaceB
461+
// Ensure csvA transitions to Failed with reason "UnsupportedOperatorGroup"
462+
// Update csvA to have SingleNamespace supported=true
463+
// Ensure csvA transitions to Pending
464+
// Update operatorGroupA's target namespaces to select namespaceA and namespaceB
465+
// Ensure csvA transitions to Failed with reason "UnsupportedOperatorGroup"
466+
// Update csvA to have MultiNamespace supported=true
467+
// Ensure csvA transitions to Pending
468+
// Update operatorGroupA to select all namespaces
469+
// Ensure csvA transitions to Failed with reason "UnsupportedOperatorGroup"
470+
// Update csvA to have AllNamespaces supported=true
471+
// Ensure csvA transitions to Pending
472+
473+
// Generate namespaceA and namespaceB
474+
nsA := genName("a")
475+
nsB := genName("b")
476+
477+
c := newKubeClient(t)
478+
for _, ns := range []string{nsA, nsB} {
479+
namespace := &corev1.Namespace{
480+
ObjectMeta: metav1.ObjectMeta{
481+
Name: ns,
482+
},
483+
}
484+
_, err := c.KubernetesInterface().CoreV1().Namespaces().Create(namespace)
485+
require.NoError(t, err)
486+
defer func(name string) {
487+
require.NoError(t, c.KubernetesInterface().CoreV1().Namespaces().Delete(name, &metav1.DeleteOptions{}))
488+
}(ns)
489+
}
490+
491+
// Generate operatorGroupA
492+
crc := newCRClient(t)
493+
groupA := newOperatorGroup(nsA, genName("a"), nil, metav1.LabelSelector{}, []string{nsA}, false)
494+
_, err := crc.OperatorsV1alpha2().OperatorGroups(nsA).Create(groupA)
495+
require.NoError(t, err)
496+
defer func() {
497+
require.NoError(t, crc.OperatorsV1alpha2().OperatorGroups(nsA).Delete(groupA.GetName(), &metav1.DeleteOptions{}))
498+
}()
499+
500+
// Generate csvA in namespaceA with no supported InstallModes
501+
crd := newCRD(genName("b"))
502+
namedStrategy := newNginxInstallStrategy(genName("dep-"), nil, nil)
503+
csv := newCSV("nginx-a", nsA, "", *semver.New("0.1.0"), nil, []apiextensions.CustomResourceDefinition{crd}, namedStrategy)
504+
csvA := &csv
505+
csvA.Spec.InstallModes = []v1alpha1.InstallMode{
506+
{
507+
Type: v1alpha1.InstallModeTypeOwnNamespace,
508+
Supported: false,
509+
},
510+
{
511+
Type: v1alpha1.InstallModeTypeSingleNamespace,
512+
Supported: false,
513+
},
514+
{
515+
Type: v1alpha1.InstallModeTypeMultiNamespace,
516+
Supported: false,
517+
},
518+
{
519+
Type: v1alpha1.InstallModeTypeAllNamespaces,
520+
Supported: false,
521+
},
522+
}
523+
csvA, err = crc.OperatorsV1alpha1().ClusterServiceVersions(nsA).Create(csvA)
524+
require.NoError(t, err)
525+
defer func() {
526+
require.NoError(t, crc.OperatorsV1alpha1().ClusterServiceVersions(nsA).Delete(csvA.GetName(), &metav1.DeleteOptions{}))
527+
}()
528+
529+
// Ensure csvA transitions to Failed with reason "UnsupportedOperatorGroup"
530+
failedWithUnsupportedOperatorGroup := func(csv *v1alpha1.ClusterServiceVersion) bool {
531+
return csvFailedChecker(csv) && csv.Status.Reason == v1alpha1.CSVReasonUnsupportedOperatorGroup
532+
}
533+
csvA, err = fetchCSV(t, crc, csvA.GetName(), nsA, failedWithUnsupportedOperatorGroup)
534+
require.NoError(t, err)
535+
536+
// Update csvA to have OwnNamespace supported=true
537+
csvA.Spec.InstallModes = []v1alpha1.InstallMode{
538+
{
539+
Type: v1alpha1.InstallModeTypeOwnNamespace,
540+
Supported: true,
541+
},
542+
{
543+
Type: v1alpha1.InstallModeTypeSingleNamespace,
544+
Supported: false,
545+
},
546+
{
547+
Type: v1alpha1.InstallModeTypeMultiNamespace,
548+
Supported: false,
549+
},
550+
{
551+
Type: v1alpha1.InstallModeTypeAllNamespaces,
552+
Supported: false,
553+
},
554+
}
555+
_, err = crc.OperatorsV1alpha1().ClusterServiceVersions(nsA).Update(csvA)
556+
require.NoError(t, err)
557+
558+
// Ensure csvA transitions to Pending
559+
csvA, err = fetchCSV(t, crc, csvA.GetName(), nsA, csvPendingChecker)
560+
require.NoError(t, err)
561+
562+
// Update operatorGroupA's target namespaces to select namespaceB
563+
groupA, err = crc.OperatorsV1alpha2().OperatorGroups(nsA).Get(groupA.GetName(), metav1.GetOptions{})
564+
require.NoError(t, err)
565+
groupA.Spec.TargetNamespaces = []string{nsB}
566+
_, err = crc.OperatorsV1alpha2().OperatorGroups(nsA).Update(groupA)
567+
require.NoError(t, err)
568+
569+
// Ensure csvA transitions to Failed with reason "UnsupportedOperatorGroup"
570+
csvA, err = fetchCSV(t, crc, csvA.GetName(), nsA, failedWithUnsupportedOperatorGroup)
571+
require.NoError(t, err)
572+
573+
// Update csvA to have SingleNamespace supported=true
574+
csvA.Spec.InstallModes = []v1alpha1.InstallMode{
575+
{
576+
Type: v1alpha1.InstallModeTypeOwnNamespace,
577+
Supported: true,
578+
},
579+
{
580+
Type: v1alpha1.InstallModeTypeSingleNamespace,
581+
Supported: true,
582+
},
583+
{
584+
Type: v1alpha1.InstallModeTypeMultiNamespace,
585+
Supported: false,
586+
},
587+
{
588+
Type: v1alpha1.InstallModeTypeAllNamespaces,
589+
Supported: false,
590+
},
591+
}
592+
_, err = crc.OperatorsV1alpha1().ClusterServiceVersions(nsA).Update(csvA)
593+
require.NoError(t, err)
594+
595+
// Ensure csvA transitions to Pending
596+
csvA, err = fetchCSV(t, crc, csvA.GetName(), nsA, csvPendingChecker)
597+
require.NoError(t, err)
598+
599+
// Update operatorGroupA's target namespaces to select namespaceA and namespaceB
600+
groupA, err = crc.OperatorsV1alpha2().OperatorGroups(nsA).Get(groupA.GetName(), metav1.GetOptions{})
601+
require.NoError(t, err)
602+
groupA.Spec.TargetNamespaces = []string{nsA, nsB}
603+
_, err = crc.OperatorsV1alpha2().OperatorGroups(nsA).Update(groupA)
604+
require.NoError(t, err)
605+
606+
// Ensure csvA transitions to Failed with reason "UnsupportedOperatorGroup"
607+
csvA, err = fetchCSV(t, crc, csvA.GetName(), nsA, failedWithUnsupportedOperatorGroup)
608+
require.NoError(t, err)
609+
610+
// Update csvA to have MultiNamespace supported=true
611+
csvA.Spec.InstallModes = []v1alpha1.InstallMode{
612+
{
613+
Type: v1alpha1.InstallModeTypeOwnNamespace,
614+
Supported: true,
615+
},
616+
{
617+
Type: v1alpha1.InstallModeTypeSingleNamespace,
618+
Supported: true,
619+
},
620+
{
621+
Type: v1alpha1.InstallModeTypeMultiNamespace,
622+
Supported: true,
623+
},
624+
{
625+
Type: v1alpha1.InstallModeTypeAllNamespaces,
626+
Supported: false,
627+
},
628+
}
629+
_, err = crc.OperatorsV1alpha1().ClusterServiceVersions(nsA).Update(csvA)
630+
require.NoError(t, err)
631+
632+
// Ensure csvA transitions to Pending
633+
csvA, err = fetchCSV(t, crc, csvA.GetName(), nsA, csvPendingChecker)
634+
require.NoError(t, err)
635+
636+
// Update operatorGroupA's target namespaces to select all namespaces
637+
groupA, err = crc.OperatorsV1alpha2().OperatorGroups(nsA).Get(groupA.GetName(), metav1.GetOptions{})
638+
require.NoError(t, err)
639+
groupA.Spec.TargetNamespaces = []string{}
640+
_, err = crc.OperatorsV1alpha2().OperatorGroups(nsA).Update(groupA)
641+
require.NoError(t, err)
642+
643+
// Ensure csvA transitions to Failed with reason "UnsupportedOperatorGroup"
644+
csvA, err = fetchCSV(t, crc, csvA.GetName(), nsA, failedWithUnsupportedOperatorGroup)
645+
require.NoError(t, err)
646+
647+
// Update csvA to have AllNamespaces supported=true
648+
csvA.Spec.InstallModes = []v1alpha1.InstallMode{
649+
{
650+
Type: v1alpha1.InstallModeTypeOwnNamespace,
651+
Supported: true,
652+
},
653+
{
654+
Type: v1alpha1.InstallModeTypeSingleNamespace,
655+
Supported: true,
656+
},
657+
{
658+
Type: v1alpha1.InstallModeTypeMultiNamespace,
659+
Supported: true,
660+
},
661+
{
662+
Type: v1alpha1.InstallModeTypeAllNamespaces,
663+
Supported: true,
664+
},
665+
}
666+
_, err = crc.OperatorsV1alpha1().ClusterServiceVersions(nsA).Update(csvA)
667+
require.NoError(t, err)
668+
669+
// Ensure csvA transitions to Pending
670+
csvA, err = fetchCSV(t, crc, csvA.GetName(), nsA, csvPendingChecker)
671+
require.NoError(t, err)
672+
}
452673

453674
func TestOperatorGroupIntersection(t *testing.T) {
454675
// Generate namespaceA

0 commit comments

Comments
 (0)