Merge pull request #107921 from mpuckett159/feature/show-ingress-class

Add Ingress Class to kubectl describe ingress output
This commit is contained in:
Kubernetes Prow Robot 2022-02-10 11:57:28 -08:00 committed by GitHub
commit 3866cb91f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 4 deletions

View File

@ -2630,6 +2630,11 @@ func (i *IngressDescriber) describeIngressV1(ing *networkingv1.Ingress, events *
printLabelsMultiline(w, "Labels", ing.Labels) printLabelsMultiline(w, "Labels", ing.Labels)
w.Write(LEVEL_0, "Namespace:\t%v\n", ing.Namespace) w.Write(LEVEL_0, "Namespace:\t%v\n", ing.Namespace)
w.Write(LEVEL_0, "Address:\t%v\n", loadBalancerStatusStringer(ing.Status.LoadBalancer, true)) w.Write(LEVEL_0, "Address:\t%v\n", loadBalancerStatusStringer(ing.Status.LoadBalancer, true))
ingressClassName := "<none>"
if ing.Spec.IngressClassName != nil {
ingressClassName = *ing.Spec.IngressClassName
}
w.Write(LEVEL_0, "Ingress Class:\t%v\n", ingressClassName)
def := ing.Spec.DefaultBackend def := ing.Spec.DefaultBackend
ns := ing.Namespace ns := ing.Namespace
if def == nil { if def == nil {
@ -2686,6 +2691,11 @@ func (i *IngressDescriber) describeIngressV1beta1(ing *networkingv1beta1.Ingress
printLabelsMultiline(w, "Labels", ing.Labels) printLabelsMultiline(w, "Labels", ing.Labels)
w.Write(LEVEL_0, "Namespace:\t%v\n", ing.Namespace) w.Write(LEVEL_0, "Namespace:\t%v\n", ing.Namespace)
w.Write(LEVEL_0, "Address:\t%v\n", loadBalancerStatusStringer(ing.Status.LoadBalancer, true)) w.Write(LEVEL_0, "Address:\t%v\n", loadBalancerStatusStringer(ing.Status.LoadBalancer, true))
ingressClassName := "<none>"
if ing.Spec.IngressClassName != nil {
ingressClassName = *ing.Spec.IngressClassName
}
w.Write(LEVEL_0, "Ingress Class:\t%v\n", ingressClassName)
def := ing.Spec.Backend def := ing.Spec.Backend
ns := ing.Namespace ns := ing.Namespace
if def == nil { if def == nil {

View File

@ -2257,7 +2257,7 @@ func TestDescribeJob(t *testing.T) {
if !strings.Contains(out, fmt.Sprintf("Completed Indexes: %s\n", tc.wantCompletedIndexes)) { if !strings.Contains(out, fmt.Sprintf("Completed Indexes: %s\n", tc.wantCompletedIndexes)) {
t.Errorf("Output didn't contain wanted Completed Indexes:\n%s", out) t.Errorf("Output didn't contain wanted Completed Indexes:\n%s", out)
} }
} else if strings.Contains(out, fmt.Sprintf("Completed Indexes:")) { } else if strings.Contains(out, "Completed Indexes:") {
t.Errorf("Output contains unexpected completed indexes:\n%s", out) t.Errorf("Output contains unexpected completed indexes:\n%s", out)
} }
}) })
@ -2265,6 +2265,7 @@ func TestDescribeJob(t *testing.T) {
} }
func TestDescribeIngress(t *testing.T) { func TestDescribeIngress(t *testing.T) {
ingresClassName := "test"
backendV1beta1 := networkingv1beta1.IngressBackend{ backendV1beta1 := networkingv1beta1.IngressBackend{
ServiceName: "default-backend", ServiceName: "default-backend",
ServicePort: intstr.FromInt(80), ServicePort: intstr.FromInt(80),
@ -2279,6 +2280,7 @@ func TestDescribeIngress(t *testing.T) {
Namespace: "foo", Namespace: "foo",
}, },
Spec: networkingv1beta1.IngressSpec{ Spec: networkingv1beta1.IngressSpec{
IngressClassName: &ingresClassName,
Rules: []networkingv1beta1.IngressRule{ Rules: []networkingv1beta1.IngressRule{
{ {
Host: "foo.bar.com", Host: "foo.bar.com",
@ -2311,6 +2313,7 @@ func TestDescribeIngress(t *testing.T) {
Namespace: "foo", Namespace: "foo",
}, },
Spec: networkingv1.IngressSpec{ Spec: networkingv1.IngressSpec{
IngressClassName: &ingresClassName,
Rules: []networkingv1.IngressRule{ Rules: []networkingv1.IngressRule{
{ {
Host: "foo.bar.com", Host: "foo.bar.com",
@ -2354,6 +2357,7 @@ Labels: id1=app1
id2=app2 id2=app2
Namespace: foo Namespace: foo
Address: Address:
Ingress Class: test
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>) Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules: Rules:
Host Path Backends Host Path Backends
@ -2369,6 +2373,7 @@ Events: <none>` + "\n",
Labels: <none> Labels: <none>
Namespace: foo Namespace: foo
Address: Address:
Ingress Class: test
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>) Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules: Rules:
Host Path Backends Host Path Backends
@ -2385,6 +2390,7 @@ Events: <none>` + "\n",
Namespace: "foo", Namespace: "foo",
}, },
Spec: networkingv1.IngressSpec{ Spec: networkingv1.IngressSpec{
IngressClassName: &ingresClassName,
Rules: []networkingv1.IngressRule{ Rules: []networkingv1.IngressRule{
{ {
Host: "foo.bar.com", Host: "foo.bar.com",
@ -2406,6 +2412,7 @@ Events: <none>` + "\n",
Labels: <none> Labels: <none>
Namespace: foo Namespace: foo
Address: Address:
Ingress Class: test
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>) Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules: Rules:
Host Path Backends Host Path Backends
@ -2422,6 +2429,7 @@ Events: <none>` + "\n",
Namespace: "foo", Namespace: "foo",
}, },
Spec: networkingv1.IngressSpec{ Spec: networkingv1.IngressSpec{
IngressClassName: &ingresClassName,
Rules: []networkingv1.IngressRule{ Rules: []networkingv1.IngressRule{
{ {
Host: "foo.bar.com", Host: "foo.bar.com",
@ -2443,6 +2451,7 @@ Events: <none>` + "\n",
Labels: <none> Labels: <none>
Namespace: foo Namespace: foo
Address: Address:
Ingress Class: test
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>) Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules: Rules:
Host Path Backends Host Path Backends
@ -2460,6 +2469,7 @@ Events: <none>` + "\n",
}, },
Spec: networkingv1.IngressSpec{ Spec: networkingv1.IngressSpec{
DefaultBackend: &backendV1, DefaultBackend: &backendV1,
IngressClassName: &ingresClassName,
Rules: []networkingv1.IngressRule{ Rules: []networkingv1.IngressRule{
{ {
Host: "foo.bar.com", Host: "foo.bar.com",
@ -2481,6 +2491,7 @@ Events: <none>` + "\n",
Labels: <none> Labels: <none>
Namespace: foo Namespace: foo
Address: Address:
Ingress Class: test
Default backend: default-backend:80 (<error: endpoints "default-backend" not found>) Default backend: default-backend:80 (<error: endpoints "default-backend" not found>)
Rules: Rules:
Host Path Backends Host Path Backends
@ -2498,6 +2509,7 @@ Events: <none>` + "\n",
}, },
Spec: networkingv1.IngressSpec{ Spec: networkingv1.IngressSpec{
DefaultBackend: &backendResource, DefaultBackend: &backendResource,
IngressClassName: &ingresClassName,
Rules: []networkingv1.IngressRule{ Rules: []networkingv1.IngressRule{
{ {
Host: "foo.bar.com", Host: "foo.bar.com",
@ -2519,6 +2531,7 @@ Events: <none>` + "\n",
Labels: <none> Labels: <none>
Namespace: foo Namespace: foo
Address: Address:
Ingress Class: test
Default backend: APIGroup: example.com, Kind: foo, Name: bar Default backend: APIGroup: example.com, Kind: foo, Name: bar
Rules: Rules:
Host Path Backends Host Path Backends
@ -2536,6 +2549,7 @@ Events: <none>` + "\n",
}, },
Spec: networkingv1.IngressSpec{ Spec: networkingv1.IngressSpec{
DefaultBackend: &backendResource, DefaultBackend: &backendResource,
IngressClassName: &ingresClassName,
Rules: []networkingv1.IngressRule{ Rules: []networkingv1.IngressRule{
{ {
Host: "foo.bar.com", Host: "foo.bar.com",
@ -2557,6 +2571,7 @@ Events: <none>` + "\n",
Labels: <none> Labels: <none>
Namespace: foo Namespace: foo
Address: Address:
Ingress Class: test
Default backend: APIGroup: example.com, Kind: foo, Name: bar Default backend: APIGroup: example.com, Kind: foo, Name: bar
Rules: Rules:
Host Path Backends Host Path Backends
@ -2574,12 +2589,38 @@ Events: <none>` + "\n",
}, },
Spec: networkingv1.IngressSpec{ Spec: networkingv1.IngressSpec{
DefaultBackend: &backendV1, DefaultBackend: &backendV1,
IngressClassName: &ingresClassName,
}, },
}), }),
output: `Name: bar output: `Name: bar
Labels: <none> Labels: <none>
Namespace: foo Namespace: foo
Address: Address:
Ingress Class: test
Default backend: default-backend:80 (<error: endpoints "default-backend" not found>)
Rules:
Host Path Backends
---- ---- --------
* * default-backend:80 (<error: endpoints "default-backend" not found>)
Annotations: <none>
Events: <none>
`,
},
"EmptyIngressClassName": {
input: fake.NewSimpleClientset(&networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "foo",
},
Spec: networkingv1.IngressSpec{
DefaultBackend: &backendV1,
},
}),
output: `Name: bar
Labels: <none>
Namespace: foo
Address:
Ingress Class: <none>
Default backend: default-backend:80 (<error: endpoints "default-backend" not found>) Default backend: default-backend:80 (<error: endpoints "default-backend" not found>)
Rules: Rules:
Host Path Backends Host Path Backends
@ -2609,6 +2650,7 @@ Events: <none>
} }
func TestDescribeIngressV1(t *testing.T) { func TestDescribeIngressV1(t *testing.T) {
ingresClassName := "test"
defaultBackend := networkingv1.IngressBackend{ defaultBackend := networkingv1.IngressBackend{
Service: &networkingv1.IngressServiceBackend{ Service: &networkingv1.IngressServiceBackend{
Name: "default-backend", Name: "default-backend",
@ -2628,6 +2670,7 @@ func TestDescribeIngressV1(t *testing.T) {
Namespace: "foo", Namespace: "foo",
}, },
Spec: networkingv1.IngressSpec{ Spec: networkingv1.IngressSpec{
IngressClassName: &ingresClassName,
Rules: []networkingv1.IngressRule{ Rules: []networkingv1.IngressRule{
{ {
Host: "foo.bar.com", Host: "foo.bar.com",