Skip to content

Commit

Permalink
Remove GetDomain
Browse files Browse the repository at this point in the history
  • Loading branch information
Tara Gu committed Nov 5, 2019
1 parent e66eb18 commit 9c9b613
Showing 1 changed file with 28 additions and 47 deletions.
75 changes: 28 additions & 47 deletions test/v1alpha1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,34 +126,10 @@ func CreateRunLatestServiceReady(t *testing.T, clients *test.Clients, names *tes
return nil, nil, fmt.Errorf("expected non-empty Image name; got Image=%v", names.Image)
}

var httpsTransportOption *spoof.TransportOption
var err error
if https {
tlsOptions := &v1alpha3.TLSOptions{
Mode: v1alpha3.TLSModeSimple,
PrivateKey: "/etc/istio/ingressgateway-certs/tls.key",
ServerCertificate: "/etc/istio/ingressgateway-certs/tls.crt",
}
servers := []v1alpha3.Server{{
Hosts: []string{"*"},
Port: v1alpha3.Port{
Name: "standard-https",
Number: 443,
Protocol: v1alpha3.ProtocolHTTPS,
},
TLS: tlsOptions,
}}
httpsTransportOption, err = setupHTTPS(t, clients.KubeClient, names.Service, GetDomain(t, clients))
if err != nil {
return nil, nil, err
}
setupGateway(t, clients, servers)
}

t.Logf("Creating a new Service %s.", names.Service)
svc, err := CreateLatestService(t, clients, *names, fopt...)
if err != nil {
return nil, httpsTransportOption, err
return nil, nil, err
}

// Populate Route and Configuration Objects with name
Expand All @@ -166,14 +142,38 @@ func CreateRunLatestServiceReady(t *testing.T, clients *test.Clients, names *tes
}

t.Logf("Waiting for Service %q to transition to Ready.", names.Service)
if err := WaitForServiceState(clients.ServingAlphaClient, names.Service, IsServiceReady, "ServiceIsReady"); err != nil {
return nil, httpsTransportOption, err
if err = WaitForServiceState(clients.ServingAlphaClient, names.Service, IsServiceReady, "ServiceIsReady"); err != nil {
return nil, nil, err
}

t.Log("Checking to ensure Service Status is populated for Ready service", names.Service)
err = validateCreatedServiceStatus(clients, names)
if err != nil {
return nil, httpsTransportOption, err
return nil, nil, err
}

var httpsTransportOption *spoof.TransportOption
if https {
tlsOptions := &v1alpha3.TLSOptions{
Mode: v1alpha3.TLSModeSimple,
PrivateKey: "/etc/istio/ingressgateway-certs/tls.key",
ServerCertificate: "/etc/istio/ingressgateway-certs/tls.crt",
}
servers := []v1alpha3.Server{{
Hosts: []string{"*"},
Port: v1alpha3.Port{
Name: "standard-https",
Number: 443,
Protocol: v1alpha3.ProtocolHTTPS,
},
TLS: tlsOptions,
}}
domainName := strings.SplitN(names.URL.Host, ".", 2)[1]
httpsTransportOption, err = setupHTTPS(t, clients.KubeClient, names.Service, domainName)
if err != nil {
return nil, nil, err
}
setupGateway(t, clients, servers)
}

t.Log("Getting latest objects Created by Service", names.Service)
Expand Down Expand Up @@ -415,25 +415,6 @@ func RestoreGateway(t *testing.T, clients *test.Clients, oldGateway v1alpha3.Gat
}
}

// GetDomain returns the domain name. If the saved domain name is null, it will create a dummy service in order to get
// the domain name
func GetDomain(t *testing.T, clients *test.Clients) string {
if domainName == nil {
names := test.ResourceNames{
Service: test.ObjectNameForTest(t),
Image: "helloworld",
}
test.CleanupOnInterrupt(func() { test.TearDown(clients, names) })
defer test.TearDown(clients, names)
objects, _, err := CreateRunLatestServiceReady(t, clients, &names, false /* https */)
if err != nil {
t.Fatalf("Failed to create Service %s: %v", names.Service, err)
}
domainName = &(strings.SplitN(objects.Route.Status.URL.Host, ".", 2)[1])
}
return *domainName
}

// setupGateway updates the ingress Gateway to the provided Servers and waits until all Envoy pods have been updated.
func setupGateway(t *testing.T, clients *test.Clients, servers []v1alpha3.Server) {
// Get the current Gateway
Expand Down

0 comments on commit 9c9b613

Please sign in to comment.