Refactor mirror feature
This commit is contained in:
parent
b9e944a8a6
commit
b3146354d4
14 changed files with 178 additions and 128 deletions
|
|
@ -30,6 +30,7 @@ import (
|
|||
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/authreq"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/parser"
|
||||
"k8s.io/ingress-nginx/internal/ingress/controller/config"
|
||||
ing_net "k8s.io/ingress-nginx/internal/net"
|
||||
"k8s.io/ingress-nginx/internal/runtime"
|
||||
|
|
@ -211,7 +212,7 @@ func ReadConfig(src map[string]string) config.Configuration {
|
|||
if val, ok := conf[globalAuthURL]; ok {
|
||||
delete(conf, globalAuthURL)
|
||||
|
||||
authURL, message := authreq.ParseStringToURL(val)
|
||||
authURL, message := parser.StringToURL(val)
|
||||
if authURL == nil {
|
||||
klog.Warningf("Global auth location denied - %v.", message)
|
||||
} else {
|
||||
|
|
@ -235,7 +236,7 @@ func ReadConfig(src map[string]string) config.Configuration {
|
|||
if val, ok := conf[globalAuthSignin]; ok {
|
||||
delete(conf, globalAuthSignin)
|
||||
|
||||
signinURL, _ := authreq.ParseStringToURL(val)
|
||||
signinURL, _ := parser.StringToURL(val)
|
||||
if signinURL == nil {
|
||||
klog.Warningf("Global auth location denied - %v.", "global-auth-signin setting is undefined and will not be set")
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -180,6 +180,7 @@ var (
|
|||
"buildOpentracingForLocation": buildOpentracingForLocation,
|
||||
"shouldLoadOpentracingModule": shouldLoadOpentracingModule,
|
||||
"buildModSecurityForLocation": buildModSecurityForLocation,
|
||||
"buildMirrorLocations": buildMirrorLocations,
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -1377,3 +1378,29 @@ modsecurity_rules_file /etc/nginx/modsecurity/modsecurity.conf;
|
|||
|
||||
return buffer.String()
|
||||
}
|
||||
|
||||
func buildMirrorLocations(locs []*ingress.Location) string {
|
||||
var buffer bytes.Buffer
|
||||
|
||||
mapped := sets.String{}
|
||||
|
||||
for _, loc := range locs {
|
||||
if loc.Mirror.Source == "" || loc.Mirror.Target == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if mapped.Has(loc.Mirror.Source) {
|
||||
continue
|
||||
}
|
||||
|
||||
mapped.Insert(loc.Mirror.Source)
|
||||
buffer.WriteString(fmt.Sprintf(`location = %v {
|
||||
internal;
|
||||
proxy_pass %v;
|
||||
}
|
||||
|
||||
`, loc.Mirror.Source, loc.Mirror.Target))
|
||||
}
|
||||
|
||||
return buffer.String()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue