Merge pull request #721 from vmware-tanzu/resolve-load-balancer-dns

wait for lb dns to resolve in the impersonation proxy integration test
This commit is contained in:
Margo Crawford 2021-07-15 17:02:08 -07:00 committed by GitHub
commit d204b46c18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,6 +16,7 @@ import (
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
@ -278,6 +279,9 @@ func TestImpersonationProxy(t *testing.T) { //nolint:gocyclo // yeah, it's compl
if !clusterSupportsLoadBalancers { if !clusterSupportsLoadBalancers {
// In this case, we specified the endpoint in the configmap, so check that it was reported correctly in the CredentialIssuer. // In this case, we specified the endpoint in the configmap, so check that it was reported correctly in the CredentialIssuer.
require.Equal(t, "https://"+proxyServiceEndpoint, impersonationProxyURL) require.Equal(t, "https://"+proxyServiceEndpoint, impersonationProxyURL)
} else {
// If the impersonationProxyURL is a hostname, make sure DNS will resolve before we move on.
ensureDNSResolves(t, impersonationProxyURL)
} }
// Because our credentials expire so quickly, we'll always use a new client, to give us a chance to refresh our // Because our credentials expire so quickly, we'll always use a new client, to give us a chance to refresh our
@ -1624,6 +1628,18 @@ func TestImpersonationProxy(t *testing.T) { //nolint:gocyclo // yeah, it's compl
}) })
} }
func ensureDNSResolves(t *testing.T, urlString string) {
t.Helper()
parsedURL, err := url.Parse(urlString)
require.NoError(t, err)
if net.ParseIP(parsedURL.Host) == nil {
testlib.RequireEventually(t, func(requireEventually *require.Assertions) {
_, err = net.LookupIP(parsedURL.Host)
requireEventually.NoError(err)
}, 5*time.Minute, 1*time.Second)
}
}
func createTestNamespace(t *testing.T, adminClient kubernetes.Interface) string { func createTestNamespace(t *testing.T, adminClient kubernetes.Interface) string {
t.Helper() t.Helper()
@ -1721,6 +1737,7 @@ func performImpersonatorDiscovery(ctx context.Context, t *testing.T, env *testli
return false, fmt.Errorf("did not find an ImpersonationProxyInfo") // unexpected, fail the test return false, fmt.Errorf("did not find an ImpersonationProxyInfo") // unexpected, fail the test
} }
impersonationProxyURL = strategy.Frontend.ImpersonationProxyInfo.Endpoint impersonationProxyURL = strategy.Frontend.ImpersonationProxyInfo.Endpoint
impersonationProxyCACertPEM, err = base64.StdEncoding.DecodeString(strategy.Frontend.ImpersonationProxyInfo.CertificateAuthorityData) impersonationProxyCACertPEM, err = base64.StdEncoding.DecodeString(strategy.Frontend.ImpersonationProxyInfo.CertificateAuthorityData)
if err != nil { if err != nil {
return false, err // unexpected, fail the test return false, err // unexpected, fail the test