@@ -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,23 @@ func (entry *routeBackendEntry) BuildMapAssociations(route *routeapi.Route) {
915
928
}
916
929
}
917
930
931
+ // validateBlueprint runs extended validation on a blueprint route.
932
+ func validateBlueprintRoute (route * routeapi.Route ) error {
933
+ errs := validation .ExtendedValidateRoute (route )
934
+ if len (errs ) > 0 {
935
+ errmsg := ""
936
+ for i := 0 ; i < len (errs ); i ++ {
937
+ errmsg = errmsg + "\n - " + errs [i ].Error ()
938
+ }
939
+
940
+ return fmt .Errorf (errmsg )
941
+ }
942
+
943
+ return nil
944
+ }
945
+
918
946
// buildBlueprintRoutes generates a list of blueprint routes.
919
- func buildBlueprintRoutes (customRoutes []* routeapi.Route ) []* routeapi.Route {
947
+ func buildBlueprintRoutes (customRoutes []* routeapi.Route , validate bool ) []* routeapi.Route {
920
948
routes := make ([]* routeapi.Route , 0 )
921
949
922
950
// Add in defaults based on the different route termination types.
@@ -937,6 +965,13 @@ func buildBlueprintRoutes(customRoutes []*routeapi.Route) []*routeapi.Route {
937
965
for _ , r := range customRoutes {
938
966
dolly := r .DeepCopy ()
939
967
dolly .Namespace = blueprintRoutePoolNamespace
968
+ if validate {
969
+ if err := validateBlueprintRoute (dolly ); err != nil {
970
+ glog .Errorf ("Skipping blueprint route %s/%s due to invalid configuration: %v" , r .Namespace , r .Name , err )
971
+ continue
972
+ }
973
+ }
974
+
940
975
routes = append (routes , dolly )
941
976
}
942
977
0 commit comments