Skip to content

Commit 7cc8b51

Browse files
committed
e2e: Add assertInstallPlan helper function
Use assertInstallPlan helper function get more insights about failed install plans for the upgrade e2e test.
1 parent d322094 commit 7cc8b51

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

test/e2e/gateway_api_upgrade_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestOSSMOperatorUpgradeViaIntermediateVersions(t *testing.T) {
6969
}
7070

7171
// Installation.
72-
t.Logf("Creating GatewayClass with OSSMversion %q ans Istio version %q...", initialOSSMVersion, initialIstioVersion)
72+
t.Logf("Creating GatewayClass with OSSMversion %q and Istio version %q...", initialOSSMVersion, initialIstioVersion)
7373
gatewayClass := buildGatewayClass("openshift-default", "openshift.io/gateway-controller/v1")
7474
gatewayClass.Annotations = map[string]string{
7575
"unsupported.do-not-use.openshift.io/ossm-catalog": customCatalogSourceName,
@@ -83,6 +83,10 @@ func TestOSSMOperatorUpgradeViaIntermediateVersions(t *testing.T) {
8383
if err := assertSubscription(t, openshiftOperatorsNamespace, expectedSubscriptionName); err != nil {
8484
t.Fatalf("Failed to find expected Subscription %s: %v", expectedSubscriptionName, err)
8585
}
86+
t.Log("Checking for the InstallPlan...")
87+
if err := assertInstallPlan(t, openshiftOperatorsNamespace, initialOSSMVersion); err != nil {
88+
t.Fatalf("Failed to find expected InstallPlan %s: %v", initialOSSMVersion, err)
89+
}
8690
t.Log("Checking for the OSSM operator deployment...")
8791
if err := assertOSSMOperatorWithConfig(t, initialOSSMVersion, 2*time.Second, 2*time.Minute); err != nil {
8892
t.Fatalf("Failed to find expected Istio operator: %v", err)

test/e2e/util_gatewayapi_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,63 @@ func deleteExistingSubscription(t *testing.T, namespace, subName string) error {
640640

641641
}
642642

643+
// assertInstallPlan checks if the InstallPlan with given ClusterServiceVersion exists and installed.
644+
func assertInstallPlan(t *testing.T, namespace, csvName string) error {
645+
t.Helper()
646+
647+
ips := &operatorsv1alpha1.InstallPlanList{}
648+
var ip *operatorsv1alpha1.InstallPlan
649+
ipHasCSV := func(ip operatorsv1alpha1.InstallPlan) bool {
650+
for _, c := range ip.Spec.ClusterServiceVersionNames {
651+
if c == csvName {
652+
return true
653+
}
654+
}
655+
return false
656+
}
657+
658+
err := wait.PollUntilContextTimeout(context.Background(), 2*time.Second, 2*time.Minute, false, func(context context.Context) (bool, error) {
659+
if err := kclient.List(context, ips); err != nil {
660+
t.Logf("Failed to list install plans: %v, retrying...", err)
661+
return false, nil
662+
}
663+
664+
for i := range ips.Items {
665+
if ipHasCSV(ips.Items[i]) {
666+
ip = &ips.Items[i]
667+
break
668+
}
669+
}
670+
671+
if ip == nil {
672+
t.Logf("Failed to find install plan for clusterserviceversion %q, retrying...", csvName)
673+
return false, nil
674+
}
675+
676+
t.Logf("Found install plan %q", ip.Name)
677+
for _, c := range ip.Status.Conditions {
678+
if c.Type == operatorsv1alpha1.InstallPlanInstalled {
679+
if c.Status == corev1.ConditionTrue {
680+
t.Logf("Installed condition is false for install plan %q, retrying...", ip.Name)
681+
return false, nil
682+
}
683+
break
684+
}
685+
}
686+
t.Logf("Install plan %q successfully installed", ip.Name)
687+
return true, nil
688+
})
689+
if err != nil {
690+
if ip != nil {
691+
t.Logf("Last observed state of install plan %q:\n%s", ip.Name, util.ToYaml(ip))
692+
} else {
693+
t.Logf("Last observed state of all install plans:\n%s", util.ToYaml(ips))
694+
}
695+
}
696+
697+
return err
698+
}
699+
643700
// assertOSSMOperator checks if the OSSM operator gets successfully installed
644701
// and returns an error if not. It uses configurable parameters such as the expected OSSM version, polling interval, and timeout.
645702
func assertOSSMOperator(t *testing.T) error {

0 commit comments

Comments
 (0)