mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
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:
commit
134e89e663
@ -2088,7 +2088,7 @@ func describeService(service *api.Service, endpoints *api.Endpoints, events *api
|
||||
if sp.TargetPort.Type == intstr.Type(intstr.Int) {
|
||||
w.Write(LEVEL_0, "TargetPort:\t%d/%s\n", sp.TargetPort.IntVal, sp.Protocol)
|
||||
} 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 {
|
||||
w.Write(LEVEL_0, "NodePort:\t%s\t%d/%s\n", name, sp.NodePort, sp.Protocol)
|
||||
|
@ -277,50 +277,97 @@ func getResourceList(cpu, memory string) api.ResourceList {
|
||||
}
|
||||
|
||||
func TestDescribeService(t *testing.T) {
|
||||
fake := fake.NewSimpleClientset(&api.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "bar",
|
||||
Namespace: "foo",
|
||||
testCases := []struct {
|
||||
service *api.Service
|
||||
expect []string
|
||||
}{
|
||||
{
|
||||
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,
|
||||
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,
|
||||
{
|
||||
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.FromString("targetPort"),
|
||||
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", "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}
|
||||
d := ServiceDescriber{c}
|
||||
out, err := d.Describe("foo", "bar", printers.DescriberSettings{ShowEvents: true})
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
for _, expected := range expectedElements {
|
||||
if !strings.Contains(out, expected) {
|
||||
t.Errorf("expected to find %q in output: %q", expected, out)
|
||||
for _, testCase := range testCases {
|
||||
fake := fake.NewSimpleClientset(testCase.service)
|
||||
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
|
||||
d := ServiceDescriber{c}
|
||||
out, err := d.Describe("foo", "bar", printers.DescriberSettings{ShowEvents: true})
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
for _, expected := range testCase.expect {
|
||||
if !strings.Contains(out, expected) {
|
||||
t.Errorf("expected to find %q in output: %q", expected, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user