diff --git a/integration-tests/backend/flowcollector.go b/integration-tests/backend/flowcollector.go index c5c14c72e7..2bcc16f8b0 100644 --- a/integration-tests/backend/flowcollector.go +++ b/integration-tests/backend/flowcollector.go @@ -9,6 +9,7 @@ import ( exutil "github.com/openshift/origin/test/extended/util" compat_otp "github.com/openshift/origin/test/extended/util/compat_otp" + "golang.org/x/mod/semver" "k8s.io/apimachinery/pkg/util/wait" e2e "k8s.io/kubernetes/test/e2e/framework" @@ -209,8 +210,15 @@ func (flow *Flowcollector) WaitForFlowcollectorReady(oc *exutil.CLI) { default: waitUntilDeploymentReady(oc, "flowlogs-pipeline", flow.Namespace) } - // check informers deployment - waitUntilDeploymentReady(oc, "flowlogs-pipeline-informers", flow.Namespace) + // check informers deployment - only available in version >= 2.0 + csvVersion, err := getCSVVersion(oc.AdminDynamicClient(), netobservNS) + if err != nil { + e2e.Logf("Could not get CSV version, skipping informers check: %v", err) + } else if semver.Compare(semver.Canonical("v"+csvVersion), "v2.0.0") >= 0 { + waitUntilDeploymentReady(oc, "flowlogs-pipeline-informers", flow.Namespace) + } else { + e2e.Logf("Skipping informers check, CSV version %s is below 2.0", csvVersion) + } // check ebpf-agent status waitUntilDaemonSetReady(oc, "netobserv-ebpf-agent", flow.Namespace+"-privileged") @@ -222,7 +230,7 @@ func (flow *Flowcollector) WaitForFlowcollectorReady(oc *exutil.CLI) { compat_otp.AssertAllPodsToBeReady(oc, flow.Namespace) compat_otp.AssertAllPodsToBeReady(oc, flow.Namespace+"-privileged") - err := wait.PollUntilContextTimeout(context.Background(), 10*time.Second, 600*time.Second, false, func(context.Context) (done bool, err error) { + err = wait.PollUntilContextTimeout(context.Background(), 10*time.Second, 600*time.Second, false, func(context.Context) (done bool, err error) { condStatus, err := oc.AsAdmin().Run("get").Args("flowcollector", "cluster", "-o", `jsonpath='{.status.conditions[?(@.type=="Ready")].status}'`).Output() if err != nil { return false, nil diff --git a/integration-tests/backend/operator.go b/integration-tests/backend/operator.go index 9082413ac2..4ad2df2b1b 100644 --- a/integration-tests/backend/operator.go +++ b/integration-tests/backend/operator.go @@ -13,7 +13,10 @@ import ( compat_otp "github.com/openshift/origin/test/extended/util/compat_otp" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/client-go/dynamic" e2e "k8s.io/kubernetes/test/e2e/framework" ) @@ -337,3 +340,46 @@ func getOperatorChannel(oc *exutil.CLI, catalog string, packageName string) (ope channelArr := strings.Split(channels, " ") return channelArr[len(channelArr)-1], err } + +// getCSVVersion returns the version of the installed NetObserv Operator CSV in the given namespace. +// It uses the dynamic client to list CSVs and finds the one whose name starts with the operator name prefix. +func getCSVVersion(dynamicClient dynamic.Interface, operatorNamespace string) (string, error) { + csvGVR := schema.GroupVersionResource{ + Group: "operators.coreos.com", + Version: "v1alpha1", + Resource: "clusterserviceversions", + } + + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + csvList, err := dynamicClient.Resource(csvGVR).Namespace(operatorNamespace).List(ctx, metav1.ListOptions{}) + if err != nil { + return "", fmt.Errorf("failed to list CSVs in namespace %s: %v", operatorNamespace, err) + } + + var matched []string + for _, csv := range csvList.Items { + if !strings.HasPrefix(csv.GetName(), NOPackageName+".") { + continue + } + // Only consider the active CSV (phase "Succeeded"); during upgrades, + // replaced CSVs have phase "Replacing" or "Deleting". + phase, _, _ := unstructured.NestedString(csv.Object, "status", "phase") + if phase != "Succeeded" { + continue + } + version, found, err := unstructured.NestedString(csv.Object, "spec", "version") + if err != nil || !found { + return "", fmt.Errorf("version field not found in CSV %s", csv.GetName()) + } + matched = append(matched, version) + } + switch len(matched) { + case 0: + return "", fmt.Errorf("no active CSV found for %s in namespace %s", NOPackageName, operatorNamespace) + case 1: + return matched[0], nil + default: + return "", fmt.Errorf("multiple active CSVs found for %s in namespace %s: %v", NOPackageName, operatorNamespace, matched) + } +}