Make the output of kubectl describe service more informative (#125117)
				
					
				
			* kubectl: add internalTrafficPolicy to Service describer * kubectl: add loadBalancer ipMode to Service describer * kubectl: fix duplicate IP fields in Service describer For a LoadBalancer Service, there were two "IP" fields in the output of `kubectl describe service` if its loadBalancerIP is not empty, which looks ambiguous.
This commit is contained in:
		@@ -2984,6 +2984,9 @@ func buildIngressString(ingress []corev1.LoadBalancerIngress) string {
 | 
			
		||||
		}
 | 
			
		||||
		if ingress[i].IP != "" {
 | 
			
		||||
			buffer.WriteString(ingress[i].IP)
 | 
			
		||||
			if ingress[i].IPMode != nil {
 | 
			
		||||
				buffer.WriteString(fmt.Sprintf(" (%s)", *ingress[i].IPMode))
 | 
			
		||||
			}
 | 
			
		||||
		} else {
 | 
			
		||||
			buffer.WriteString(ingress[i].Hostname)
 | 
			
		||||
		}
 | 
			
		||||
@@ -3027,7 +3030,7 @@ func describeService(service *corev1.Service, endpointSlices []discoveryv1.Endpo
 | 
			
		||||
			w.Write(LEVEL_0, "External IPs:\t%v\n", strings.Join(service.Spec.ExternalIPs, ","))
 | 
			
		||||
		}
 | 
			
		||||
		if service.Spec.LoadBalancerIP != "" {
 | 
			
		||||
			w.Write(LEVEL_0, "IP:\t%s\n", service.Spec.LoadBalancerIP)
 | 
			
		||||
			w.Write(LEVEL_0, "Desired LoadBalancer IP:\t%s\n", service.Spec.LoadBalancerIP)
 | 
			
		||||
		}
 | 
			
		||||
		if service.Spec.ExternalName != "" {
 | 
			
		||||
			w.Write(LEVEL_0, "External Name:\t%s\n", service.Spec.ExternalName)
 | 
			
		||||
@@ -3058,6 +3061,9 @@ func describeService(service *corev1.Service, endpointSlices []discoveryv1.Endpo
 | 
			
		||||
		if service.Spec.ExternalTrafficPolicy != "" {
 | 
			
		||||
			w.Write(LEVEL_0, "External Traffic Policy:\t%s\n", service.Spec.ExternalTrafficPolicy)
 | 
			
		||||
		}
 | 
			
		||||
		if service.Spec.InternalTrafficPolicy != nil {
 | 
			
		||||
			w.Write(LEVEL_0, "Internal Traffic Policy:\t%s\n", *service.Spec.InternalTrafficPolicy)
 | 
			
		||||
		}
 | 
			
		||||
		if service.Spec.HealthCheckNodePort != 0 {
 | 
			
		||||
			w.Write(LEVEL_0, "HealthCheck NodePort:\t%d\n", service.Spec.HealthCheckNodePort)
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -710,8 +710,19 @@ func TestDescribeService(t *testing.T) {
 | 
			
		||||
					LoadBalancerIP:        "5.6.7.8",
 | 
			
		||||
					SessionAffinity:       corev1.ServiceAffinityNone,
 | 
			
		||||
					ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyLocal,
 | 
			
		||||
					InternalTrafficPolicy: ptr.To(corev1.ServiceInternalTrafficPolicyCluster),
 | 
			
		||||
					HealthCheckNodePort:   32222,
 | 
			
		||||
				},
 | 
			
		||||
				Status: corev1.ServiceStatus{
 | 
			
		||||
					LoadBalancer: corev1.LoadBalancerStatus{
 | 
			
		||||
						Ingress: []corev1.LoadBalancerIngress{
 | 
			
		||||
							{
 | 
			
		||||
								IP:     "5.6.7.8",
 | 
			
		||||
								IPMode: ptr.To(corev1.LoadBalancerIPModeVIP),
 | 
			
		||||
							},
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			endpointSlices: []*discoveryv1.EndpointSlice{{
 | 
			
		||||
				ObjectMeta: metav1.ObjectMeta{
 | 
			
		||||
@@ -742,13 +753,15 @@ func TestDescribeService(t *testing.T) {
 | 
			
		||||
				IP Families:              IPv4
 | 
			
		||||
				IP:                       1.2.3.4
 | 
			
		||||
				IPs:                      <none>
 | 
			
		||||
				IP:                       5.6.7.8
 | 
			
		||||
				Desired LoadBalancer IP:  5.6.7.8
 | 
			
		||||
				LoadBalancer Ingress:     5.6.7.8 (VIP)
 | 
			
		||||
				Port:                     port-tcp  8080/TCP
 | 
			
		||||
				TargetPort:               9527/TCP
 | 
			
		||||
				NodePort:                 port-tcp  31111/TCP
 | 
			
		||||
				Endpoints:                10.244.0.1:9527,10.244.0.2:9527,10.244.0.3:9527
 | 
			
		||||
				Session Affinity:         None
 | 
			
		||||
				External Traffic Policy:  Local
 | 
			
		||||
				Internal Traffic Policy:  Cluster
 | 
			
		||||
				HealthCheck NodePort:     32222
 | 
			
		||||
				Events:                   <none>
 | 
			
		||||
			`)[1:],
 | 
			
		||||
@@ -775,8 +788,18 @@ func TestDescribeService(t *testing.T) {
 | 
			
		||||
					LoadBalancerIP:        "5.6.7.8",
 | 
			
		||||
					SessionAffinity:       corev1.ServiceAffinityNone,
 | 
			
		||||
					ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyLocal,
 | 
			
		||||
					InternalTrafficPolicy: ptr.To(corev1.ServiceInternalTrafficPolicyLocal),
 | 
			
		||||
					HealthCheckNodePort:   32222,
 | 
			
		||||
				},
 | 
			
		||||
				Status: corev1.ServiceStatus{
 | 
			
		||||
					LoadBalancer: corev1.LoadBalancerStatus{
 | 
			
		||||
						Ingress: []corev1.LoadBalancerIngress{
 | 
			
		||||
							{
 | 
			
		||||
								IP: "5.6.7.8",
 | 
			
		||||
							},
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			endpointSlices: []*discoveryv1.EndpointSlice{
 | 
			
		||||
				{
 | 
			
		||||
@@ -827,13 +850,15 @@ func TestDescribeService(t *testing.T) {
 | 
			
		||||
				IP Families:              IPv4
 | 
			
		||||
				IP:                       1.2.3.4
 | 
			
		||||
				IPs:                      <none>
 | 
			
		||||
				IP:                       5.6.7.8
 | 
			
		||||
				Desired LoadBalancer IP:  5.6.7.8
 | 
			
		||||
				LoadBalancer Ingress:     5.6.7.8
 | 
			
		||||
				Port:                     port-tcp  8080/TCP
 | 
			
		||||
				TargetPort:               targetPort/TCP
 | 
			
		||||
				NodePort:                 port-tcp  31111/TCP
 | 
			
		||||
				Endpoints:                10.244.0.1:9527,10.244.0.2:9527,10.244.0.3:9527 + 2 more...
 | 
			
		||||
				Session Affinity:         None
 | 
			
		||||
				External Traffic Policy:  Local
 | 
			
		||||
				Internal Traffic Policy:  Local
 | 
			
		||||
				HealthCheck NodePort:     32222
 | 
			
		||||
				Events:                   <none>
 | 
			
		||||
			`)[1:],
 | 
			
		||||
@@ -890,7 +915,7 @@ func TestDescribeService(t *testing.T) {
 | 
			
		||||
				IP Families:              IPv4
 | 
			
		||||
				IP:                       1.2.3.4
 | 
			
		||||
				IPs:                      <none>
 | 
			
		||||
				IP:                       5.6.7.8
 | 
			
		||||
				Desired LoadBalancer IP:  5.6.7.8
 | 
			
		||||
				Port:                     port-tcp  8080/TCP
 | 
			
		||||
				TargetPort:               targetPort/TCP
 | 
			
		||||
				NodePort:                 port-tcp  31111/TCP
 | 
			
		||||
@@ -939,7 +964,7 @@ func TestDescribeService(t *testing.T) {
 | 
			
		||||
				IP Families:              IPv4
 | 
			
		||||
				IP:                       1.2.3.4
 | 
			
		||||
				IPs:                      1.2.3.4
 | 
			
		||||
				IP:                       5.6.7.8
 | 
			
		||||
				Desired LoadBalancer IP:  5.6.7.8
 | 
			
		||||
				Port:                     port-tcp  8080/TCP
 | 
			
		||||
				TargetPort:               targetPort/TCP
 | 
			
		||||
				NodePort:                 port-tcp  31111/TCP
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user