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. Kubernetes-commit: 59d90eb17e41f855e65f6ca4ac3d93d3709a3067
This commit is contained in:
parent
42f728c3d6
commit
770b201e9c
2
go.mod
2
go.mod
|
|
@ -30,7 +30,7 @@ require (
|
|||
gopkg.in/evanphx/json-patch.v4 v4.12.0
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
k8s.io/api v0.0.0-20240626182217-e025325e26d9
|
||||
k8s.io/apimachinery v0.0.0-20240626181934-01e80c94aa3d
|
||||
k8s.io/apimachinery v0.0.0-20240626221952-93912e7e097c
|
||||
k8s.io/cli-runtime v0.0.0-20240626185853-ef67a51fc752
|
||||
k8s.io/client-go v0.0.0-20240626182623-88829a42b75c
|
||||
k8s.io/component-base v0.0.0-20240626183556-be12fe0993e2
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -279,8 +279,8 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
|
|||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
k8s.io/api v0.0.0-20240626182217-e025325e26d9 h1:X44rlrfL9raYAeTdQin9ml5opO0SAfsFMHs7TV0UWv4=
|
||||
k8s.io/api v0.0.0-20240626182217-e025325e26d9/go.mod h1:aJpJykBcvFzrEmoawdT8TjyxAJrp996V2NHz/eKgvrg=
|
||||
k8s.io/apimachinery v0.0.0-20240626181934-01e80c94aa3d h1:PI8ONv9r5xrdM//0BdiLwSsVJSoLXUK51CLPCQY5Ezw=
|
||||
k8s.io/apimachinery v0.0.0-20240626181934-01e80c94aa3d/go.mod h1:fHtYPEGOJ0v5phs8kGMb2EX2tF8J3NvyWKNR745wW9o=
|
||||
k8s.io/apimachinery v0.0.0-20240626221952-93912e7e097c h1:3DxeI16iQVB4iJFW5QstfXYmlZffsGZrWjEVxlxbQKo=
|
||||
k8s.io/apimachinery v0.0.0-20240626221952-93912e7e097c/go.mod h1:fHtYPEGOJ0v5phs8kGMb2EX2tF8J3NvyWKNR745wW9o=
|
||||
k8s.io/cli-runtime v0.0.0-20240626185853-ef67a51fc752 h1:gtL3d/zeMla2aZZMVWDocDPeqTayRNjxj8A89Un/qKw=
|
||||
k8s.io/cli-runtime v0.0.0-20240626185853-ef67a51fc752/go.mod h1:nMRZg3wxhW7ySfjGQZGYq9XnutwbnERkCMhN0HpwPKM=
|
||||
k8s.io/client-go v0.0.0-20240626182623-88829a42b75c h1:2PwR01gisPgUJKJvmb6VtnMQYjYRTSRvLajRBijKsNM=
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue