@@ -495,39 +495,45 @@ func deleteExistingSubscription(t *testing.T, namespace, subName string) error {
495495
496496}
497497
498- // assertOSSMOperator checks if the OSSM Istio operator gets successfully installed
499- // and returns an error if not.
498+ // assertOSSMOperator checks if the OSSM operator gets successfully installed
499+ // and returns an error if not. It uses configurable parameters such as the expected OSSM version, polling interval, and timeout.
500500func assertOSSMOperator (t * testing.T ) error {
501+ return assertOSSMOperatorWithConfig (t , "" , 1 * time .Second , 30 * time .Second )
502+ }
503+
504+ // assertOSSMOperatorWithConfig checks if the OSSM operator gets successfully installed
505+ // and returns an error if not. It uses configurable parameters such as
506+ // the expected OSSM version, polling interval, and timeout.
507+ func assertOSSMOperatorWithConfig (t * testing.T , version string , interval , timeout time.Duration ) error {
501508 t .Helper ()
502509 dep := & appsv1.Deployment {}
503510 ns := types.NamespacedName {Namespace : openshiftOperatorsNamespace , Name : openshiftIstioOperatorDeploymentName }
504511
505- // Get the Istio operator deployment.
506- err := wait .PollUntilContextTimeout (context .Background (), 1 * time . Second , 30 * time . Second , false , func (context context.Context ) (bool , error ) {
512+ // Get the OSSM operator deployment.
513+ if err := wait .PollUntilContextTimeout (context .Background (), interval , timeout , false , func (context context.Context ) (bool , error ) {
507514 if err := kclient .Get (context , ns , dep ); err != nil {
508515 t .Logf ("failed to get deployment %v, retrying..." , ns )
509516 return false , nil
510517 }
518+ if len (version ) > 0 {
519+ if csv , found := dep .Labels ["olm.owner" ]; found {
520+ if csv == version {
521+ t .Logf ("Found OSSM deployment %q with expected version %q" , ns , version )
522+ } else {
523+ t .Logf ("OSSM deployment %q expected to have version %q but got %q, retrying..." , ns , version , csv )
524+ return false , nil
525+ }
526+ }
527+ }
528+ if dep .Status .AvailableReplicas < * dep .Spec .Replicas {
529+ t .Logf ("OSSM deployment %q expected to have %d available replica(s) but got %d, retrying..." , ns , * dep .Spec .Replicas , dep .Status .AvailableReplicas )
530+ return false , nil
531+ }
532+ t .Logf ("found OSSM operator deployment %q with %d available replica(s)" , ns , dep .Status .AvailableReplicas )
511533 return true , nil
512- })
513- if err != nil {
534+ }); err != nil {
514535 return fmt .Errorf ("error finding deployment %v: %v" , ns , err )
515536 }
516-
517- // Get the istio-operator pod.
518- podlist , err := getPods (t , kclient , dep )
519- if err != nil {
520- return fmt .Errorf ("error finding pod for deployment %v: %v" , ns , err )
521- }
522- if len (podlist .Items ) > 1 {
523- return fmt .Errorf ("too many pods for deployment %v: %d" , ns , len (podlist .Items ))
524- }
525- pod := podlist .Items [0 ]
526- if pod .Status .Phase != corev1 .PodRunning {
527- return fmt .Errorf ("OSSM operator failure: pod %s is not running, it is %v" , pod .Name , pod .Status .Phase )
528- }
529-
530- t .Logf ("found OSSM operator pod %s/%s to be %s" , pod .Namespace , pod .Name , pod .Status .Phase )
531537 return nil
532538}
533539
@@ -963,6 +969,13 @@ func assertCatalogSource(t *testing.T, namespace, csName string) error {
963969// assertIstio checks if the Istio exists in a ready state,
964970// and returns an error if not.
965971func assertIstio (t * testing.T ) error {
972+ return assertIstioWithConfig (t , "" )
973+ }
974+
975+ // assertIstio checks if the Istio exists in a ready state,
976+ // and returns an error if not.It uses configurable parameters such as
977+ // the expected version.
978+ func assertIstioWithConfig (t * testing.T , version string ) error {
966979 t .Helper ()
967980 istio := & sailv1.Istio {}
968981 nsName := types.NamespacedName {Namespace : operatorcontroller .DefaultOperandNamespace , Name : openshiftIstioName }
@@ -972,6 +985,14 @@ func assertIstio(t *testing.T) error {
972985 t .Logf ("Failed to get Istio %s/%s: %v. Retrying..." , nsName .Namespace , nsName .Name , err )
973986 return false , nil
974987 }
988+ if len (version ) > 0 {
989+ if version == istio .Spec .Version {
990+ t .Logf ("Found Istio %s/%s with expected version %q" , istio .Namespace , istio .Name , version )
991+ } else {
992+ t .Logf ("Istio %s/%s expected to have version %q but got %q, retrying..." , istio .Namespace , istio .Name , version , istio .Spec .Version )
993+ return false , nil
994+ }
995+ }
975996 if istio .Status .GetCondition (sailv1 .IstioConditionReady ).Status == metav1 .ConditionTrue {
976997 t .Logf ("Found Istio %s/%s, and it reports ready" , istio .Namespace , istio .Name )
977998 return true , nil
0 commit comments