@@ -18,6 +18,7 @@ import (
18
18
k8serrors "k8s.io/apimachinery/pkg/api/errors"
19
19
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20
20
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
21
+ "k8s.io/apimachinery/pkg/types"
21
22
"k8s.io/apimachinery/pkg/util/wait"
22
23
"k8s.io/apimachinery/pkg/watch"
23
24
"k8s.io/kubernetes/pkg/apis/rbac"
@@ -106,6 +107,22 @@ func fetchInstallPlanWithNamespace(t *testing.T, c versioned.Interface, name str
106
107
return fetchedInstallPlan , err
107
108
}
108
109
110
+ // do not return an error if the installplan has not been created yet
111
+ func waitForInstallPlan (t * testing.T , c versioned.Interface , name string , namespace string , checkPhase checkInstallPlanFunc ) (* v1alpha1.InstallPlan , error ) {
112
+ var fetchedInstallPlan * v1alpha1.InstallPlan
113
+ var err error
114
+
115
+ err = wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
116
+ fetchedInstallPlan , err = c .OperatorsV1alpha1 ().InstallPlans (namespace ).Get (name , metav1.GetOptions {})
117
+ if err != nil && ! k8serrors .IsNotFound (err ) {
118
+ return false , err
119
+ }
120
+
121
+ return checkPhase (fetchedInstallPlan ), nil
122
+ })
123
+ return fetchedInstallPlan , err
124
+ }
125
+
109
126
func newNginxInstallStrategy (name string , permissions []v1alpha1.StrategyDeploymentPermissions , clusterPermissions []v1alpha1.StrategyDeploymentPermissions ) v1alpha1.NamedInstallStrategy {
110
127
// Create an nginx details deployment
111
128
details := v1alpha1.StrategyDetailsDeployment {
@@ -2552,3 +2569,135 @@ func TestInstallPlanCRDValidation(t *testing.T) {
2552
2569
2553
2570
require .Equal (t , v1alpha1 .InstallPlanPhaseComplete , fetchedInstallPlan .Status .Phase )
2554
2571
}
2572
+
2573
+ func TestInstallPlanFromBundleImage (t * testing.T ) {
2574
+ defer cleaner .NotifyTestComplete (t , true )
2575
+ c := newKubeClient (t )
2576
+ crc := newCRClient (t )
2577
+ catalogSourceName := genName ("mock-kiali-" )
2578
+
2579
+ // expect to execute in the same namespace OLM is operating in
2580
+ testNamespace := strings .TrimSuffix (testNamespace , "-operator" )
2581
+
2582
+ // add RBAC for e2e namespace
2583
+ rbacRole := & rbacv1.Role {
2584
+ ObjectMeta : metav1.ObjectMeta {
2585
+ Name : "olm-e2e-configmap-access" ,
2586
+ Namespace : testNamespace ,
2587
+ },
2588
+ Rules : []rbacv1.PolicyRule {
2589
+ {
2590
+ APIGroups : []string {
2591
+ "" ,
2592
+ },
2593
+ Verbs : []string {
2594
+ "create" , "get" , "update" ,
2595
+ },
2596
+ Resources : []string {
2597
+ "configmaps" ,
2598
+ },
2599
+ },
2600
+ },
2601
+ }
2602
+ _ , err := c .KubernetesInterface ().RbacV1 ().Roles (testNamespace ).Create (rbacRole )
2603
+ require .NoError (t , err )
2604
+ defer func () {
2605
+ require .NoError (t , c .KubernetesInterface ().RbacV1 ().Roles (testNamespace ).Delete (rbacRole .GetName (), & metav1.DeleteOptions {}))
2606
+ }()
2607
+
2608
+ rbacBinding := & rbacv1.RoleBinding {
2609
+ ObjectMeta : metav1.ObjectMeta {
2610
+ Name : "olm-e2e-configmap-access-binding" ,
2611
+ Namespace : testNamespace ,
2612
+ },
2613
+ Subjects : []rbacv1.Subject {
2614
+ {
2615
+ Kind : "ServiceAccount" ,
2616
+ APIGroup : "" ,
2617
+ Name : "default" ,
2618
+ Namespace : testNamespace ,
2619
+ },
2620
+ },
2621
+ RoleRef : rbacv1.RoleRef {
2622
+ APIGroup : "rbac.authorization.k8s.io" ,
2623
+ Kind : "Role" ,
2624
+ Name : rbacRole .GetName (),
2625
+ },
2626
+ }
2627
+ _ , err = c .KubernetesInterface ().RbacV1 ().RoleBindings (testNamespace ).Create (rbacBinding )
2628
+ require .NoError (t , err )
2629
+ defer func () {
2630
+ require .NoError (t , c .KubernetesInterface ().RbacV1 ().RoleBindings (testNamespace ).Delete (rbacBinding .GetName (), & metav1.DeleteOptions {}))
2631
+ }()
2632
+
2633
+ grpcCatalogSource := & v1alpha1.CatalogSource {
2634
+ ObjectMeta : metav1.ObjectMeta {
2635
+ Name : catalogSourceName ,
2636
+ Namespace : testNamespace ,
2637
+ UID : types .UID ("catalog-uid" ),
2638
+ Labels : map [string ]string {"olm.catalogSource" : "kaili-catalog" },
2639
+ },
2640
+ Spec : v1alpha1.CatalogSourceSpec {
2641
+ Image : "quay.io/jpeeler/registry-image:latest" ,
2642
+ SourceType : v1alpha1 .SourceTypeGrpc ,
2643
+ },
2644
+ }
2645
+ _ , err = crc .OperatorsV1alpha1 ().CatalogSources (testNamespace ).Create (grpcCatalogSource )
2646
+ require .NoError (t , err )
2647
+ defer func () {
2648
+ require .NoError (t , crc .OperatorsV1alpha1 ().CatalogSources (testNamespace ).Delete (grpcCatalogSource .GetName (), & metav1.DeleteOptions {}))
2649
+ }()
2650
+
2651
+ // wait for catalog source to be ready
2652
+ _ , err = fetchCatalogSource (t , crc , catalogSourceName , testNamespace , catalogSourceRegistryPodSynced )
2653
+ require .NoError (t , err )
2654
+
2655
+ // generate subscription
2656
+ subscriptionName := genName ("sub-kiali-" )
2657
+ cleanupSubscription := createSubscriptionForCatalog (t , crc , testNamespace , subscriptionName , catalogSourceName , "kiali" , stableChannel , "" , v1alpha1 .ApprovalAutomatic )
2658
+ defer cleanupSubscription ()
2659
+
2660
+ subscription , err := fetchSubscription (t , crc , testNamespace , subscriptionName , subscriptionHasInstallPlanChecker )
2661
+ require .NoError (t , err )
2662
+ require .NotNil (t , subscription )
2663
+ installPlanName := subscription .Status .InstallPlanRef .Name
2664
+
2665
+ // get InstallPlan
2666
+ fetchedInstallPlan , err := waitForInstallPlan (t , crc , installPlanName , testNamespace , buildInstallPlanPhaseCheckFunc (v1alpha1 .InstallPlanPhaseFailed , v1alpha1 .InstallPlanPhaseComplete ))
2667
+ require .NoError (t , err )
2668
+ require .NotEqual (t , v1alpha1 .InstallPlanPhaseFailed , fetchedInstallPlan .Status .Phase , "InstallPlan failed" )
2669
+
2670
+ // verify steps
2671
+ operatorName := "kiali-operator"
2672
+ expectedSteps := map [registry.ResourceKey ]struct {}{
2673
+ registry.ResourceKey {Name : operatorName , Kind : "ClusterServiceVersion" }: {},
2674
+ registry.ResourceKey {Name : "kialis.kiali.io" , Kind : "CustomResourceDefinition" }: {},
2675
+ registry.ResourceKey {Name : "monitoringdashboards.monitoring.kiali.io" , Kind : "CustomResourceDefinition" }: {},
2676
+ registry.ResourceKey {Name : operatorName , Kind : "ServiceAccount" }: {},
2677
+ registry.ResourceKey {Name : operatorName , Kind : "ClusterRole" }: {},
2678
+ registry.ResourceKey {Name : operatorName , Kind : "ClusterRoleBinding" }: {},
2679
+ }
2680
+
2681
+ require .Equal (t , len (expectedSteps ), len (fetchedInstallPlan .Status .Plan ), "number of expected steps does not match installed: %v" , fetchedInstallPlan .Status .Plan )
2682
+
2683
+ for _ , step := range fetchedInstallPlan .Status .Plan {
2684
+ key := registry.ResourceKey {
2685
+ Name : step .Resource .Name ,
2686
+ Kind : step .Resource .Kind ,
2687
+ }
2688
+ for expected := range expectedSteps {
2689
+ if strings .HasPrefix (key .Name , expected .Name ) && key .Kind == expected .Kind {
2690
+ delete (expectedSteps , expected )
2691
+ } else {
2692
+ t .Logf ("%v, %v: %v && %v" , key , expected , strings .HasPrefix (key .Name , expected .Name ), key .Kind == expected .Kind )
2693
+ }
2694
+ }
2695
+ }
2696
+ require .Equal (t , 0 , len (expectedSteps ), "Actual resource steps do not match expected: %#v" , expectedSteps )
2697
+
2698
+ // check CSV installed successfully
2699
+ csvName := "kiali-operator.v1.4.2"
2700
+ _ , err = fetchCSV (t , crc , csvName , testNamespace , csvSucceededChecker )
2701
+ require .NoError (t , err )
2702
+ require .NoError (t , crc .OperatorsV1alpha1 ().ClusterServiceVersions (testNamespace ).Delete (csvName , & metav1.DeleteOptions {}))
2703
+ }
0 commit comments