Skip to content

Commit fc23518

Browse files
committed
Fix haproxy router config manager issue where sanitize pems don't match when
extended validation is enabled (causes a reload where none is needed). fixes bugz #1615802
1 parent 1afa797 commit fc23518

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

pkg/cmd/infra/router/template.go

+1
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ func (o *TemplateRouterOptions) Run() error {
468468
BlueprintRoutePoolSize: o.BlueprintRoutePoolSize,
469469
MaxDynamicServers: o.MaxDynamicServers,
470470
WildcardRoutesAllowed: o.AllowWildcardRoutes,
471+
ExtendedValidation: o.ExtendedValidation,
471472
}
472473
cfgManager = haproxyconfigmanager.NewHAProxyConfigManager(cmopts)
473474
if len(o.BlueprintRouteNamespace) > 0 {

pkg/router/template/configmanager/haproxy/manager.go

+37-2
Original file line numberDiff line numberDiff line change
@@ -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,23 @@ func (entry *routeBackendEntry) BuildMapAssociations(route *routeapi.Route) {
915928
}
916929
}
917930

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+
918946
// 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 {
920948
routes := make([]*routeapi.Route, 0)
921949

922950
// Add in defaults based on the different route termination types.
@@ -937,6 +965,13 @@ func buildBlueprintRoutes(customRoutes []*routeapi.Route) []*routeapi.Route {
937965
for _, r := range customRoutes {
938966
dolly := r.DeepCopy()
939967
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+
940975
routes = append(routes, dolly)
941976
}
942977

pkg/router/template/types.go

+3
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ type ConfigManagerOptions struct {
166166

167167
// WildcardRoutesAllowed indicates if wildcard routes are allowed.
168168
WildcardRoutesAllowed bool
169+
170+
// ExtendedValidation indicates if extended route validation is enabled.
171+
ExtendedValidation bool
169172
}
170173

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

0 commit comments

Comments
 (0)