Add status subresource to Ingress
This commit is contained in:
@@ -951,6 +951,98 @@ func TestValidateIngress(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateIngressStatusUpdate(t *testing.T) {
|
||||
defaultBackend := extensions.IngressBackend{
|
||||
ServiceName: "default-backend",
|
||||
ServicePort: util.IntOrString{Kind: util.IntstrInt, IntVal: 80},
|
||||
}
|
||||
|
||||
newValid := func() extensions.Ingress {
|
||||
return extensions.Ingress{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Namespace: api.NamespaceDefault,
|
||||
ResourceVersion: "9",
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Backend: &extensions.IngressBackend{
|
||||
ServiceName: "default-backend",
|
||||
ServicePort: util.IntOrString{Kind: util.IntstrInt, IntVal: 80},
|
||||
},
|
||||
Rules: []extensions.IngressRule{
|
||||
{
|
||||
Host: "foo.bar.com",
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
{
|
||||
Path: "/foo",
|
||||
Backend: defaultBackend,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Status: extensions.IngressStatus{
|
||||
LoadBalancer: api.LoadBalancerStatus{
|
||||
Ingress: []api.LoadBalancerIngress{
|
||||
{IP: "127.0.0.1", Hostname: "foo.bar.com"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
oldValue := newValid()
|
||||
newValue := newValid()
|
||||
newValue.Status = extensions.IngressStatus{
|
||||
LoadBalancer: api.LoadBalancerStatus{
|
||||
Ingress: []api.LoadBalancerIngress{
|
||||
{IP: "127.0.0.2", Hostname: "foo.com"},
|
||||
},
|
||||
},
|
||||
}
|
||||
invalidIP := newValid()
|
||||
invalidIP.Status = extensions.IngressStatus{
|
||||
LoadBalancer: api.LoadBalancerStatus{
|
||||
Ingress: []api.LoadBalancerIngress{
|
||||
{IP: "abcd", Hostname: "foo.com"},
|
||||
},
|
||||
},
|
||||
}
|
||||
invalidHostname := newValid()
|
||||
invalidHostname.Status = extensions.IngressStatus{
|
||||
LoadBalancer: api.LoadBalancerStatus{
|
||||
Ingress: []api.LoadBalancerIngress{
|
||||
{IP: "127.0.0.1", Hostname: "127.0.0.1"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
errs := ValidateIngressStatusUpdate(&newValue, &oldValue)
|
||||
if len(errs) != 0 {
|
||||
t.Errorf("Unexpected error %v", errs)
|
||||
}
|
||||
|
||||
errorCases := map[string]extensions.Ingress{
|
||||
"status.loadBalancer.ingress.ip: invalid value": invalidIP,
|
||||
"status.loadBalancer.ingress.hostname: invalid value": invalidHostname,
|
||||
}
|
||||
for k, v := range errorCases {
|
||||
errs := ValidateIngressStatusUpdate(&v, &oldValue)
|
||||
if len(errs) == 0 {
|
||||
t.Errorf("expected failure for %s", k)
|
||||
} else {
|
||||
s := strings.Split(k, ":")
|
||||
err := errs[0].(*errors.ValidationError)
|
||||
if err.Field != s[0] || !strings.Contains(err.Error(), s[1]) {
|
||||
t.Errorf("unexpected error: %v, expected: %s", errs[0], k)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateClusterAutoscaler(t *testing.T) {
|
||||
successCases := []extensions.ClusterAutoscaler{
|
||||
{
|
||||
|
Reference in New Issue
Block a user