Add header Host into mirror annotations (#8178)

This commit is contained in:
serge-r 2022-05-08 07:39:17 +07:00 committed by GitHub
parent ec1b01092e
commit 730b7408ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 2 deletions

View file

@ -18,9 +18,9 @@ package mirror
import (
"fmt"
"strings"
networking "k8s.io/api/networking/v1"
"k8s.io/ingress-nginx/internal/ingress/annotations/parser"
"k8s.io/ingress-nginx/internal/ingress/resolver"
)
@ -30,6 +30,7 @@ type Config struct {
Source string `json:"source"`
RequestBody string `json:"requestBody"`
Target string `json:"target"`
Host string `json:"host"`
}
// Equal tests for equality between two Configuration types
@ -54,6 +55,10 @@ func (m1 *Config) Equal(m2 *Config) bool {
return false
}
if m1.Host != m2.Host {
return false
}
return true
}
@ -85,5 +90,18 @@ func (a mirror) Parse(ing *networking.Ingress) (interface{}, error) {
config.Source = ""
}
config.Host, err = parser.GetStringAnnotation("mirror-host", ing)
if err != nil {
if config.Target != "" {
url, err := parser.StringToURL(config.Target)
if err != nil {
config.Host = ""
} else {
hostname := strings.Split(url.Hostname(), "$")
config.Host = hostname[0]
}
}
}
return config, nil
}