Skip to content

Commit

Permalink
Include all_kube_services route for potential envoy clients
Browse files Browse the repository at this point in the history
  • Loading branch information
ffilippopoulos committed Dec 10, 2024
1 parent f541708 commit e27a6d8
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions xds/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func makeRouteConfig(name, namespace, authority string, port int32, retry *route
}
return routeConfig(routeName, clusterName, virtualHostName, domains, retry, hashPolicies)
}

func routeConfig(routeName, clusterName, virtualHostName string, domains []string, retry *routev3.RetryPolicy, hashPolicies []*routev3.RouteAction_HashPolicy) *routev3.RouteConfiguration {
return &routev3.RouteConfiguration{
Name: routeName,
Expand Down Expand Up @@ -123,6 +124,43 @@ func routeConfig(routeName, clusterName, virtualHostName string, domains []strin
}
}

// makeAllKubeServicesRouteConfig will return all the available routes in a
// Kubernetes cluster. It is meant to be combined with envoy clients that will
// also configure on-demand CDS and EDS for lazy resources discovery.
func makeAllKubeServicesRouteConfig(serviceStore XdsServiceStore) *routev3.RouteConfiguration {
route := &routev3.RouteConfiguration{
Name: "all_kube_routes",
}
for _, s := range serviceStore.All() {
for _, port := range s.Service.Spec.Ports {
clusterName := makeClusterName(s.Service.Name, s.Service.Namespace, port.Port)
virtualHostName := makeVirtualHostName(s.Service.Name, s.Service.Namespace, port.Port)
domains := []string{makeGlobalServiceDomain(s.Service.Name, s.Service.Namespace, port.Port)}
route.VirtualHosts = append(route.VirtualHosts, &routev3.VirtualHost{
Name: virtualHostName,
Domains: domains,
Routes: []*routev3.Route{{
Match: &routev3.RouteMatch{
PathSpecifier: &routev3.RouteMatch_Prefix{
Prefix: "",
},
},
Action: &routev3.Route_Route{
Route: &routev3.RouteAction{
ClusterSpecifier: &routev3.RouteAction_Cluster{
Cluster: clusterName,
},
HashPolicy: s.RingHashPolicies,
},
},
}},
RetryPolicy: s.Retry,
})
}
}
return route
}

func makeManager(routeConfig *routev3.RouteConfiguration) (*anypb.Any, error) {
router, _ := anypb.New(&routerv3.Router{})
return anypb.New(&managerv3.HttpConnectionManager{
Expand Down Expand Up @@ -216,5 +254,6 @@ func servicesToResources(serviceStore XdsServiceStore, authority string) ([]type
cls = append(cls, cluster)
}
}
rds = append(rds, makeAllKubeServicesRouteConfig(serviceStore))
return cls, rds, lsnr, nil
}

0 comments on commit e27a6d8

Please sign in to comment.