Add support for Server Alias in Nginx

Adds support for server alias in nginx. Adds a new annotation
which allows us to specify a server alias that will be appended
to the server name.
This commit is contained in:
Fernando Diaz 2017-08-09 22:22:54 -05:00
parent 198c926bb9
commit ac504bdbc0
8 changed files with 146 additions and 4 deletions

View file

@ -1055,19 +1055,37 @@ func (ic *GenericController) createServers(data []interface{},
}
}
// configure default location and SSL
// configure default location, alias, and SSL
for _, ingIf := range data {
ing := ingIf.(*extensions.Ingress)
if !class.IsValid(ing, ic.cfg.IngressClass, ic.cfg.DefaultIngressClass) {
continue
}
// setup server-aliases based on annotations
aliasMap := map[string]string{}
aliasAnnotation := ic.annotations.Alias(ing)
// Here we parse the annotation string in the following format:
// ingress.kubernetes.io/server-alias: "host_0:alias_0;...;host_n:alias_n"
aliases := strings.Split(aliasAnnotation, ";")
for _, alias := range aliases {
aliasParts := strings.Split(alias, ":")
if len(aliasParts) == 2 {
// aliasMap[host] = alias
aliasMap[aliasParts[0]] = aliasParts[1]
}
}
for _, rule := range ing.Spec.Rules {
host := rule.Host
if host == "" {
host = defServerName
}
// setup server aliases
servers[host].Alias = aliasMap[host]
// only add a certificate if the server does not have one previously configured
if len(ing.Spec.TLS) == 0 || servers[host].SSLCertificate != "" {
continue