Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exposing cluster local names to the external gateway. #6174

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.Ingress, isPrivate bool) (*corev1.Serv
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 @@ -152,7 +151,8 @@ func testProxyToHelloworld(t *testing.T, clients *test.Clients, helloworldURL *u
t.Fatalf("The httpproxy response = %q, want: %q.", 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 @@ -224,7 +224,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 @@ -259,7 +259,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 @@ -328,7 +328,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)
})
}
}