Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Sloka <[email protected]>
  • Loading branch information
stevesloka committed Feb 11, 2021
1 parent 9058ae5 commit d643389
Showing 1 changed file with 10 additions and 38 deletions.
48 changes: 10 additions & 38 deletions internal/dag/serviceapis_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ func (p *ServiceAPIsProcessor) Run(dag *DAG, source *KubernetesCache) {
p.source = nil
}()

for _, route := range p.validHTTPRoutes() {
for _, route := range p.source.httproutes {
p.computeHTTPRoute(route)
}
}

func (p *ServiceAPIsProcessor) computeHTTPRoute(route *serviceapis.HTTPRoute) {

// Validate TLS Configuration
if route.Spec.TLS != nil {
p.Error("NOT IMPLEMENTED: The 'RouteTLSConfig' is not yet implemented.")
}

// Determine the hosts on the route, if no hosts
// are defined, then set to "*".
var hosts []string
Expand Down Expand Up @@ -86,12 +91,13 @@ func (p *ServiceAPIsProcessor) computeHTTPRoute(route *serviceapis.HTTPRoute) {
service, err := p.dag.EnsureService(meta, intstr.FromInt(int(forward.Port)), p.source)
if err != nil {
// TODO: Raise `ResolvedRefs` condition on Gateway with `DegradedRoutes` reason.
p.Errorf("Service %q does not exist in namespace %q", meta.Name, meta.Namespace)
return
}
services = append(services, service)
}

routes := p.route(pathPrefixes, services)
routes := p.routes(pathPrefixes, services)

for _, vhost := range hosts {
vhost := p.dag.EnsureVirtualHost(vhost)
Expand All @@ -102,8 +108,8 @@ func (p *ServiceAPIsProcessor) computeHTTPRoute(route *serviceapis.HTTPRoute) {
}
}

// route builds a []*dag.Route for the supplied HTTPRoute.
func (p *ServiceAPIsProcessor) route(pathPrefixes []string, services []*Service) []*Route {
// routes builds a []*dag.Route for the supplied set of pathPrefixes & services.
func (p *ServiceAPIsProcessor) routes(pathPrefixes []string, services []*Service) []*Route {
var clusters []*Cluster
var routes []*Route

Expand All @@ -124,37 +130,3 @@ func (p *ServiceAPIsProcessor) route(pathPrefixes []string, services []*Service)

return routes
}

// httpRoutes returns a slice of *serviceapis.HTTPRoute objects.
// invalid HTTPRoute objects are excluded from the slice and their status
// updated accordingly.
func (p *ServiceAPIsProcessor) validHTTPRoutes() []*serviceapis.HTTPRoute {
var valid []*serviceapis.HTTPRoute

// Validate this HTTPRoute references an existing Gateway when the "allow" type
// on the HTTPRoute is set to "FromList".
for _, route := range p.source.httproutes {
switch route.Spec.Gateways.Allow {
case serviceapis.GatewayAllowFromList:
// GatewayAllowFromList indicates that only Gateways that have been
// specified in GatewayRefs will be able to use this route.
for _, gatewayRef := range route.Spec.Gateways.GatewayRefs {
if p.gatewayExists(gatewayRef.Name, gatewayRef.Namespace) {
valid = append(valid, route)
}
}
default:
valid = append(valid, route)
}
}
return valid
}

func (p *ServiceAPIsProcessor) gatewayExists(name, namespace string) bool {
for _, gw := range p.source.gateways {
if name == gw.Name && namespace == gw.Namespace {
return true
}
}
return false
}

0 comments on commit d643389

Please sign in to comment.