Skip to content

Commit

Permalink
OCPBUGS-18534: monitor test fix to wait before connecting to a non-ex…
Browse files Browse the repository at this point in the history
…istent dns

Signed-off-by: Jason Cho <jason.cho2@ibm.com>

go fmt fix

Signed-off-by: Jason Cho <jason.cho2@ibm.com>
  • Loading branch information
jcho02 committed Apr 29, 2024
1 parent ce9d443 commit 377e5dc
Showing 1 changed file with 39 additions and 0 deletions.
@@ -1,14 +1,17 @@
package disruptionserviceloadbalancer

import (
"bytes"
"context"
"crypto/tls"
_ "embed"
"fmt"
"net"
"net/http"
"os"
"os/exec"
"strconv"
"strings"
"time"

"github.com/openshift/origin/pkg/monitortestframework"
Expand Down Expand Up @@ -165,6 +168,14 @@ func (w *availability) StartCollection(ctx context.Context, adminRESTConfig *res
return fmt.Errorf("error waiting for load balancer: %w", err)
}

//Checks if platform is PowerVS or IBMCloud to verify the hostname through the service LoadBalancer
if infra.Spec.PlatformSpec.Type == configv1.PowerVSPlatformType || infra.Spec.PlatformSpec.Type == configv1.IBMCloudPlatformType {
nodeTgt := "node/" + nodeList.Items[0].ObjectMeta.Name
if err := checkHostnameReady(tcpService, nodeTgt); err != nil {
return err
}
}

// Get info to hit it with
tcpIngressIP := service.GetIngressPoint(&tcpService.Status.LoadBalancer.Ingress[0])
svcPort := int(tcpService.Spec.Ports[0].Port)
Expand Down Expand Up @@ -344,3 +355,31 @@ func httpGetNoConnectionPoolTimeout(url string, timeout time.Duration) (*http.Re

return client.Get(url)
}

// checkHostnameReady debugs the master node in the PowerVS or IBMCloud cluster
// and verifies the hostname is active before hitting through the LoadBalancer
func checkHostnameReady(tcpService *corev1.Service, nodeTgt string) error {
for i := 0; i < 60; i++ {
lbTgt := tcpService.Status.LoadBalancer.Ingress[0].Hostname
cmd := exec.Command("oc", "debug", nodeTgt, "--", "/bin/bash", "-c", "dig +short "+lbTgt)
out := &bytes.Buffer{}
errOut := &bytes.Buffer{}
cmd.Stdout = out
cmd.Stderr = errOut

if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to run the command: %v: %v", err, errOut.String())
}

output := strings.TrimSpace(out.String())
fmt.Println("output: " + output)
if output == "" {
fmt.Println("waiting for the LB to come active")
time.Sleep(1 * time.Minute)
continue
} else {
break
}
}
return nil
}

0 comments on commit 377e5dc

Please sign in to comment.