Skip to content

Commit a19c0ad

Browse files
authored
Merge pull request kubernetes#131491 from tchap/kubectl-service-describe-trafficdistribution
kubectl describe service: Add Traffic Distribution
2 parents c519248 + ad40bc8 commit a19c0ad

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

staging/src/k8s.io/kubectl/pkg/describe/describe.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,6 +3157,9 @@ func describeService(service *corev1.Service, endpointSlices []discoveryv1.Endpo
31573157
if len(service.Spec.LoadBalancerSourceRanges) > 0 {
31583158
w.Write(LEVEL_0, "LoadBalancer Source Ranges:\t%v\n", strings.Join(service.Spec.LoadBalancerSourceRanges, ","))
31593159
}
3160+
if service.Spec.TrafficDistribution != nil {
3161+
w.Write(LEVEL_0, "Traffic Distribution:\t%s\n", *service.Spec.TrafficDistribution)
3162+
}
31603163
if events != nil {
31613164
DescribeEvents(events, w)
31623165
}

staging/src/k8s.io/kubectl/pkg/describe/describe_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ func getResourceList(cpu, memory string) corev1.ResourceList {
781781

782782
func TestDescribeService(t *testing.T) {
783783
singleStack := corev1.IPFamilyPolicySingleStack
784+
preferClose := corev1.ServiceTrafficDistributionPreferClose
784785
testCases := []struct {
785786
name string
786787
service *corev1.Service
@@ -1139,6 +1140,54 @@ func TestDescribeService(t *testing.T) {
11391140
Events: <none>
11401141
`)[1:],
11411142
},
1143+
{
1144+
name: "test-TrafficDistribution",
1145+
service: &corev1.Service{
1146+
ObjectMeta: metav1.ObjectMeta{
1147+
Name: "bar",
1148+
Namespace: "foo",
1149+
},
1150+
Spec: corev1.ServiceSpec{
1151+
Type: corev1.ServiceTypeLoadBalancer,
1152+
Ports: []corev1.ServicePort{{
1153+
Name: "port-tcp",
1154+
Port: 8080,
1155+
Protocol: corev1.ProtocolTCP,
1156+
TargetPort: intstr.FromString("targetPort"),
1157+
NodePort: 31111,
1158+
}},
1159+
Selector: map[string]string{"blah": "heh"},
1160+
ClusterIP: "1.2.3.4",
1161+
IPFamilies: []corev1.IPFamily{corev1.IPv4Protocol},
1162+
LoadBalancerIP: "5.6.7.8",
1163+
SessionAffinity: corev1.ServiceAffinityNone,
1164+
ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyLocal,
1165+
TrafficDistribution: &preferClose,
1166+
HealthCheckNodePort: 32222,
1167+
},
1168+
},
1169+
expected: dedent.Dedent(`
1170+
Name: bar
1171+
Namespace: foo
1172+
Labels: <none>
1173+
Annotations: <none>
1174+
Selector: blah=heh
1175+
Type: LoadBalancer
1176+
IP Families: IPv4
1177+
IP: 1.2.3.4
1178+
IPs: <none>
1179+
Desired LoadBalancer IP: 5.6.7.8
1180+
Port: port-tcp 8080/TCP
1181+
TargetPort: targetPort/TCP
1182+
NodePort: port-tcp 31111/TCP
1183+
Endpoints: <none>
1184+
Session Affinity: None
1185+
External Traffic Policy: Local
1186+
HealthCheck NodePort: 32222
1187+
Traffic Distribution: PreferClose
1188+
Events: <none>
1189+
`)[1:],
1190+
},
11421191
}
11431192
for _, tc := range testCases {
11441193
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)