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:
parent
198c926bb9
commit
ac504bdbc0
8 changed files with 146 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue