kubectl: Add labels to ingress describe

Kubernetes-commit: 2ad2bc6844318034dd3296a0b0d5a7ce97e51962
This commit is contained in:
kabab 2021-07-24 22:56:36 +02:00 committed by Kubernetes Publisher
parent 0d2412020e
commit 3e3ae2747f
2 changed files with 27 additions and 3 deletions

View File

@ -2605,6 +2605,7 @@ func (i *IngressDescriber) describeIngressV1(ing *networkingv1.Ingress, events *
return tabbedString(func(out io.Writer) error {
w := NewPrefixWriter(out)
w.Write(LEVEL_0, "Name:\t%v\n", ing.Name)
printLabelsMultiline(w, "Labels", ing.Labels)
w.Write(LEVEL_0, "Namespace:\t%v\n", ing.Namespace)
w.Write(LEVEL_0, "Address:\t%v\n", loadBalancerStatusStringer(ing.Status.LoadBalancer, true))
def := ing.Spec.DefaultBackend
@ -2660,6 +2661,7 @@ func (i *IngressDescriber) describeIngressV1beta1(ing *networkingv1beta1.Ingress
return tabbedString(func(out io.Writer) error {
w := NewPrefixWriter(out)
w.Write(LEVEL_0, "Name:\t%v\n", ing.Name)
printLabelsMultiline(w, "Labels", ing.Labels)
w.Write(LEVEL_0, "Namespace:\t%v\n", ing.Namespace)
w.Write(LEVEL_0, "Address:\t%v\n", loadBalancerStatusStringer(ing.Status.LoadBalancer, true))
def := ing.Spec.Backend

View File

@ -2162,7 +2162,11 @@ func TestDescribeIngress(t *testing.T) {
}
v1beta1 := fake.NewSimpleClientset(&networkingv1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Name: "bar",
Labels: map[string]string{
"id1": "app1",
"id2": "app2",
},
Namespace: "foo",
},
Spec: networkingv1beta1.IngressSpec{
@ -2237,6 +2241,8 @@ func TestDescribeIngress(t *testing.T) {
"IngressRule.HTTP.Paths.Backend.Service v1beta1": {
input: v1beta1,
output: `Name: bar
Labels: id1=app1
id2=app2
Namespace: foo
Address:
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
@ -2251,6 +2257,7 @@ Events: <none>` + "\n",
"IngressRule.HTTP.Paths.Backend.Service v1": {
input: netv1,
output: `Name: bar
Labels: <none>
Namespace: foo
Address:
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
@ -2287,6 +2294,7 @@ Events: <none>` + "\n",
},
}),
output: `Name: bar
Labels: <none>
Namespace: foo
Address:
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
@ -2323,6 +2331,7 @@ Events: <none>` + "\n",
},
}),
output: `Name: bar
Labels: <none>
Namespace: foo
Address:
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
@ -2360,6 +2369,7 @@ Events: <none>` + "\n",
},
}),
output: `Name: bar
Labels: <none>
Namespace: foo
Address:
Default backend: default-backend:80 (<error: endpoints "default-backend" not found>)
@ -2397,6 +2407,7 @@ Events: <none>` + "\n",
},
}),
output: `Name: bar
Labels: <none>
Namespace: foo
Address:
Default backend: APIGroup: example.com, Kind: foo, Name: bar
@ -2434,6 +2445,7 @@ Events: <none>` + "\n",
},
}),
output: `Name: bar
Labels: <none>
Namespace: foo
Address:
Default backend: APIGroup: example.com, Kind: foo, Name: bar
@ -2456,6 +2468,7 @@ Events: <none>` + "\n",
},
}),
output: `Name: bar
Labels: <none>
Namespace: foo
Address:
Default backend: default-backend:80 (<error: endpoints "default-backend" not found>)
@ -2498,7 +2511,11 @@ func TestDescribeIngressV1(t *testing.T) {
fakeClient := fake.NewSimpleClientset(&networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Name: "bar",
Labels: map[string]string{
"id1": "app1",
"id2": "app2",
},
Namespace: "foo",
},
Spec: networkingv1.IngressSpec{
@ -2524,7 +2541,12 @@ func TestDescribeIngressV1(t *testing.T) {
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if !strings.Contains(out, "bar") || !strings.Contains(out, "foo") || !strings.Contains(out, "foo.bar.com") || !strings.Contains(out, "/foo") {
if !strings.Contains(out, "bar") ||
!strings.Contains(out, "foo") ||
!strings.Contains(out, "foo.bar.com") ||
!strings.Contains(out, "/foo") ||
!strings.Contains(out, "app1") ||
!strings.Contains(out, "app2") {
t.Errorf("unexpected out: %s", out)
}
}