Remove any aliases that conflict with a hostname
Removes the alias association if an existing server with the same hostname as the alias exists. This is done to disallow any duplicate server creation when the alias annotation is provided.
This commit is contained in:
parent
62fea9aa01
commit
e12138f4dc
4 changed files with 19 additions and 9 deletions
|
@ -490,4 +490,4 @@ func buildNextUpstream(input interface{}) string {
|
|||
}
|
||||
|
||||
return strings.Join(nextUpstreamCodes, " ")
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
{{ $all := . }}
|
||||
{{ $servers := .Servers }}
|
||||
{{ $cfg := .Cfg }}
|
||||
{{ $IsIPV6Enabled := .IsIPV6Enabled }}
|
||||
{{ $healthzURI := .HealthzURI }}
|
||||
|
@ -269,7 +270,7 @@ http {
|
|||
{{ end }}
|
||||
|
||||
{{/* build the maps that will be use to validate the Whitelist */}}
|
||||
{{ range $index, $server := .Servers }}
|
||||
{{ range $index, $server := $servers }}
|
||||
{{ range $location := $server.Locations }}
|
||||
{{ $path := buildLocation $location }}
|
||||
|
||||
|
@ -288,18 +289,18 @@ http {
|
|||
|
||||
{{/* build all the required rate limit zones. Each annotation requires a dedicated zone */}}
|
||||
{{/* 1MB -> 16 thousand 64-byte states or about 8 thousand 128-byte states */}}
|
||||
{{ range $zone := (buildRateLimitZones $cfg.LimitConnZoneVariable .Servers) }}
|
||||
{{ range $zone := (buildRateLimitZones $cfg.LimitConnZoneVariable $servers) }}
|
||||
{{ $zone }}
|
||||
{{ end }}
|
||||
|
||||
{{ $backlogSize := .BacklogSize }}
|
||||
{{ range $index, $server := .Servers }}
|
||||
{{ range $index, $server := $servers }}
|
||||
server {
|
||||
server_name {{ $server.Hostname }};
|
||||
{{ template "SERVER" serverConfig $all $server }}
|
||||
{{ template "CUSTOM_ERRORS" $all }}
|
||||
}
|
||||
{{if $server.Alias }}
|
||||
{{ if $server.Alias }}
|
||||
server {
|
||||
server_name {{ $server.Alias }};
|
||||
{{ template "SERVER" serverConfig $all $server }}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -29,14 +29,13 @@ const (
|
|||
type alias struct {
|
||||
}
|
||||
|
||||
// NewParser creates a new CORS annotation parser
|
||||
// NewParser creates a new Alias annotation parser
|
||||
func NewParser() parser.IngressAnnotation {
|
||||
return alias{}
|
||||
}
|
||||
|
||||
// Parse parses the annotations contained in the ingress rule
|
||||
// used to indicate if the location/s contains a fragment of
|
||||
// configuration to be included inside the paths of the rules
|
||||
// used to add an alias to the provided hosts
|
||||
func (a alias) Parse(ing *extensions.Ingress) (interface{}, error) {
|
||||
return parser.GetStringAnnotation(annotation, ing)
|
||||
}
|
|
@ -605,6 +605,16 @@ func (ic *GenericController) getBackendServers() ([]*ingress.Backend, []*ingress
|
|||
upstreams := ic.createUpstreams(ings)
|
||||
servers := ic.createServers(ings, upstreams)
|
||||
|
||||
// If a server has a hostname equivalent to a pre-existing alias, then we remove the alias
|
||||
for _, server := range servers {
|
||||
for j, alias := range servers {
|
||||
if server.Hostname == alias.Alias {
|
||||
glog.Warningf("There is a conflict with hostname '%v' and alias of `%v`.", server.Hostname, alias.Hostname)
|
||||
servers[j].Alias = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, ingIf := range ings {
|
||||
ing := ingIf.(*extensions.Ingress)
|
||||
|
||||
|
|
Loading…
Reference in a new issue