Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the output of kubectl describe service more informative #125117

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion staging/src/k8s.io/kubectl/pkg/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments is addressed.
Do you have time to take a look again @danwinship @aojea ?

}
if service.Spec.ExternalName != "" {
w.Write(LEVEL_0, "External Name:\t%s\n", service.Spec.ExternalName)
Expand Down Expand Up @@ -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)
}
Expand Down
33 changes: 29 additions & 4 deletions staging/src/k8s.io/kubectl/pkg/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,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{
Expand Down Expand Up @@ -713,13 +724,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:],
Expand All @@ -746,8 +759,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{
{
Expand Down Expand Up @@ -798,13 +821,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:],
Expand Down Expand Up @@ -861,7 +886,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
Expand Down Expand Up @@ -910,7 +935,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
Expand Down