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

Refactor blueprint route validation and generate events on errors #20722

Closed
wants to merge 1 commit into from
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
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