mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #19460 from bprashanth/kubectl_desc_ing
Auto commit by PR queue bot
This commit is contained in:
		@@ -1029,55 +1029,60 @@ func (i *IngressDescriber) Describe(namespace, name string) (string, error) {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return "", err
 | 
							return "", err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	events, _ := i.Events(namespace).Search(ing)
 | 
						return i.describeIngress(ing)
 | 
				
			||||||
	endpoints, _ := i.Endpoints(namespace).Get(ing.Spec.Backend.ServiceName)
 | 
					 | 
				
			||||||
	service, _ := i.Services(namespace).Get(ing.Spec.Backend.ServiceName)
 | 
					 | 
				
			||||||
	return describeIngress(ing, endpoints, service, events)
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func describeIngressEndpoints(out io.Writer, ing *extensions.Ingress, endpoints *api.Endpoints, service *api.Service) {
 | 
					func (i *IngressDescriber) describeBackend(ns string, backend *extensions.IngressBackend) string {
 | 
				
			||||||
 | 
						endpoints, _ := i.Endpoints(ns).Get(backend.ServiceName)
 | 
				
			||||||
 | 
						service, _ := i.Services(ns).Get(backend.ServiceName)
 | 
				
			||||||
	spName := ""
 | 
						spName := ""
 | 
				
			||||||
	for i := range service.Spec.Ports {
 | 
						for i := range service.Spec.Ports {
 | 
				
			||||||
		sp := &service.Spec.Ports[i]
 | 
							sp := &service.Spec.Ports[i]
 | 
				
			||||||
		switch ing.Spec.Backend.ServicePort.Type {
 | 
							switch backend.ServicePort.Type {
 | 
				
			||||||
		case intstr.String:
 | 
							case intstr.String:
 | 
				
			||||||
			if ing.Spec.Backend.ServicePort.StrVal == sp.Name {
 | 
								if backend.ServicePort.StrVal == sp.Name {
 | 
				
			||||||
				spName = sp.Name
 | 
									spName = sp.Name
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		case intstr.Int:
 | 
							case intstr.Int:
 | 
				
			||||||
			if int(ing.Spec.Backend.ServicePort.IntVal) == sp.Port {
 | 
								if int(backend.ServicePort.IntVal) == sp.Port {
 | 
				
			||||||
				spName = sp.Name
 | 
									spName = sp.Name
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						return formatEndpoints(endpoints, sets.NewString(spName))
 | 
				
			||||||
	fmt.Fprintf(out, "Endpoints:\t%s\n", formatEndpoints(endpoints, sets.NewString(spName)))
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func describeIngress(ing *extensions.Ingress, endpoints *api.Endpoints, service *api.Service, events *api.EventList) (string, error) {
 | 
					func (i *IngressDescriber) describeIngress(ing *extensions.Ingress) (string, error) {
 | 
				
			||||||
	return tabbedString(func(out io.Writer) error {
 | 
						return tabbedString(func(out io.Writer) error {
 | 
				
			||||||
		fmt.Fprintf(out, "Name:\t%s\n", ing.Name)
 | 
							fmt.Fprintf(out, "Name:\t%v\n", ing.Name)
 | 
				
			||||||
		fmt.Fprintf(out, "Namespace:\t%s\n", ing.Namespace)
 | 
							fmt.Fprintf(out, "Namespace:\t%v\n", ing.Namespace)
 | 
				
			||||||
		fmt.Fprintf(out, "Labels:\t%s\n", labels.FormatLabels(ing.Labels))
 | 
							fmt.Fprintf(out, "Address:\t%v\n", loadBalancerStatusStringer(ing.Status.LoadBalancer))
 | 
				
			||||||
 | 
							def := ing.Spec.Backend
 | 
				
			||||||
		fmt.Fprintf(out, "Rules:\n")
 | 
							ns := ing.Namespace
 | 
				
			||||||
 | 
							if def == nil {
 | 
				
			||||||
 | 
								// Ingresses that don't specify a default backend inherit the
 | 
				
			||||||
 | 
								// default backend in the kube-system namespace.
 | 
				
			||||||
 | 
								def = &extensions.IngressBackend{
 | 
				
			||||||
 | 
									ServiceName: "default-http-backend",
 | 
				
			||||||
 | 
									ServicePort: intstr.IntOrString{Type: intstr.Int, IntVal: 80},
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								ns = api.NamespaceSystem
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							fmt.Fprintf(out, "Default backend:\t%s (%s)\n", backendStringer(def), i.describeBackend(ns, def))
 | 
				
			||||||
 | 
							fmt.Fprint(out, "Rules:\n  Host\tPath\tBackends\n")
 | 
				
			||||||
 | 
							fmt.Fprint(out, "  ----\t----\t--------\n")
 | 
				
			||||||
		for _, rules := range ing.Spec.Rules {
 | 
							for _, rules := range ing.Spec.Rules {
 | 
				
			||||||
			if rules.HTTP == nil {
 | 
								if rules.HTTP == nil {
 | 
				
			||||||
				continue
 | 
									continue
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								fmt.Fprintf(out, "  %s\t\n", rules.Host)
 | 
				
			||||||
			fmt.Fprintf(out, "  Host\tPath\tBackend\n")
 | 
					 | 
				
			||||||
			fmt.Fprintf(out, "  ----\t----\t--------\n")
 | 
					 | 
				
			||||||
			for _, path := range rules.HTTP.Paths {
 | 
								for _, path := range rules.HTTP.Paths {
 | 
				
			||||||
				fmt.Fprintf(out, "  %s\t%s\t%s\n", rules.Host, path.Path, backendStringer(&path.Backend))
 | 
									fmt.Fprintf(out, "    \t%s \t%s (%s)\n", path.Path, backendStringer(&path.Backend), i.describeBackend(ing.Namespace, &path.Backend))
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					 | 
				
			||||||
		fmt.Fprintf(out, "Backend:\t%v\t%v\n", backendStringer(ing.Spec.Backend),
 | 
					 | 
				
			||||||
			loadBalancerStatusStringer(ing.Status.LoadBalancer))
 | 
					 | 
				
			||||||
		describeIngressEndpoints(out, ing, endpoints, service)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		describeIngressAnnotations(out, ing.Annotations)
 | 
							describeIngressAnnotations(out, ing.Annotations)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							events, _ := i.Events(ing.Namespace).Search(ing)
 | 
				
			||||||
		if events != nil {
 | 
							if events != nil {
 | 
				
			||||||
			DescribeEvents(events, out)
 | 
								DescribeEvents(events, out)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -1094,7 +1099,7 @@ func describeIngressAnnotations(out io.Writer, annotations map[string]string) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		parts := strings.Split(k, "/")
 | 
							parts := strings.Split(k, "/")
 | 
				
			||||||
		name := parts[len(parts)-1]
 | 
							name := parts[len(parts)-1]
 | 
				
			||||||
		fmt.Fprintf(out, "%v:\t%s\n", name, v)
 | 
							fmt.Fprintf(out, "  %v:\t%s\n", name, v)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return
 | 
						return
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user