Skip to content
Closed
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
4 changes: 4 additions & 0 deletions pkg/controller/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func GetServingK8SServiceFullnameForRoute(u *v1alpha1.Route) string {
return GetK8SServiceFullname(GetServingK8SServiceNameForRoute(u), u.Namespace)
}

func GetServingK8SServiceShortnameForRoute(u *v1alpha1.Route) string {
return fmt.Sprintf("%s.%s", GetServingK8SServiceNameForRoute(u), u.Namespace)
}

func GetServiceConfigurationName(u *v1alpha1.Service) string {
return u.Name
}
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/route/istio/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func MakeRouteK8SService(route *v1alpha1.Route) *corev1.Service {
Port: PortNumber,
},
},
ClusterIP: "None",
},
}
}
1 change: 0 additions & 1 deletion pkg/controller/route/istio/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestMakeRouteK8SService_ValidSpec(t *testing.T) {
Name: "http",
Port: 80,
}},
ClusterIP: "None",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!

}
spec := MakeRouteK8SService(r).Spec
if diff := cmp.Diff(expectedSpec, spec); diff != "" {
Expand Down
9 changes: 8 additions & 1 deletion pkg/controller/route/istio/virtual_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func makeVirtualServiceSpec(u *v1alpha1.Route, targets map[string][]traffic.Revi
domain,
// Traffic from inside the cluster will use the FQDN of the Route's headless Service.
controller.GetServingK8SServiceFullnameForRoute(u),
controller.GetServingK8SServiceShortnameForRoute(u),
controller.GetServingK8SServiceNameForRoute(u),
},
}
names := []string{}
Expand All @@ -86,7 +88,12 @@ func getRouteDomains(targetName string, u *v1alpha1.Route, domain string) []stri
if targetName == "" {
// Nameless traffic targets correspond to two domains: the Route.Status.Domain, and also the FQDN
// of the Route's headless Service.
return []string{domain, controller.GetServingK8SServiceFullnameForRoute(u)}
return []string{
domain,
controller.GetServingK8SServiceFullnameForRoute(u),
controller.GetServingK8SServiceShortnameForRoute(u),
controller.GetServingK8SServiceNameForRoute(u),
}
}
// Named traffic targets correspond to a subdomain of the Route.Status.Domain.
return []string{fmt.Sprintf("%s.%s", targetName, domain)}
Expand Down
13 changes: 12 additions & 1 deletion pkg/controller/route/istio/virtual_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func TestMakeVirtualServiceSpec_CorrectSpec(t *testing.T) {
"*.domain.com",
"domain.com",
"test-route-service.test-ns.svc.cluster.local",
"test-route-service.test-ns",
"test-route-service",
},
}
routes := MakeVirtualService(r, &traffic.TrafficConfig{Targets: targets}).Spec
Expand Down Expand Up @@ -114,6 +116,10 @@ func TestMakeVirtualServiceSpec_CorrectRoutes(t *testing.T) {
Authority: &v1alpha3.StringMatch{Exact: "domain.com"},
}, {
Authority: &v1alpha3.StringMatch{Exact: "test-route-service.test-ns.svc.cluster.local"},
}, {
Authority: &v1alpha3.StringMatch{Exact: "test-route-service.test-ns"},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I filed #1429 to track the short names.

For now I think it may be best that we leave them out to avoid confusions.

}, {
Authority: &v1alpha3.StringMatch{Exact: "test-route-service"},
}},
Route: []v1alpha3.DestinationWeight{{
Destination: v1alpha3.Destination{
Expand Down Expand Up @@ -153,7 +159,12 @@ func TestGetRouteDomains_NamelessTarget(t *testing.T) {
},
}
base := "domain.com"
expected := []string{base, "test-route-service.test-ns.svc.cluster.local"}
expected := []string{
base,
"test-route-service.test-ns.svc.cluster.local",
"test-route-service.test-ns",
"test-route-service",
}
domains := getRouteDomains("", r, base)
if diff := cmp.Diff(expected, domains); diff != "" {
t.Errorf("Unexpected domains (-want +got): %v", diff)
Expand Down
48 changes: 48 additions & 0 deletions pkg/controller/route/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ func TestCreateRouteCreatesStuff(t *testing.T) {
}
domain := strings.Join([]string{route.Name, route.Namespace, defaultDomainSuffix}, ".")
clusterDomain := "test-route-service.test.svc.cluster.local"
serviceShortName := "test-route-service.test"
serviceName := "test-route-service"
expectedSpec := v1alpha3.VirtualServiceSpec{
// We want to connect to two Gateways: the Route's ingress
// Gateway, and the 'mesh' Gateway. The former provides
Expand All @@ -288,12 +290,18 @@ func TestCreateRouteCreatesStuff(t *testing.T) {
"*." + domain,
domain,
clusterDomain,
serviceShortName,
serviceName,
},
Http: []v1alpha3.HTTPRoute{{
Match: []v1alpha3.HTTPMatchRequest{{
Authority: &v1alpha3.StringMatch{Exact: domain},
}, {
Authority: &v1alpha3.StringMatch{Exact: clusterDomain},
}, {
Authority: &v1alpha3.StringMatch{Exact: serviceShortName},
}, {
Authority: &v1alpha3.StringMatch{Exact: serviceName},
}},
Route: []v1alpha3.DestinationWeight{{
Destination: v1alpha3.Destination{
Expand Down Expand Up @@ -371,6 +379,8 @@ func TestCreateRouteForOneReserveRevision(t *testing.T) {
}
domain := strings.Join([]string{route.Name, route.Namespace, defaultDomainSuffix}, ".")
clusterDomain := "test-route-service.test.svc.cluster.local"
serviceShortName := "test-route-service.test"
serviceName := "test-route-service"
expectedSpec := v1alpha3.VirtualServiceSpec{
// We want to connect to two Gateways: the Route's ingress
// Gateway, and the 'mesh' Gateway. The former provides
Expand All @@ -384,12 +394,18 @@ func TestCreateRouteForOneReserveRevision(t *testing.T) {
"*." + domain,
domain,
clusterDomain,
serviceShortName,
serviceName,
},
Http: []v1alpha3.HTTPRoute{{
Match: []v1alpha3.HTTPMatchRequest{{
Authority: &v1alpha3.StringMatch{Exact: domain},
}, {
Authority: &v1alpha3.StringMatch{Exact: clusterDomain},
}, {
Authority: &v1alpha3.StringMatch{Exact: serviceShortName},
}, {
Authority: &v1alpha3.StringMatch{Exact: serviceName},
}},
Route: []v1alpha3.DestinationWeight{getActivatorDestinationWeight(100)},
AppendHeaders: map[string]string{
Expand Down Expand Up @@ -447,6 +463,8 @@ func TestCreateRouteWithMultipleTargets(t *testing.T) {

domain := strings.Join([]string{route.Name, route.Namespace, defaultDomainSuffix}, ".")
clusterDomain := "test-route-service.test.svc.cluster.local"
serviceShortName := "test-route-service.test"
serviceName := "test-route-service"
expectedSpec := v1alpha3.VirtualServiceSpec{
// We want to connect to two Gateways: the Route's ingress
// Gateway, and the 'mesh' Gateway. The former provides
Expand All @@ -460,12 +478,18 @@ func TestCreateRouteWithMultipleTargets(t *testing.T) {
"*." + domain,
domain,
clusterDomain,
serviceShortName,
serviceName,
},
Http: []v1alpha3.HTTPRoute{{
Match: []v1alpha3.HTTPMatchRequest{{
Authority: &v1alpha3.StringMatch{Exact: domain},
}, {
Authority: &v1alpha3.StringMatch{Exact: clusterDomain},
}, {
Authority: &v1alpha3.StringMatch{Exact: serviceShortName},
}, {
Authority: &v1alpha3.StringMatch{Exact: serviceName},
}},
Route: []v1alpha3.DestinationWeight{{
Destination: v1alpha3.Destination{
Expand Down Expand Up @@ -534,6 +558,8 @@ func TestCreateRouteWithOneTargetReserve(t *testing.T) {

domain := strings.Join([]string{route.Name, route.Namespace, defaultDomainSuffix}, ".")
clusterDomain := "test-route-service.test.svc.cluster.local"
serviceShortName := "test-route-service.test"
serviceName := "test-route-service"
expectedSpec := v1alpha3.VirtualServiceSpec{
// We want to connect to two Gateways: the Route's ingress
// Gateway, and the 'mesh' Gateway. The former provides
Expand All @@ -547,12 +573,18 @@ func TestCreateRouteWithOneTargetReserve(t *testing.T) {
"*." + domain,
domain,
clusterDomain,
serviceShortName,
serviceName,
},
Http: []v1alpha3.HTTPRoute{{
Match: []v1alpha3.HTTPMatchRequest{{
Authority: &v1alpha3.StringMatch{Exact: domain},
}, {
Authority: &v1alpha3.StringMatch{Exact: clusterDomain},
}, {
Authority: &v1alpha3.StringMatch{Exact: serviceShortName},
}, {
Authority: &v1alpha3.StringMatch{Exact: serviceName},
}},
Route: []v1alpha3.DestinationWeight{{
Destination: v1alpha3.Destination{
Expand Down Expand Up @@ -632,6 +664,8 @@ func TestCreateRouteWithDuplicateTargets(t *testing.T) {

domain := strings.Join([]string{route.Name, route.Namespace, defaultDomainSuffix}, ".")
clusterDomain := "test-route-service.test.svc.cluster.local"
serviceShortName := "test-route-service.test"
serviceName := "test-route-service"
expectedSpec := v1alpha3.VirtualServiceSpec{
// We want to connect to two Gateways: the Route's ingress
// Gateway, and the 'mesh' Gateway. The former provides
Expand All @@ -645,12 +679,18 @@ func TestCreateRouteWithDuplicateTargets(t *testing.T) {
"*." + domain,
domain,
clusterDomain,
serviceShortName,
serviceName,
},
Http: []v1alpha3.HTTPRoute{{
Match: []v1alpha3.HTTPMatchRequest{{
Authority: &v1alpha3.StringMatch{Exact: domain},
}, {
Authority: &v1alpha3.StringMatch{Exact: clusterDomain},
}, {
Authority: &v1alpha3.StringMatch{Exact: serviceShortName},
}, {
Authority: &v1alpha3.StringMatch{Exact: serviceName},
}},
Route: []v1alpha3.DestinationWeight{{
Destination: v1alpha3.Destination{
Expand Down Expand Up @@ -733,6 +773,8 @@ func TestCreateRouteWithNamedTargets(t *testing.T) {
}
domain := strings.Join([]string{route.Name, route.Namespace, defaultDomainSuffix}, ".")
clusterDomain := "test-route-service.test.svc.cluster.local"
serviceShortName := "test-route-service.test"
serviceName := "test-route-service"
expectedSpec := v1alpha3.VirtualServiceSpec{
// We want to connect to two Gateways: the Route's ingress
// Gateway, and the 'mesh' Gateway. The former provides
Expand All @@ -746,12 +788,18 @@ func TestCreateRouteWithNamedTargets(t *testing.T) {
"*." + domain,
domain,
clusterDomain,
serviceShortName,
serviceName,
},
Http: []v1alpha3.HTTPRoute{{
Match: []v1alpha3.HTTPMatchRequest{{
Authority: &v1alpha3.StringMatch{Exact: domain},
}, {
Authority: &v1alpha3.StringMatch{Exact: clusterDomain},
}, {
Authority: &v1alpha3.StringMatch{Exact: serviceShortName},
}, {
Authority: &v1alpha3.StringMatch{Exact: serviceName},
}},
Route: []v1alpha3.DestinationWeight{{
Destination: v1alpha3.Destination{
Expand Down