Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
bfe6474d
Commit
bfe6474d
authored
Oct 25, 2017
by
wackxu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update the wrong format of string TargetPort
parent
7f991a3b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
42 deletions
+89
-42
describe.go
pkg/printers/internalversion/describe.go
+1
-1
describe_test.go
pkg/printers/internalversion/describe_test.go
+88
-41
No files found.
pkg/printers/internalversion/describe.go
View file @
bfe6474d
...
@@ -2082,7 +2082,7 @@ func describeService(service *api.Service, endpoints *api.Endpoints, events *api
...
@@ -2082,7 +2082,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
)
...
...
pkg/printers/internalversion/describe_test.go
View file @
bfe6474d
...
@@ -231,50 +231,97 @@ func getResourceList(cpu, memory string) api.ResourceList {
...
@@ -231,50 +231,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
}
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
{
for
_
,
testCase
:=
range
testCases
{
if
!
strings
.
Contains
(
out
,
expected
)
{
fake
:=
fake
.
NewSimpleClientset
(
testCase
.
service
)
t
.
Errorf
(
"expected to find %q in output: %q"
,
expected
,
out
)
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
)
}
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment