Skip to content

Commit

Permalink
squash (knative#6174)
Browse files Browse the repository at this point in the history
  • Loading branch information
vagababov committed Dec 7, 2019
1 parent a1a35b1 commit 2a75f57
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 35 deletions.
6 changes: 5 additions & 1 deletion pkg/reconciler/route/resources/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ func makeServiceSpec(ingress netv1alpha1.IngressAccessor, isPrivate bool) (*core
func GetDesiredServiceNames(ctx context.Context, route *v1alpha1.Route) (sets.String, error) {
traffic := route.Spec.Traffic

names := sets.String{}
// We always want create the route with the service name.
// If the traffic stanza only contains revision targets, then
// this will not be added below, and as a consequence we'll create
// a public route to it.
names := sets.NewString(route.Name)

for _, t := range traffic {
serviceName, err := domains.HostnameFromTemplate(ctx, route.Name, t.Tag)
Expand Down
68 changes: 41 additions & 27 deletions pkg/reconciler/route/resources/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,36 +381,50 @@ func TestGetDesiredServiceNames(t *testing.T) {
traffic RouteOption
want sets.String
wantErr bool
}{
{
name: "no traffic defined",
},
{
name: "only default traffic",
traffic: WithSpecTraffic(v1alpha1.TrafficTarget{TrafficTarget: v1.TrafficTarget{}}),
want: sets.NewString("myroute"),
}{{
name: "no traffic defined",
want: sets.NewString("myroute"),
}, {
name: "only default traffic",
traffic: WithSpecTraffic(v1alpha1.TrafficTarget{TrafficTarget: v1.TrafficTarget{}}),
want: sets.NewString("myroute"),
}, {
name: "traffic targets with default and tags",
traffic: WithSpecTraffic(v1alpha1.TrafficTarget{
TrafficTarget: v1.TrafficTarget{},
}, v1alpha1.TrafficTarget{
TrafficTarget: v1.TrafficTarget{
Tag: "hello",
},
}, v1alpha1.TrafficTarget{
TrafficTarget: v1.TrafficTarget{
Tag: "hello",
},
}, v1alpha1.TrafficTarget{
TrafficTarget: v1.TrafficTarget{
Tag: "bye",
},
},
{
name: "traffic targets with tag",
traffic: WithSpecTraffic(v1alpha1.TrafficTarget{
TrafficTarget: v1.TrafficTarget{},
}, v1alpha1.TrafficTarget{
TrafficTarget: v1.TrafficTarget{
Tag: "hello",
},
}, v1alpha1.TrafficTarget{
TrafficTarget: v1.TrafficTarget{
Tag: "hello",
},
}, v1alpha1.TrafficTarget{
TrafficTarget: v1.TrafficTarget{
Tag: "bye",
},
),
want: sets.NewString("myroute", "hello-myroute", "bye-myroute"),
}, {
name: "traffic targets with NO default and tags",
traffic: WithSpecTraffic(v1alpha1.TrafficTarget{
TrafficTarget: v1.TrafficTarget{
Tag: "hello",
},
}, v1alpha1.TrafficTarget{
TrafficTarget: v1.TrafficTarget{
Tag: "hello",
},
}, v1alpha1.TrafficTarget{
TrafficTarget: v1.TrafficTarget{
Tag: "bye",
},
),
want: sets.NewString("myroute", "hello-myroute", "bye-myroute"),
},
}
),
want: sets.NewString("myroute", "hello-myroute", "bye-myroute"),
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cfg := testConfig()
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/service_to_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ import (
"knative.dev/pkg/test/ingress"
"knative.dev/pkg/test/logstream"
"knative.dev/pkg/test/spoof"
"knative.dev/serving/pkg/apis/autoscaling"
routeconfig "knative.dev/serving/pkg/reconciler/route/config"
v1alph1testing "knative.dev/serving/pkg/testing/v1alpha1"
"knative.dev/serving/test"
v1a1test "knative.dev/serving/test/v1alpha1"

corev1 "k8s.io/api/core/v1"

"knative.dev/serving/pkg/apis/autoscaling"
routeconfig "knative.dev/serving/pkg/reconciler/route/config"
)

const (
Expand Down Expand Up @@ -151,7 +150,8 @@ func testProxyToHelloworld(t *testing.T, clients *test.Clients, helloworldURL *u
t.Fatalf("The httpproxy response '%s' is not equal to helloworld response '%s'.", string(response.Body), helloworldResponse)
}

// As a final check (since we know they are both up), check that if we can access the helloworld app externally.
// As a final check (since we know they are both up), check that if we can
// (or cannot) access the helloworld app externally.
response, err = sendRequest(t, clients, test.ServingFlags.ResolvableDomain, helloworldURL)
if err != nil {
if test.ServingFlags.ResolvableDomain {
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestServiceToServiceCall(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
cancel := logstream.Start(t)
defer cancel()
testProxyToHelloworld(t, clients, helloworldURL, true, false)
testProxyToHelloworld(t, clients, helloworldURL, true /*inject*/, false /*accessible externally*/)
})
}
}
Expand Down Expand Up @@ -256,7 +256,7 @@ func testSvcToSvcCallViaActivator(t *testing.T, clients *test.Clients, injectA b
}

// Send request to helloworld app via httpproxy service
testProxyToHelloworld(t, clients, resources.Route.Status.URL.URL(), injectA, false)
testProxyToHelloworld(t, clients, resources.Route.Status.URL.URL(), injectA, false /*accessible externally*/)
}

// Same test as TestServiceToServiceCall but before sending requests
Expand Down Expand Up @@ -324,7 +324,7 @@ func TestCallToPublicService(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
cancel := logstream.Start(t)
defer cancel()
testProxyToHelloworld(t, clients, tc.url, false, tc.accessibleExternally)
testProxyToHelloworld(t, clients, tc.url, false /*inject*/, tc.accessibleExternally)
})
}
}

0 comments on commit 2a75f57

Please sign in to comment.