Merge pull request #3889 from Shopify/simplify-controller-annotations
Separate out annotation assignment logic
This commit is contained in:
commit
189e2db412
1 changed files with 50 additions and 99 deletions
|
@ -35,6 +35,7 @@ import (
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
|
|
||||||
"k8s.io/ingress-nginx/internal/ingress"
|
"k8s.io/ingress-nginx/internal/ingress"
|
||||||
|
"k8s.io/ingress-nginx/internal/ingress/annotations"
|
||||||
"k8s.io/ingress-nginx/internal/ingress/annotations/proxy"
|
"k8s.io/ingress-nginx/internal/ingress/annotations/proxy"
|
||||||
ngx_config "k8s.io/ingress-nginx/internal/ingress/controller/config"
|
ngx_config "k8s.io/ingress-nginx/internal/ingress/controller/config"
|
||||||
"k8s.io/ingress-nginx/internal/k8s"
|
"k8s.io/ingress-nginx/internal/k8s"
|
||||||
|
@ -464,30 +465,7 @@ func (n *NGINXController) getBackendServers(ingresses []*ingress.Ingress) ([]*in
|
||||||
loc.Port = ups.Port
|
loc.Port = ups.Port
|
||||||
loc.Service = ups.Service
|
loc.Service = ups.Service
|
||||||
loc.Ingress = ing
|
loc.Ingress = ing
|
||||||
loc.BasicDigestAuth = anns.BasicDigestAuth
|
locationApplyAnnotations(loc, anns)
|
||||||
loc.ClientBodyBufferSize = anns.ClientBodyBufferSize
|
|
||||||
loc.ConfigurationSnippet = anns.ConfigurationSnippet
|
|
||||||
loc.CorsConfig = anns.CorsConfig
|
|
||||||
loc.ExternalAuth = anns.ExternalAuth
|
|
||||||
loc.HTTP2PushPreload = anns.HTTP2PushPreload
|
|
||||||
loc.Proxy = anns.Proxy
|
|
||||||
loc.RateLimit = anns.RateLimit
|
|
||||||
loc.Redirect = anns.Redirect
|
|
||||||
loc.Rewrite = anns.Rewrite
|
|
||||||
loc.UpstreamVhost = anns.UpstreamVhost
|
|
||||||
loc.Whitelist = anns.Whitelist
|
|
||||||
loc.Denied = anns.Denied
|
|
||||||
loc.XForwardedPrefix = anns.XForwardedPrefix
|
|
||||||
loc.UsePortInRedirects = anns.UsePortInRedirects
|
|
||||||
loc.Connection = anns.Connection
|
|
||||||
loc.Logs = anns.Logs
|
|
||||||
loc.LuaRestyWAF = anns.LuaRestyWAF
|
|
||||||
loc.InfluxDB = anns.InfluxDB
|
|
||||||
loc.DefaultBackend = anns.DefaultBackend
|
|
||||||
loc.BackendProtocol = anns.BackendProtocol
|
|
||||||
loc.CustomHTTPErrors = anns.CustomHTTPErrors
|
|
||||||
loc.ModSecurity = anns.ModSecurity
|
|
||||||
loc.Satisfy = anns.Satisfy
|
|
||||||
|
|
||||||
if loc.Redirect.FromToWWW {
|
if loc.Redirect.FromToWWW {
|
||||||
server.RedirectFromToWWW = true
|
server.RedirectFromToWWW = true
|
||||||
|
@ -508,30 +486,8 @@ func (n *NGINXController) getBackendServers(ingresses []*ingress.Ingress) ([]*in
|
||||||
Service: ups.Service,
|
Service: ups.Service,
|
||||||
Port: ups.Port,
|
Port: ups.Port,
|
||||||
Ingress: ing,
|
Ingress: ing,
|
||||||
BasicDigestAuth: anns.BasicDigestAuth,
|
|
||||||
ClientBodyBufferSize: anns.ClientBodyBufferSize,
|
|
||||||
ConfigurationSnippet: anns.ConfigurationSnippet,
|
|
||||||
CorsConfig: anns.CorsConfig,
|
|
||||||
ExternalAuth: anns.ExternalAuth,
|
|
||||||
Proxy: anns.Proxy,
|
|
||||||
RateLimit: anns.RateLimit,
|
|
||||||
Redirect: anns.Redirect,
|
|
||||||
Rewrite: anns.Rewrite,
|
|
||||||
UpstreamVhost: anns.UpstreamVhost,
|
|
||||||
Whitelist: anns.Whitelist,
|
|
||||||
Denied: anns.Denied,
|
|
||||||
XForwardedPrefix: anns.XForwardedPrefix,
|
|
||||||
UsePortInRedirects: anns.UsePortInRedirects,
|
|
||||||
Connection: anns.Connection,
|
|
||||||
Logs: anns.Logs,
|
|
||||||
LuaRestyWAF: anns.LuaRestyWAF,
|
|
||||||
InfluxDB: anns.InfluxDB,
|
|
||||||
DefaultBackend: anns.DefaultBackend,
|
|
||||||
BackendProtocol: anns.BackendProtocol,
|
|
||||||
CustomHTTPErrors: anns.CustomHTTPErrors,
|
|
||||||
ModSecurity: anns.ModSecurity,
|
|
||||||
Satisfy: anns.Satisfy,
|
|
||||||
}
|
}
|
||||||
|
locationApplyAnnotations(loc, anns)
|
||||||
|
|
||||||
if loc.Redirect.FromToWWW {
|
if loc.Redirect.FromToWWW {
|
||||||
server.RedirectFromToWWW = true
|
server.RedirectFromToWWW = true
|
||||||
|
@ -968,25 +924,12 @@ func (n *NGINXController) createServers(data []*ingress.Ingress,
|
||||||
defLoc.Service = backendUpstream.Service
|
defLoc.Service = backendUpstream.Service
|
||||||
defLoc.Ingress = ing
|
defLoc.Ingress = ing
|
||||||
|
|
||||||
// customize using Ingress annotations
|
|
||||||
defLoc.Logs = anns.Logs
|
|
||||||
defLoc.BasicDigestAuth = anns.BasicDigestAuth
|
|
||||||
defLoc.ClientBodyBufferSize = anns.ClientBodyBufferSize
|
|
||||||
defLoc.ConfigurationSnippet = anns.ConfigurationSnippet
|
|
||||||
defLoc.CorsConfig = anns.CorsConfig
|
|
||||||
defLoc.ExternalAuth = anns.ExternalAuth
|
|
||||||
defLoc.Proxy = anns.Proxy
|
|
||||||
defLoc.RateLimit = anns.RateLimit
|
|
||||||
// TODO: Redirect and rewrite can affect the catch all behavior, skip for now
|
// TODO: Redirect and rewrite can affect the catch all behavior, skip for now
|
||||||
// defLoc.Redirect = anns.Redirect
|
originalRedirect := defLoc.Redirect
|
||||||
// defLoc.Rewrite = anns.Rewrite
|
originalRewrite := defLoc.Rewrite
|
||||||
defLoc.UpstreamVhost = anns.UpstreamVhost
|
locationApplyAnnotations(defLoc, anns)
|
||||||
defLoc.Whitelist = anns.Whitelist
|
defLoc.Redirect = originalRedirect
|
||||||
defLoc.Denied = anns.Denied
|
defLoc.Rewrite = originalRewrite
|
||||||
defLoc.LuaRestyWAF = anns.LuaRestyWAF
|
|
||||||
defLoc.InfluxDB = anns.InfluxDB
|
|
||||||
defLoc.BackendProtocol = anns.BackendProtocol
|
|
||||||
defLoc.ModSecurity = anns.ModSecurity
|
|
||||||
} else {
|
} else {
|
||||||
klog.V(3).Infof("Ingress %q defines both a backend and rules. Using its backend as default upstream for all its rules.",
|
klog.V(3).Infof("Ingress %q defines both a backend and rules. Using its backend as default upstream for all its rules.",
|
||||||
ingKey)
|
ingKey)
|
||||||
|
@ -1004,37 +947,18 @@ func (n *NGINXController) createServers(data []*ingress.Ingress,
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
servers[host] = &ingress.Server{
|
loc := &ingress.Location{
|
||||||
Hostname: host,
|
|
||||||
Locations: []*ingress.Location{
|
|
||||||
{
|
|
||||||
Path: rootLocation,
|
Path: rootLocation,
|
||||||
IsDefBackend: true,
|
IsDefBackend: true,
|
||||||
Backend: un,
|
Backend: un,
|
||||||
Service: &apiv1.Service{},
|
Service: &apiv1.Service{},
|
||||||
BasicDigestAuth: anns.BasicDigestAuth,
|
}
|
||||||
ClientBodyBufferSize: anns.ClientBodyBufferSize,
|
locationApplyAnnotations(loc, anns)
|
||||||
ConfigurationSnippet: anns.ConfigurationSnippet,
|
|
||||||
CorsConfig: anns.CorsConfig,
|
servers[host] = &ingress.Server{
|
||||||
ExternalAuth: anns.ExternalAuth,
|
Hostname: host,
|
||||||
Proxy: anns.Proxy,
|
Locations: []*ingress.Location{
|
||||||
RateLimit: anns.RateLimit,
|
loc,
|
||||||
Redirect: anns.Redirect,
|
|
||||||
Rewrite: anns.Rewrite,
|
|
||||||
UpstreamVhost: anns.UpstreamVhost,
|
|
||||||
Whitelist: anns.Whitelist,
|
|
||||||
Denied: anns.Denied,
|
|
||||||
XForwardedPrefix: anns.XForwardedPrefix,
|
|
||||||
UsePortInRedirects: anns.UsePortInRedirects,
|
|
||||||
Connection: anns.Connection,
|
|
||||||
Logs: anns.Logs,
|
|
||||||
LuaRestyWAF: anns.LuaRestyWAF,
|
|
||||||
InfluxDB: anns.InfluxDB,
|
|
||||||
DefaultBackend: anns.DefaultBackend,
|
|
||||||
BackendProtocol: anns.BackendProtocol,
|
|
||||||
CustomHTTPErrors: anns.CustomHTTPErrors,
|
|
||||||
ModSecurity: anns.ModSecurity,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
SSLPassthrough: anns.SSLPassthrough,
|
SSLPassthrough: anns.SSLPassthrough,
|
||||||
SSLCiphers: anns.SSLCiphers,
|
SSLCiphers: anns.SSLCiphers,
|
||||||
|
@ -1153,6 +1077,33 @@ func (n *NGINXController) createServers(data []*ingress.Ingress,
|
||||||
return servers
|
return servers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func locationApplyAnnotations(loc *ingress.Location, anns *annotations.Ingress) {
|
||||||
|
loc.BasicDigestAuth = anns.BasicDigestAuth
|
||||||
|
loc.ClientBodyBufferSize = anns.ClientBodyBufferSize
|
||||||
|
loc.ConfigurationSnippet = anns.ConfigurationSnippet
|
||||||
|
loc.CorsConfig = anns.CorsConfig
|
||||||
|
loc.ExternalAuth = anns.ExternalAuth
|
||||||
|
loc.HTTP2PushPreload = anns.HTTP2PushPreload
|
||||||
|
loc.Proxy = anns.Proxy
|
||||||
|
loc.RateLimit = anns.RateLimit
|
||||||
|
loc.Redirect = anns.Redirect
|
||||||
|
loc.Rewrite = anns.Rewrite
|
||||||
|
loc.UpstreamVhost = anns.UpstreamVhost
|
||||||
|
loc.Whitelist = anns.Whitelist
|
||||||
|
loc.Denied = anns.Denied
|
||||||
|
loc.XForwardedPrefix = anns.XForwardedPrefix
|
||||||
|
loc.UsePortInRedirects = anns.UsePortInRedirects
|
||||||
|
loc.Connection = anns.Connection
|
||||||
|
loc.Logs = anns.Logs
|
||||||
|
loc.LuaRestyWAF = anns.LuaRestyWAF
|
||||||
|
loc.InfluxDB = anns.InfluxDB
|
||||||
|
loc.DefaultBackend = anns.DefaultBackend
|
||||||
|
loc.BackendProtocol = anns.BackendProtocol
|
||||||
|
loc.CustomHTTPErrors = anns.CustomHTTPErrors
|
||||||
|
loc.ModSecurity = anns.ModSecurity
|
||||||
|
loc.Satisfy = anns.Satisfy
|
||||||
|
}
|
||||||
|
|
||||||
// OK to merge canary ingresses iff there exists one or more ingresses to potentially merge into
|
// OK to merge canary ingresses iff there exists one or more ingresses to potentially merge into
|
||||||
func nonCanaryIngressExists(ingresses []*ingress.Ingress, canaryIngresses []*ingress.Ingress) bool {
|
func nonCanaryIngressExists(ingresses []*ingress.Ingress, canaryIngresses []*ingress.Ingress) bool {
|
||||||
return len(ingresses)-len(canaryIngresses) > 0
|
return len(ingresses)-len(canaryIngresses) > 0
|
||||||
|
|
Loading…
Reference in a new issue