Skip to content

Commit

Permalink
[NO-ISSUE] Add startup check for test proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
brusdev committed Dec 5, 2024
1 parent 4a9f087 commit bea0cd0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,22 @@ func setUpTestProxy() {
true, "", testProxyHost, isOpenshift)
createOrOverwriteResource(testProxyIngress)

if os.Getenv("USE_EXISTING_CLUSTER") == "true" {
Eventually(func(g Gomega) {
tlsConn, tlsErr := tls.Dial("tcp", clusterIngressHost+":443",
&tls.Config{ServerName: testProxyHost, InsecureSkipVerify: true})
g.Expect(tlsErr).Should(BeNil())
tlsConn.Close()
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())
}

http.DefaultTransport = &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
tlsConn, tlsErr := tls.Dial("tcp", clusterIngressHost+":443",
&tls.Config{ServerName: testProxyHost, InsecureSkipVerify: true})
if tlsErr != nil {
testProxyLog.V(1).Info("Error creating tls connection", "addr", addr, "error", tlsErr)
return nil, tlsErr
return nil, fmt.Errorf("Error creating tls connection to %s: %v", addr, tlsErr)
}

sshConn, sshChans, sshReqs, sshErr := ssh.NewClientConn(tlsConn, "127.0.0.1:2022", &ssh.ClientConfig{
Expand All @@ -388,9 +397,8 @@ func setUpTestProxy() {
})
if sshErr != nil {
testProxyLog.V(1).Info("Error creating SSH connection", "addr", addr, "error", sshErr)
fmt.Printf("\nError creating SSH tunnel to %s: %v", addr, sshErr)
tlsConn.Close()
return nil, sshErr
return nil, fmt.Errorf("Error creating SSH connection to %s: %v", addr, sshErr)
}

sshClient := ssh.NewClient(sshConn, sshChans, sshReqs)
Expand All @@ -401,7 +409,7 @@ func setUpTestProxy() {
sshClient.Close()
sshConn.Close()
tlsConn.Close()
return nil, sshClientErr
return nil, fmt.Errorf("Error creating SSH tunnel to %s: %v", addr, sshClientErr)
}

testProxyLog.V(1).Info("Opened SSH tunnel", "addr", addr)
Expand Down

0 comments on commit bea0cd0

Please sign in to comment.