Skip to content

Commit

Permalink
Allow routes from certain domains (ala defaulted domains) to be repla…
Browse files Browse the repository at this point in the history
…ced with

the subdomain/hostname-template the router environment is running under.
Fixes issue openshift#16797
  • Loading branch information
ramr committed Apr 13, 2018
1 parent fedbc3b commit 61938aa
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/cmd/infra/router/router.go
Expand Up @@ -35,6 +35,8 @@ type RouterSelection struct {

HostnameTemplate string
OverrideHostname bool
OverrideDomains []string
RedactedDomains sets.String

LabelSelector string
FieldSelector string
Expand Down Expand Up @@ -71,6 +73,7 @@ func (o *RouterSelection) Bind(flag *pflag.FlagSet) {
flag.DurationVar(&o.ResyncInterval, "resync-interval", controllerfactory.DefaultResyncInterval, "The interval at which the route list should be fully refreshed")
flag.StringVar(&o.HostnameTemplate, "hostname-template", cmdutil.Env("ROUTER_SUBDOMAIN", ""), "If specified, a template that should be used to generate the hostname for a route without spec.host (e.g. '${name}-${namespace}.myapps.mycompany.com')")
flag.BoolVar(&o.OverrideHostname, "override-hostname", isTrue(cmdutil.Env("ROUTER_OVERRIDE_HOSTNAME", "")), "Override the spec.host value for a route with --hostname-template")
flag.StringSliceVar(&o.OverrideDomains, "override-domains", envVarAsStrings("ROUTER_OVERRIDE_DOMAINS", "", ","), "List of comma separated domains to override if present in any routes")
flag.StringVar(&o.LabelSelector, "labels", cmdutil.Env("ROUTE_LABELS", ""), "A label selector to apply to the routes to watch")
flag.StringVar(&o.FieldSelector, "fields", cmdutil.Env("ROUTE_FIELDS", ""), "A field selector to apply to routes to watch")
flag.StringVar(&o.ProjectLabelSelector, "project-labels", cmdutil.Env("PROJECT_LABELS", ""), "A label selector to apply to projects to watch; if '*' watches all projects the client can access")
Expand All @@ -92,7 +95,7 @@ func (o *RouterSelection) RouteSelectionFunc() controller.RouteHostFunc {
return controller.HostForRoute
}
return func(route *routeapi.Route) string {
if !o.OverrideHostname && len(route.Spec.Host) > 0 {
if !o.OverrideHostname && len(route.Spec.Host) > 0 && !hostInDomainList(route.Spec.Host, o.RedactedDomains) {
return route.Spec.Host
}
s, err := variable.ExpandStrict(o.HostnameTemplate, func(key string) (string, bool) {
Expand Down Expand Up @@ -165,6 +168,12 @@ func (o *RouterSelection) Complete() error {
if len(o.HostnameTemplate) == 0 && o.OverrideHostname {
return fmt.Errorf("--override-hostname requires that --hostname-template be specified")
}

o.RedactedDomains = sets.NewString(o.OverrideDomains...)
if len(o.RedactedDomains) > 0 && len(o.HostnameTemplate) == 0 {
return fmt.Errorf("--override-domains requires that --hostname-template be specified")
}

if len(o.LabelSelector) > 0 {
if _, err := labels.Parse(o.LabelSelector); err != nil {
return fmt.Errorf("label selector is not valid: %v", err)
Expand Down

0 comments on commit 61938aa

Please sign in to comment.