Skip to content

Commit

Permalink
Allows 503's for a newly created revision
Browse files Browse the repository at this point in the history
  • Loading branch information
bsnchan committed Jun 25, 2018
1 parent e444ce1 commit 12df486
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 23 deletions.
15 changes: 13 additions & 2 deletions test/conformance/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ package conformance

import (
"fmt"
"github.com/golang/glog"
"strings"
"testing"

"github.com/golang/glog"

"encoding/json"

"github.com/knative/serving/pkg/apis/serving/v1alpha1"
Expand Down Expand Up @@ -89,7 +90,17 @@ func assertResourcesUpdatedWhenRevisionIsReady(t *testing.T, clients *test.Clien
if err != nil {
t.Fatalf("Error fetching Route %s: %v", names.Route, err)
}
err = test.WaitForEndpointState(clients.Kube, test.Flags.ResolvableDomain, updatedRoute.Status.Domain, namespaceName, names.Route, func(body string) (bool, error) {

// TODO(#348): The ingress endpoint occasionally returns 503's and 404's.
// Explicitly allow 404's and 503's for a newly created revision.
opts := &test.Options{
ResolvableDomain: test.Flags.ResolvableDomain,
Domain: updatedRoute.Status.Domain,
NamespaceName: namespaceName,
RouteName: names.Route,
AllowableStatuses: []int{404, 503},
}
err = test.WaitForEndpointState(clients.Kube, opts, func(body string) (bool, error) {
return body == expectedText, nil
})
if err != nil {
Expand Down
33 changes: 22 additions & 11 deletions test/e2e/autoscale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ limitations under the License.
package e2e

import (
"github.com/golang/glog"
"strings"
"testing"

"github.com/golang/glog"

"github.com/knative/serving/pkg/apis/serving/v1alpha1"
"github.com/knative/serving/test"
"k8s.io/api/core/v1"
Expand Down Expand Up @@ -59,14 +60,19 @@ func generateTrafficBurst(clients *test.Clients, names test.ResourceNames, num i
concurrentRequests := make(chan bool, num)

glog.Infof("Performing %d concurrent requests.", num)

for i := 0; i < num; i++ {
go func() {
test.WaitForEndpointState(clients.Kube,
test.Flags.ResolvableDomain,
domain,
NamespaceName,
names.Route,
isExpectedOutput())
test.WaitForEndpointState(
clients.Kube,
&test.Options{
ResolvableDomain: test.Flags.ResolvableDomain,
Domain: domain,
NamespaceName: NamespaceName,
RouteName: names.Route,
},
isExpectedOutput(),
)
concurrentRequests <- true
}()
}
Expand Down Expand Up @@ -155,10 +161,15 @@ func TestAutoscaleUpDownUp(t *testing.T) {

err = test.WaitForEndpointState(
clients.Kube,
test.Flags.ResolvableDomain,
domain,
NamespaceName,
names.Route,
// TODO(#348): The ingress endpoint occasionally returns 503's and 404's.
// Explicitly allow 404's and 503's for a newly created revision.
&test.Options{
ResolvableDomain: test.Flags.ResolvableDomain,
Domain: domain,
NamespaceName: NamespaceName,
RouteName: names.Route,
AllowableStatuses: []int{503, 404},
},
isExpectedOutput())
if err != nil {
t.Fatalf(`The endpoint for Route %s at domain %s didn't serve
Expand Down
12 changes: 10 additions & 2 deletions test/e2e/helloworld_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ limitations under the License.
package e2e

import (
"github.com/golang/glog"
"strings"
"testing"

"github.com/golang/glog"

"github.com/knative/serving/pkg/apis/serving/v1alpha1"
"github.com/knative/serving/test"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -68,8 +69,15 @@ func TestHelloWorld(t *testing.T) {
if err != nil {
t.Fatalf("Error fetching Route %s: %v", names.Route, err)
}

domain := route.Status.Domain
err = test.WaitForEndpointState(clients.Kube, test.Flags.ResolvableDomain, domain, NamespaceName, names.Route, isHelloWorldExpectedOutput())
opts := &test.Options{
ResolvableDomain: test.Flags.ResolvableDomain,
Domain: domain,
NamespaceName: NamespaceName,
RouteName: names.Route,
}
err = test.WaitForEndpointState(clients.Kube, opts, isHelloWorldExpectedOutput())
if err != nil {
t.Fatalf("The endpoint for Route %s at domain %s didn't serve the expected text \"%s\": %v", names.Route, domain, helloWorldExpectedOutput, err)
}
Expand Down
30 changes: 22 additions & 8 deletions test/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ const (
requestTimeout = 1 * time.Minute
)

type Options struct {
ResolvableDomain bool
Domain string
NamespaceName string
AllowableStatuses []int
RouteName string
}

func waitForRequestToDomainState(address string, spoofDomain string, retryableCodes []int, inState func(body string) (bool, error)) error {
h := http.Client{}
req, err := http.NewRequest("GET", address, nil)
Expand Down Expand Up @@ -73,29 +81,35 @@ func waitForRequestToDomainState(address string, spoofDomain string, retryableCo
// WaitForEndpointState will poll an endpoint until inState indicates the state is achieved. If resolvableDomain
// is false, it will use kubeClientset to look up the ingress (named based on routeName) in the namespace namespaceName,
// and spoof domain in the request heaers, otherwise it will make the request directly to domain.
func WaitForEndpointState(kubeClientset *kubernetes.Clientset, resolvableDomain bool, domain string, namespaceName string, routeName string, inState func(body string) (bool, error)) error {
func WaitForEndpointState(kubeClientset *kubernetes.Clientset, opts *Options, inState func(body string) (bool, error)) error {
if len(opts.AllowableStatuses) == 0 {
// TODO(#348): The ingress endpoint tends to return 503's and 404's.
// Since there is currently a workaround for 503's, only allow 404's
// as an acceptable status code.
opts.AllowableStatuses = []int{404}
}

var endpoint, spoofDomain string

// If the domain that the Route controller is configured to assign to Route.Status.Domain
// (the domainSuffix) is not resolvable, we need to retrieve the IP of the endpoint and
// spoof the Host in our requests.
if !resolvableDomain {
ingressName := routeName + "-ingress"
ingress, err := kubeClientset.ExtensionsV1beta1().Ingresses(namespaceName).Get(ingressName, metav1.GetOptions{})
if !opts.ResolvableDomain {
ingressName := opts.RouteName + "-ingress"
ingress, err := kubeClientset.ExtensionsV1beta1().Ingresses(opts.NamespaceName).Get(ingressName, metav1.GetOptions{})
if err != nil {
return err
}
if ingress.Status.LoadBalancer.Ingress[0].IP == "" {
return fmt.Errorf("Expected ingress loadbalancer IP for %s to be set, instead was empty", ingressName)
}
endpoint = fmt.Sprintf("http://%s", ingress.Status.LoadBalancer.Ingress[0].IP)
spoofDomain = domain
spoofDomain = opts.Domain
} else {
// If the domain is resolvable, we can use it directly when we make requests
endpoint = domain
endpoint = opts.Domain
}

glog.Infof("Wait for the endpoint to be up and handling requests")
// TODO(#348): The ingress endpoint tends to return 503's and 404's
return waitForRequestToDomainState(endpoint, spoofDomain, []int{404}, inState)
return waitForRequestToDomainState(endpoint, spoofDomain, opts.AllowableStatuses, inState)
}

0 comments on commit 12df486

Please sign in to comment.