mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Fix validation in kubectl create ingress (#101377)
* Fix validation in kubectl create ingress Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@gmail.com> * Fix validation in kubectl create ingress Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@gmail.com>
This commit is contained in:
parent
0e05558717
commit
3dfbcbc878
@ -228,6 +228,12 @@ func (o *CreateIngressOptions) Validate() error {
|
||||
}
|
||||
}
|
||||
|
||||
for _, annotation := range o.Annotations {
|
||||
if an := strings.SplitN(annotation, "=", 2); len(an) != 2 {
|
||||
return fmt.Errorf("annotation %s is invalid and should be in format key=[value]", annotation)
|
||||
}
|
||||
}
|
||||
|
||||
if len(o.DefaultBackend) > 0 && len(strings.Split(o.DefaultBackend, ":")) != 2 {
|
||||
return fmt.Errorf("default-backend should be in format servicename:serviceport")
|
||||
}
|
||||
@ -285,8 +291,8 @@ func (o *CreateIngressOptions) createIngress() *networkingv1.Ingress {
|
||||
}
|
||||
|
||||
func (o *CreateIngressOptions) buildAnnotations() map[string]string {
|
||||
var annotations map[string]string
|
||||
annotations = make(map[string]string)
|
||||
|
||||
var annotations = make(map[string]string)
|
||||
|
||||
for _, annotation := range o.Annotations {
|
||||
an := strings.SplitN(annotation, "=", 2)
|
||||
|
@ -30,6 +30,7 @@ func TestCreateIngressValidation(t *testing.T) {
|
||||
defaultbackend string
|
||||
ingressclass string
|
||||
rules []string
|
||||
annotations []string
|
||||
expected string
|
||||
}{
|
||||
"no default backend and rule": {
|
||||
@ -49,6 +50,22 @@ func TestCreateIngressValidation(t *testing.T) {
|
||||
defaultbackend: "xpto:4444",
|
||||
expected: "",
|
||||
},
|
||||
"invalid annotation": {
|
||||
defaultbackend: "xpto:4444",
|
||||
annotations: []string{
|
||||
"key1=value1",
|
||||
"key2",
|
||||
},
|
||||
expected: "annotation key2 is invalid and should be in format key=[value]",
|
||||
},
|
||||
"valid annotations": {
|
||||
defaultbackend: "xpto:4444",
|
||||
annotations: []string{
|
||||
"key1=value1",
|
||||
"key2=",
|
||||
},
|
||||
expected: "",
|
||||
},
|
||||
"multiple conformant rules": {
|
||||
rules: []string{
|
||||
"foo.com/path*=svc:8080",
|
||||
@ -122,6 +139,7 @@ func TestCreateIngressValidation(t *testing.T) {
|
||||
DefaultBackend: tc.defaultbackend,
|
||||
Rules: tc.rules,
|
||||
IngressClass: tc.ingressclass,
|
||||
Annotations: tc.annotations,
|
||||
}
|
||||
|
||||
err := o.Validate()
|
||||
|
Loading…
Reference in New Issue
Block a user