Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.18] OCPBUGS-48389: only provision workloads when network creation has started #29413

Open
wants to merge 6 commits into
base: release-4.18
Choose a base branch
from
Prev Previous commit
Next Next commit
virt: assert network is ready in each node before starting workloads
Otherwise, we risk facing a situation where the primary UDN will not be
plumbed into the worlkload.

Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
  • Loading branch information
maiqueb authored and openshift-cherrypick-robot committed Jan 9, 2025
commit 126d57532b0eb0b0e64cade2db120ea737edcddf
78 changes: 78 additions & 0 deletions test/extended/networking/livemigration.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package networking

import (
"bufio"
"context"
"encoding/json"
"fmt"
"net"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -79,6 +81,15 @@ var _ = Describe("[sig-network][OCPFeatureGate:PersistentIPsForVirtualization][F

createNetworkFn(netConfig)

for _, node := range workerNodes {
Eventually(func() bool {
isNetProvisioned, err := isNetworkProvisioned(oc, node.Name, netConfig.networkName)
return err == nil && isNetProvisioned
}).WithPolling(time.Second).WithTimeout(udnCrReadyTimeout).Should(
BeTrueBecause("the network must be ready before creating workloads"),
)
}

httpServerPods := prepareHTTPServerPods(f, netConfig, workerNodes)
vmCreationParams := kubevirt.CreationTemplateParams{
VMName: vmName,
Expand Down Expand Up @@ -462,3 +473,70 @@ func checkEastWestTraffic(virtClient *kubevirt.Client, vmiName string, podIPsByN
}
}
}

func isNetworkProvisioned(oc *exutil.CLI, nodeName string, networkName string) (bool, error) {
var podName string
var out string
var err error

out, err = runOcWithRetry(oc.AsAdmin(), "get",
"pods",
"-o", "name",
"-n", "openshift-ovn-kubernetes",
"--field-selector", fmt.Sprintf("spec.nodeName=%s", nodeName),
"-l", "app=ovnkube-node")
if err != nil {
return false, err
}
outReader := bufio.NewScanner(strings.NewReader(out))
re := regexp.MustCompile("^pod/(.*)")
for outReader.Scan() {
match := re.FindSubmatch([]byte(outReader.Text()))
if len(match) != 2 {
continue
}
podName = string(match[1])
break
}
if podName == "" {
return false, fmt.Errorf("could not find a valid ovnkube-node pod on node '%s'", nodeName)
}

ovnkubePod, err := oc.AdminKubeClient().CoreV1().Pods("openshift-ovn-kubernetes").Get(context.Background(),
podName, metav1.GetOptions{})
if err != nil {
return false, fmt.Errorf("couldn't get %s pod in openshift-ovn-kubernetes namespace: %v", podName, err)
}

ovnkubeContainerName := ""
for _, container := range ovnkubePod.Spec.Containers {
if container.Name == "ovnkube-node" {
ovnkubeContainerName = container.Name
} else if container.Name == "ovnkube-controller" {
ovnkubeContainerName = container.Name
}
}
if ovnkubeContainerName == "" {
return false, fmt.Errorf("didn't find ovnkube-node or ovnkube-controller container in %s pod", podName)
}

lsName := logicalSwitchName(networkName)
out, err = adminExecInPod(
oc,
"openshift-ovn-kubernetes",
podName,
ovnkubeContainerName,
fmt.Sprintf("ovn-nbctl list logical-switch %s", lsName),
)
if err != nil {
return false, fmt.Errorf("failed to find a logical switch for network %q: %w", networkName, err)
}

return strings.Contains(out, lsName), nil
}

func logicalSwitchName(networkName string) string {
netName := strings.ReplaceAll(networkName, "-", ".")
netName = strings.ReplaceAll(netName, "/", ".")
return fmt.Sprintf("%s_ovn_layer2_switch", netName)
}