Skip to content

Commit

Permalink
Refactor haproxy router config manager blueprint validation code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ramr committed Aug 22, 2018
1 parent a9901a5 commit f2bbf2c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ func newFakeConfigManager() *fakeConfigManager {
func (cm *fakeConfigManager) Initialize(router templaterouter.RouterInterface, certPath string) {
}

func (cm *fakeConfigManager) AddBlueprint(route *routev1.Route) {
func (cm *fakeConfigManager) AddBlueprint(route *routev1.Route) error {
cm.blueprints[routeKey(route)] = route
return nil
}

func (cm *fakeConfigManager) RemoveBlueprint(route *routev1.Route) {
Expand Down
21 changes: 6 additions & 15 deletions pkg/router/template/configmanager/haproxy/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,16 @@ func (cm *haproxyConfigManager) Initialize(router templaterouter.RouterInterface
}

// AddBlueprint adds a new (or replaces an existing) route blueprint.
func (cm *haproxyConfigManager) AddBlueprint(route *routev1.Route) {
func (cm *haproxyConfigManager) AddBlueprint(route *routev1.Route) error {
newRoute := route.DeepCopy()
newRoute.Namespace = blueprintRoutePoolNamespace
newRoute.Spec.Host = ""

if cm.extendedValidation {
if err := validateBlueprintRoute(newRoute); err != nil {
if err := routeapihelpers.ExtendedValidateRoute(newRoute).ToAggregate(); err != nil {
glog.Errorf("Skipping blueprint route %s/%s due to invalid configuration: %v",
route.Namespace, route.Name, err)
return
return err
}
}

Expand Down Expand Up @@ -240,14 +240,15 @@ func (cm *haproxyConfigManager) AddBlueprint(route *routev1.Route) {
}

if !updated {
return
return nil
}

cm.lock.Lock()
cm.blueprintRoutes = blueprints
cm.lock.Unlock()

cm.provisionRoutePool(newRoute)
return nil
}

// RemoveBlueprint removes a route blueprint.
Expand Down Expand Up @@ -928,16 +929,6 @@ func (entry *routeBackendEntry) BuildMapAssociations(route *routev1.Route) {
}
}

// validateBlueprintRoute runs extended validation on a blueprint route.
func validateBlueprintRoute(route *routev1.Route) error {
if errs := routeapihelpers.ExtendedValidateRoute(route); len(errs) > 0 {
agg := errs.ToAggregate()
return fmt.Errorf(agg.Error())
}

return nil
}

// buildBlueprintRoutes generates a list of blueprint routes.
func buildBlueprintRoutes(customRoutes []*routev1.Route, validate bool) []*routev1.Route {
routes := make([]*routev1.Route, 0)
Expand All @@ -961,7 +952,7 @@ func buildBlueprintRoutes(customRoutes []*routev1.Route, validate bool) []*route
dolly := r.DeepCopy()
dolly.Namespace = blueprintRoutePoolNamespace
if validate {
if err := validateBlueprintRoute(dolly); err != nil {
if err := routeapihelpers.ExtendedValidateRoute(dolly).ToAggregate(); err != nil {
glog.Errorf("Skipping blueprint route %s/%s due to invalid configuration: %v", r.Namespace, r.Name, err)
continue
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/router/template/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ type ConfigManager interface {
Initialize(router RouterInterface, certPath string)

// AddBlueprint adds a new (or replaces an existing) route blueprint.
AddBlueprint(route *routev1.Route)
AddBlueprint(route *routev1.Route) error

// RemoveBlueprint removes a route blueprint.
RemoveBlueprint(route *routev1.Route)
Expand Down

0 comments on commit f2bbf2c

Please sign in to comment.