Add support for multiple alias and remove duplication of SSL certificates (#4472)
This commit is contained in:
parent
4847bb02f0
commit
8def5ef7ca
19 changed files with 190 additions and 101 deletions
|
|
@ -17,7 +17,11 @@ limitations under the License.
|
|||
package alias
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
networking "k8s.io/api/networking/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/parser"
|
||||
"k8s.io/ingress-nginx/internal/ingress/resolver"
|
||||
|
|
@ -35,5 +39,25 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
|
|||
// Parse parses the annotations contained in the ingress rule
|
||||
// used to add an alias to the provided hosts
|
||||
func (a alias) Parse(ing *networking.Ingress) (interface{}, error) {
|
||||
return parser.GetStringAnnotation("server-alias", ing)
|
||||
val, err := parser.GetStringAnnotation("server-alias", ing)
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
|
||||
aliases := sets.NewString()
|
||||
for _, alias := range strings.Split(val, ",") {
|
||||
alias = strings.TrimSpace(alias)
|
||||
if len(alias) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if !aliases.Has(alias) {
|
||||
aliases.Insert(alias)
|
||||
}
|
||||
}
|
||||
|
||||
l := aliases.List()
|
||||
sort.Strings(l)
|
||||
|
||||
return l, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
package alias
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
api "k8s.io/api/core/v1"
|
||||
|
|
@ -36,14 +37,15 @@ func TestParse(t *testing.T) {
|
|||
|
||||
testCases := []struct {
|
||||
annotations map[string]string
|
||||
expected string
|
||||
expected []string
|
||||
}{
|
||||
{map[string]string{annotation: "www.example.com"}, "www.example.com"},
|
||||
{map[string]string{annotation: "*.example.com www.example.*"}, "*.example.com www.example.*"},
|
||||
{map[string]string{annotation: `~^www\d+\.example\.com$`}, `~^www\d+\.example\.com$`},
|
||||
{map[string]string{annotation: ""}, ""},
|
||||
{map[string]string{}, ""},
|
||||
{nil, ""},
|
||||
{map[string]string{annotation: "a.com, b.com, , c.com"}, []string{"a.com", "b.com", "c.com"}},
|
||||
{map[string]string{annotation: "www.example.com"}, []string{"www.example.com"}},
|
||||
{map[string]string{annotation: "*.example.com,www.example.*"}, []string{"*.example.com", "www.example.*"}},
|
||||
{map[string]string{annotation: `~^www\d+\.example\.com$`}, []string{`~^www\d+\.example\.com$`}},
|
||||
{map[string]string{annotation: ""}, []string{}},
|
||||
{map[string]string{}, []string{}},
|
||||
{nil, []string{}},
|
||||
}
|
||||
|
||||
ing := &networking.Ingress{
|
||||
|
|
@ -57,7 +59,7 @@ func TestParse(t *testing.T) {
|
|||
for _, testCase := range testCases {
|
||||
ing.SetAnnotations(testCase.annotations)
|
||||
result, _ := ap.Parse(ing)
|
||||
if result != testCase.expected {
|
||||
if !reflect.DeepEqual(result, testCase.expected) {
|
||||
t.Errorf("expected %v but returned %v, annotations: %s", testCase.expected, result, testCase.annotations)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ const DeniedKeyName = "Denied"
|
|||
type Ingress struct {
|
||||
metav1.ObjectMeta
|
||||
BackendProtocol string
|
||||
Alias string
|
||||
Aliases []string
|
||||
BasicDigestAuth auth.Config
|
||||
Canary canary.Config
|
||||
CertificateAuth authtls.Config
|
||||
|
|
@ -124,7 +124,7 @@ type Extractor struct {
|
|||
func NewAnnotationExtractor(cfg resolver.Resolver) Extractor {
|
||||
return Extractor{
|
||||
map[string]parser.IngressAnnotation{
|
||||
"Alias": alias.NewParser(cfg),
|
||||
"Aliases": alias.NewParser(cfg),
|
||||
"BasicDigestAuth": auth.NewParser(auth.AuthDirectory, cfg),
|
||||
"Canary": canary.NewParser(cfg),
|
||||
"CertificateAuth": authtls.NewParser(cfg),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue