Merge pull request #54548 from wackxu/desser

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

update the wrong format of string TargetPort

**What this PR does / why we need it**:

update the wrong format of string TargetPort

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #54546 

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2017-11-06 16:57:10 -08:00 committed by GitHub
commit 134e89e663
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 89 additions and 42 deletions

View File

@ -2088,7 +2088,7 @@ func describeService(service *api.Service, endpoints *api.Endpoints, events *api
if sp.TargetPort.Type == intstr.Type(intstr.Int) { if sp.TargetPort.Type == intstr.Type(intstr.Int) {
w.Write(LEVEL_0, "TargetPort:\t%d/%s\n", sp.TargetPort.IntVal, sp.Protocol) w.Write(LEVEL_0, "TargetPort:\t%d/%s\n", sp.TargetPort.IntVal, sp.Protocol)
} else { } else {
w.Write(LEVEL_0, "TargetPort:\t%d/%s\n", sp.TargetPort.StrVal, sp.Protocol) w.Write(LEVEL_0, "TargetPort:\t%s/%s\n", sp.TargetPort.StrVal, sp.Protocol)
} }
if sp.NodePort != 0 { if sp.NodePort != 0 {
w.Write(LEVEL_0, "NodePort:\t%s\t%d/%s\n", name, sp.NodePort, sp.Protocol) w.Write(LEVEL_0, "NodePort:\t%s\t%d/%s\n", name, sp.NodePort, sp.Protocol)

View File

@ -277,50 +277,97 @@ func getResourceList(cpu, memory string) api.ResourceList {
} }
func TestDescribeService(t *testing.T) { func TestDescribeService(t *testing.T) {
fake := fake.NewSimpleClientset(&api.Service{ testCases := []struct {
ObjectMeta: metav1.ObjectMeta{ service *api.Service
Name: "bar", expect []string
Namespace: "foo", }{
{
service: &api.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "foo",
},
Spec: api.ServiceSpec{
Type: api.ServiceTypeLoadBalancer,
Ports: []api.ServicePort{{
Name: "port-tcp",
Port: 8080,
Protocol: api.ProtocolTCP,
TargetPort: intstr.FromInt(9527),
NodePort: 31111,
}},
Selector: map[string]string{"blah": "heh"},
ClusterIP: "1.2.3.4",
LoadBalancerIP: "5.6.7.8",
SessionAffinity: "None",
ExternalTrafficPolicy: "Local",
HealthCheckNodePort: 32222,
},
},
expect: []string{
"Name", "bar",
"Namespace", "foo",
"Selector", "blah=heh",
"Type", "LoadBalancer",
"IP", "1.2.3.4",
"Port", "port-tcp", "8080/TCP",
"TargetPort", "9527/TCP",
"NodePort", "port-tcp", "31111/TCP",
"Session Affinity", "None",
"External Traffic Policy", "Local",
"HealthCheck NodePort", "32222",
},
}, },
Spec: api.ServiceSpec{ {
Type: api.ServiceTypeLoadBalancer, service: &api.Service{
Ports: []api.ServicePort{{ ObjectMeta: metav1.ObjectMeta{
Name: "port-tcp", Name: "bar",
Port: 8080, Namespace: "foo",
Protocol: api.ProtocolTCP, },
TargetPort: intstr.FromInt(9527), Spec: api.ServiceSpec{
NodePort: 31111, Type: api.ServiceTypeLoadBalancer,
}}, Ports: []api.ServicePort{{
Selector: map[string]string{"blah": "heh"}, Name: "port-tcp",
ClusterIP: "1.2.3.4", Port: 8080,
LoadBalancerIP: "5.6.7.8", Protocol: api.ProtocolTCP,
SessionAffinity: "None", TargetPort: intstr.FromString("targetPort"),
ExternalTrafficPolicy: "Local", NodePort: 31111,
HealthCheckNodePort: 32222, }},
Selector: map[string]string{"blah": "heh"},
ClusterIP: "1.2.3.4",
LoadBalancerIP: "5.6.7.8",
SessionAffinity: "None",
ExternalTrafficPolicy: "Local",
HealthCheckNodePort: 32222,
},
},
expect: []string{
"Name", "bar",
"Namespace", "foo",
"Selector", "blah=heh",
"Type", "LoadBalancer",
"IP", "1.2.3.4",
"Port", "port-tcp", "8080/TCP",
"TargetPort", "targetPort/TCP",
"NodePort", "port-tcp", "31111/TCP",
"Session Affinity", "None",
"External Traffic Policy", "Local",
"HealthCheck NodePort", "32222",
},
}, },
})
expectedElements := []string{
"Name", "bar",
"Namespace", "foo",
"Selector", "blah=heh",
"Type", "LoadBalancer",
"IP", "1.2.3.4",
"Port", "port-tcp", "8080/TCP",
"TargetPort", "9527/TCP",
"NodePort", "port-tcp", "31111/TCP",
"Session Affinity", "None",
"External Traffic Policy", "Local",
"HealthCheck NodePort", "32222",
} }
c := &describeClient{T: t, Namespace: "foo", Interface: fake} for _, testCase := range testCases {
d := ServiceDescriber{c} fake := fake.NewSimpleClientset(testCase.service)
out, err := d.Describe("foo", "bar", printers.DescriberSettings{ShowEvents: true}) c := &describeClient{T: t, Namespace: "foo", Interface: fake}
if err != nil { d := ServiceDescriber{c}
t.Errorf("unexpected error: %v", err) out, err := d.Describe("foo", "bar", printers.DescriberSettings{ShowEvents: true})
} if err != nil {
for _, expected := range expectedElements { t.Errorf("unexpected error: %v", err)
if !strings.Contains(out, expected) { }
t.Errorf("expected to find %q in output: %q", expected, out) for _, expected := range testCase.expect {
if !strings.Contains(out, expected) {
t.Errorf("expected to find %q in output: %q", expected, out)
}
} }
} }
} }