@@ -15,6 +15,7 @@ import (
1515 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1616
1717 routeapi "github.com/openshift/origin/pkg/route/apis/route"
18+ "github.com/openshift/origin/pkg/route/apis/route/validation"
1819 templaterouter "github.com/openshift/origin/pkg/router/template"
1920 templateutil "github.com/openshift/origin/pkg/router/template/util"
2021)
@@ -119,6 +120,9 @@ type haproxyConfigManager struct {
119120 // wildcardRoutesAllowed indicates if wildcard routes are allowed.
120121 wildcardRoutesAllowed bool
121122
123+ // extendedValidation indicates if extended route validation is enabled.
124+ extendedValidation bool
125+
122126 // router is the associated template router.
123127 router templaterouter.RouterInterface
124128
@@ -154,10 +158,11 @@ func NewHAProxyConfigManager(options templaterouter.ConfigManagerOptions) *hapro
154158 return & haproxyConfigManager {
155159 connectionInfo : options .ConnectionInfo ,
156160 commitInterval : options .CommitInterval ,
157- blueprintRoutes : buildBlueprintRoutes (options .BlueprintRoutes ),
161+ blueprintRoutes : buildBlueprintRoutes (options .BlueprintRoutes , options . ExtendedValidation ),
158162 blueprintRoutePoolSize : options .BlueprintRoutePoolSize ,
159163 maxDynamicServers : options .MaxDynamicServers ,
160164 wildcardRoutesAllowed : options .WildcardRoutesAllowed ,
165+ extendedValidation : options .ExtendedValidation ,
161166 defaultCertificate : "" ,
162167
163168 client : client ,
@@ -199,6 +204,14 @@ func (cm *haproxyConfigManager) AddBlueprint(route *routeapi.Route) {
199204 newRoute .Namespace = blueprintRoutePoolNamespace
200205 newRoute .Spec .Host = ""
201206
207+ if cm .extendedValidation {
208+ if err := validateBlueprintRoute (newRoute ); err != nil {
209+ glog .Errorf ("Skipping blueprint route %s/%s due to invalid configuration: %v" ,
210+ route .Namespace , route .Name , err )
211+ return
212+ }
213+ }
214+
202215 cm .lock .Lock ()
203216 existingBlueprints := cm .blueprintRoutes
204217 cm .lock .Unlock ()
@@ -915,8 +928,18 @@ func (entry *routeBackendEntry) BuildMapAssociations(route *routeapi.Route) {
915928 }
916929}
917930
931+ // validateBlueprintRoute runs extended validation on a blueprint route.
932+ func validateBlueprintRoute (route * routeapi.Route ) error {
933+ if errs := validation .ExtendedValidateRoute (route ); len (errs ) > 0 {
934+ agg := errs .ToAggregate ()
935+ return fmt .Errorf (agg .Error ())
936+ }
937+
938+ return nil
939+ }
940+
918941// buildBlueprintRoutes generates a list of blueprint routes.
919- func buildBlueprintRoutes (customRoutes []* routeapi.Route ) []* routeapi.Route {
942+ func buildBlueprintRoutes (customRoutes []* routeapi.Route , validate bool ) []* routeapi.Route {
920943 routes := make ([]* routeapi.Route , 0 )
921944
922945 // Add in defaults based on the different route termination types.
@@ -937,6 +960,13 @@ func buildBlueprintRoutes(customRoutes []*routeapi.Route) []*routeapi.Route {
937960 for _ , r := range customRoutes {
938961 dolly := r .DeepCopy ()
939962 dolly .Namespace = blueprintRoutePoolNamespace
963+ if validate {
964+ if err := validateBlueprintRoute (dolly ); err != nil {
965+ glog .Errorf ("Skipping blueprint route %s/%s due to invalid configuration: %v" , r .Namespace , r .Name , err )
966+ continue
967+ }
968+ }
969+
940970 routes = append (routes , dolly )
941971 }
942972
0 commit comments