Add prefix nginx to annotations
This commit is contained in:
parent
97577c07a5
commit
8f1ff15a6e
54 changed files with 445 additions and 441 deletions
|
|
@ -22,6 +22,7 @@ import (
|
|||
extensions "k8s.io/api/extensions/v1beta1"
|
||||
|
||||
"k8s.io/ingress-nginx/internal/ingress/errors"
|
||||
"k8s.io/ingress-nginx/internal/ingress/resolver"
|
||||
)
|
||||
|
||||
// IngressAnnotation has a method to parse annotations located in Ingress
|
||||
|
|
@ -75,28 +76,31 @@ func checkAnnotation(name string, ing *extensions.Ingress) error {
|
|||
}
|
||||
|
||||
// GetBoolAnnotation extracts a boolean from an Ingress annotation
|
||||
func GetBoolAnnotation(name string, ing *extensions.Ingress) (bool, error) {
|
||||
err := checkAnnotation(name, ing)
|
||||
func GetBoolAnnotation(name string, ing *extensions.Ingress, r resolver.Resolver) (bool, error) {
|
||||
v := r.GetAnnotationWithPrefix(name)
|
||||
err := checkAnnotation(v, ing)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return ingAnnotations(ing.GetAnnotations()).parseBool(name)
|
||||
return ingAnnotations(ing.GetAnnotations()).parseBool(v)
|
||||
}
|
||||
|
||||
// GetStringAnnotation extracts a string from an Ingress annotation
|
||||
func GetStringAnnotation(name string, ing *extensions.Ingress) (string, error) {
|
||||
err := checkAnnotation(name, ing)
|
||||
func GetStringAnnotation(name string, ing *extensions.Ingress, r resolver.Resolver) (string, error) {
|
||||
v := r.GetAnnotationWithPrefix(name)
|
||||
err := checkAnnotation(v, ing)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return ingAnnotations(ing.GetAnnotations()).parseString(name)
|
||||
return ingAnnotations(ing.GetAnnotations()).parseString(v)
|
||||
}
|
||||
|
||||
// GetIntAnnotation extracts an int from an Ingress annotation
|
||||
func GetIntAnnotation(name string, ing *extensions.Ingress) (int, error) {
|
||||
err := checkAnnotation(name, ing)
|
||||
func GetIntAnnotation(name string, ing *extensions.Ingress, r resolver.Resolver) (int, error) {
|
||||
v := r.GetAnnotationWithPrefix(name)
|
||||
err := checkAnnotation(v, ing)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return ingAnnotations(ing.GetAnnotations()).parseInt(name)
|
||||
return ingAnnotations(ing.GetAnnotations()).parseInt(v)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,11 +17,13 @@ limitations under the License.
|
|||
package parser
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
api "k8s.io/api/core/v1"
|
||||
extensions "k8s.io/api/extensions/v1beta1"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/ingress-nginx/internal/ingress/resolver"
|
||||
)
|
||||
|
||||
func buildIngress() *extensions.Ingress {
|
||||
|
|
@ -35,9 +37,11 @@ func buildIngress() *extensions.Ingress {
|
|||
}
|
||||
|
||||
func TestGetBoolAnnotation(t *testing.T) {
|
||||
r := &resolver.Mock{}
|
||||
|
||||
ing := buildIngress()
|
||||
|
||||
_, err := GetBoolAnnotation("", nil)
|
||||
_, err := GetBoolAnnotation("", nil, r)
|
||||
if err == nil {
|
||||
t.Errorf("expected error but retuned nil")
|
||||
}
|
||||
|
|
@ -49,8 +53,6 @@ func TestGetBoolAnnotation(t *testing.T) {
|
|||
exp bool
|
||||
expErr bool
|
||||
}{
|
||||
{"empty - false", "", "false", false, true},
|
||||
{"empty - true", "", "true", false, true},
|
||||
{"valid - false", "bool", "false", false, false},
|
||||
{"valid - true", "bool", "true", true, false},
|
||||
}
|
||||
|
|
@ -59,9 +61,9 @@ func TestGetBoolAnnotation(t *testing.T) {
|
|||
ing.SetAnnotations(data)
|
||||
|
||||
for _, test := range tests {
|
||||
data[test.field] = test.value
|
||||
data[fmt.Sprintf("nginx/%v", test.field)] = test.value
|
||||
|
||||
u, err := GetBoolAnnotation(test.field, ing)
|
||||
u, err := GetBoolAnnotation(test.field, ing, r)
|
||||
if test.expErr {
|
||||
if err == nil {
|
||||
t.Errorf("%v: expected error but retuned nil", test.name)
|
||||
|
|
@ -77,9 +79,11 @@ func TestGetBoolAnnotation(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetStringAnnotation(t *testing.T) {
|
||||
r := &resolver.Mock{}
|
||||
|
||||
ing := buildIngress()
|
||||
|
||||
_, err := GetStringAnnotation("", nil)
|
||||
_, err := GetStringAnnotation("", nil, r)
|
||||
if err == nil {
|
||||
t.Errorf("expected error but retuned nil")
|
||||
}
|
||||
|
|
@ -91,8 +95,6 @@ func TestGetStringAnnotation(t *testing.T) {
|
|||
exp string
|
||||
expErr bool
|
||||
}{
|
||||
{"empty - A", "", "A", "", true},
|
||||
{"empty - B", "", "B", "", true},
|
||||
{"valid - A", "string", "A", "A", false},
|
||||
{"valid - B", "string", "B", "B", false},
|
||||
}
|
||||
|
|
@ -101,9 +103,9 @@ func TestGetStringAnnotation(t *testing.T) {
|
|||
ing.SetAnnotations(data)
|
||||
|
||||
for _, test := range tests {
|
||||
data[test.field] = test.value
|
||||
data[fmt.Sprintf("nginx/%v", test.field)] = test.value
|
||||
|
||||
s, err := GetStringAnnotation(test.field, ing)
|
||||
s, err := GetStringAnnotation(test.field, ing, r)
|
||||
if test.expErr {
|
||||
if err == nil {
|
||||
t.Errorf("%v: expected error but retuned nil", test.name)
|
||||
|
|
@ -119,9 +121,11 @@ func TestGetStringAnnotation(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetIntAnnotation(t *testing.T) {
|
||||
r := &resolver.Mock{}
|
||||
|
||||
ing := buildIngress()
|
||||
|
||||
_, err := GetIntAnnotation("", nil)
|
||||
_, err := GetIntAnnotation("", nil, r)
|
||||
if err == nil {
|
||||
t.Errorf("expected error but retuned nil")
|
||||
}
|
||||
|
|
@ -133,8 +137,6 @@ func TestGetIntAnnotation(t *testing.T) {
|
|||
exp int
|
||||
expErr bool
|
||||
}{
|
||||
{"empty - A", "", "1", 0, true},
|
||||
{"empty - B", "", "2", 0, true},
|
||||
{"valid - A", "string", "1", 1, false},
|
||||
{"valid - B", "string", "2", 2, false},
|
||||
}
|
||||
|
|
@ -143,9 +145,9 @@ func TestGetIntAnnotation(t *testing.T) {
|
|||
ing.SetAnnotations(data)
|
||||
|
||||
for _, test := range tests {
|
||||
data[test.field] = test.value
|
||||
data[fmt.Sprintf("nginx/%v", test.field)] = test.value
|
||||
|
||||
s, err := GetIntAnnotation(test.field, ing)
|
||||
s, err := GetIntAnnotation(test.field, ing, r)
|
||||
if test.expErr {
|
||||
if err == nil {
|
||||
t.Errorf("%v: expected error but retuned nil", test.name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue