Skip to content

Commit

Permalink
Merge pull request #20646 from ramr/fix-extended-validation-diffs
Browse files Browse the repository at this point in the history
Fix haproxy router config manager issue where sanitize pems cause a blueprint route to not be selected
  • Loading branch information
openshift-merge-robot authored Aug 16, 2018
2 parents a549478 + 8773471 commit e787316
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/cmd/infra/router/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ func (o *TemplateRouterOptions) Run() error {
BlueprintRoutePoolSize: o.BlueprintRoutePoolSize,
MaxDynamicServers: o.MaxDynamicServers,
WildcardRoutesAllowed: o.AllowWildcardRoutes,
ExtendedValidation: o.ExtendedValidation,
}
cfgManager = haproxyconfigmanager.NewHAProxyConfigManager(cmopts)
if len(o.BlueprintRouteNamespace) > 0 {
Expand Down
34 changes: 32 additions & 2 deletions pkg/router/template/configmanager/haproxy/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

routeapi "github.com/openshift/origin/pkg/route/apis/route"
"github.com/openshift/origin/pkg/route/apis/route/validation"
templaterouter "github.com/openshift/origin/pkg/router/template"
templateutil "github.com/openshift/origin/pkg/router/template/util"
)
Expand Down Expand Up @@ -119,6 +120,9 @@ type haproxyConfigManager struct {
// wildcardRoutesAllowed indicates if wildcard routes are allowed.
wildcardRoutesAllowed bool

// extendedValidation indicates if extended route validation is enabled.
extendedValidation bool

// router is the associated template router.
router templaterouter.RouterInterface

Expand Down Expand Up @@ -154,10 +158,11 @@ func NewHAProxyConfigManager(options templaterouter.ConfigManagerOptions) *hapro
return &haproxyConfigManager{
connectionInfo: options.ConnectionInfo,
commitInterval: options.CommitInterval,
blueprintRoutes: buildBlueprintRoutes(options.BlueprintRoutes),
blueprintRoutes: buildBlueprintRoutes(options.BlueprintRoutes, options.ExtendedValidation),
blueprintRoutePoolSize: options.BlueprintRoutePoolSize,
maxDynamicServers: options.MaxDynamicServers,
wildcardRoutesAllowed: options.WildcardRoutesAllowed,
extendedValidation: options.ExtendedValidation,
defaultCertificate: "",

client: client,
Expand Down Expand Up @@ -199,6 +204,14 @@ func (cm *haproxyConfigManager) AddBlueprint(route *routeapi.Route) {
newRoute.Namespace = blueprintRoutePoolNamespace
newRoute.Spec.Host = ""

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

cm.lock.Lock()
existingBlueprints := cm.blueprintRoutes
cm.lock.Unlock()
Expand Down Expand Up @@ -915,8 +928,18 @@ func (entry *routeBackendEntry) BuildMapAssociations(route *routeapi.Route) {
}
}

// validateBlueprintRoute runs extended validation on a blueprint route.
func validateBlueprintRoute(route *routeapi.Route) error {
if errs := validation.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 []*routeapi.Route) []*routeapi.Route {
func buildBlueprintRoutes(customRoutes []*routeapi.Route, validate bool) []*routeapi.Route {
routes := make([]*routeapi.Route, 0)

// Add in defaults based on the different route termination types.
Expand All @@ -937,6 +960,13 @@ func buildBlueprintRoutes(customRoutes []*routeapi.Route) []*routeapi.Route {
for _, r := range customRoutes {
dolly := r.DeepCopy()
dolly.Namespace = blueprintRoutePoolNamespace
if validate {
if err := validateBlueprintRoute(dolly); err != nil {
glog.Errorf("Skipping blueprint route %s/%s due to invalid configuration: %v", r.Namespace, r.Name, err)
continue
}
}

routes = append(routes, dolly)
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/router/template/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ type ConfigManagerOptions struct {

// WildcardRoutesAllowed indicates if wildcard routes are allowed.
WildcardRoutesAllowed bool

// ExtendedValidation indicates if extended route validation is enabled.
ExtendedValidation bool
}

// ConfigManager is used by the router to make configuration changes using
Expand Down

0 comments on commit e787316

Please sign in to comment.