@@ -15,6 +15,7 @@ import (
15
15
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16
16
17
17
routeapi "github.com/openshift/origin/pkg/route/apis/route"
18
+ "github.com/openshift/origin/pkg/route/apis/route/validation"
18
19
templaterouter "github.com/openshift/origin/pkg/router/template"
19
20
templateutil "github.com/openshift/origin/pkg/router/template/util"
20
21
)
@@ -119,6 +120,9 @@ type haproxyConfigManager struct {
119
120
// wildcardRoutesAllowed indicates if wildcard routes are allowed.
120
121
wildcardRoutesAllowed bool
121
122
123
+ // extendedValidation indicates if extended route validation is enabled.
124
+ extendedValidation bool
125
+
122
126
// router is the associated template router.
123
127
router templaterouter.RouterInterface
124
128
@@ -154,10 +158,11 @@ func NewHAProxyConfigManager(options templaterouter.ConfigManagerOptions) *hapro
154
158
return & haproxyConfigManager {
155
159
connectionInfo : options .ConnectionInfo ,
156
160
commitInterval : options .CommitInterval ,
157
- blueprintRoutes : buildBlueprintRoutes (options .BlueprintRoutes ),
161
+ blueprintRoutes : buildBlueprintRoutes (options .BlueprintRoutes , options . ExtendedValidation ),
158
162
blueprintRoutePoolSize : options .BlueprintRoutePoolSize ,
159
163
maxDynamicServers : options .MaxDynamicServers ,
160
164
wildcardRoutesAllowed : options .WildcardRoutesAllowed ,
165
+ extendedValidation : options .ExtendedValidation ,
161
166
defaultCertificate : "" ,
162
167
163
168
client : client ,
@@ -199,6 +204,14 @@ func (cm *haproxyConfigManager) AddBlueprint(route *routeapi.Route) {
199
204
newRoute .Namespace = blueprintRoutePoolNamespace
200
205
newRoute .Spec .Host = ""
201
206
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
+
202
215
cm .lock .Lock ()
203
216
existingBlueprints := cm .blueprintRoutes
204
217
cm .lock .Unlock ()
@@ -915,8 +928,18 @@ func (entry *routeBackendEntry) BuildMapAssociations(route *routeapi.Route) {
915
928
}
916
929
}
917
930
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
+
918
941
// 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 {
920
943
routes := make ([]* routeapi.Route , 0 )
921
944
922
945
// Add in defaults based on the different route termination types.
@@ -937,6 +960,13 @@ func buildBlueprintRoutes(customRoutes []*routeapi.Route) []*routeapi.Route {
937
960
for _ , r := range customRoutes {
938
961
dolly := r .DeepCopy ()
939
962
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
+
940
970
routes = append (routes , dolly )
941
971
}
942
972
0 commit comments