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
ad8506c3
Commit
ad8506c3
authored
Aug 03, 2017
by
xiangpengzhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Display healthcheck nodeport and other fields in describe service
parent
7bc1c676
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
2 deletions
+50
-2
describe.go
pkg/printers/internalversion/describe.go
+17
-0
describe_test.go
pkg/printers/internalversion/describe_test.go
+33
-2
No files found.
pkg/printers/internalversion/describe.go
View file @
ad8506c3
...
@@ -2006,6 +2006,9 @@ func describeService(service *api.Service, endpoints *api.Endpoints, events *api
...
@@ -2006,6 +2006,9 @@ func describeService(service *api.Service, endpoints *api.Endpoints, events *api
if
len
(
service
.
Spec
.
ExternalIPs
)
>
0
{
if
len
(
service
.
Spec
.
ExternalIPs
)
>
0
{
w
.
Write
(
LEVEL_0
,
"External IPs:
\t
%v
\n
"
,
strings
.
Join
(
service
.
Spec
.
ExternalIPs
,
","
))
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
)
}
if
service
.
Spec
.
ExternalName
!=
""
{
if
service
.
Spec
.
ExternalName
!=
""
{
w
.
Write
(
LEVEL_0
,
"External Name:
\t
%s
\n
"
,
service
.
Spec
.
ExternalName
)
w
.
Write
(
LEVEL_0
,
"External Name:
\t
%s
\n
"
,
service
.
Spec
.
ExternalName
)
}
}
...
@@ -2021,12 +2024,26 @@ func describeService(service *api.Service, endpoints *api.Endpoints, events *api
...
@@ -2021,12 +2024,26 @@ func describeService(service *api.Service, endpoints *api.Endpoints, events *api
name
=
"<unset>"
name
=
"<unset>"
}
}
w
.
Write
(
LEVEL_0
,
"Port:
\t
%s
\t
%d/%s
\n
"
,
name
,
sp
.
Port
,
sp
.
Protocol
)
w
.
Write
(
LEVEL_0
,
"Port:
\t
%s
\t
%d/%s
\n
"
,
name
,
sp
.
Port
,
sp
.
Protocol
)
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
)
}
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
)
}
}
w
.
Write
(
LEVEL_0
,
"Endpoints:
\t
%s
\n
"
,
formatEndpoints
(
endpoints
,
sets
.
NewString
(
sp
.
Name
)))
w
.
Write
(
LEVEL_0
,
"Endpoints:
\t
%s
\n
"
,
formatEndpoints
(
endpoints
,
sets
.
NewString
(
sp
.
Name
)))
}
}
w
.
Write
(
LEVEL_0
,
"Session Affinity:
\t
%s
\n
"
,
service
.
Spec
.
SessionAffinity
)
w
.
Write
(
LEVEL_0
,
"Session Affinity:
\t
%s
\n
"
,
service
.
Spec
.
SessionAffinity
)
if
service
.
Spec
.
ExternalTrafficPolicy
!=
""
{
w
.
Write
(
LEVEL_0
,
"External Traffic Policy:
\t
%s
\n
"
,
service
.
Spec
.
ExternalTrafficPolicy
)
}
if
service
.
Spec
.
HealthCheckNodePort
!=
0
{
w
.
Write
(
LEVEL_0
,
"HealthCheck NodePort:
\t
%d
\n
"
,
service
.
Spec
.
HealthCheckNodePort
)
}
if
len
(
service
.
Spec
.
LoadBalancerSourceRanges
)
>
0
{
w
.
Write
(
LEVEL_0
,
"LoadBalancer Source Ranges:
\t
%v
\n
"
,
strings
.
Join
(
service
.
Spec
.
LoadBalancerSourceRanges
,
","
))
}
if
events
!=
nil
{
if
events
!=
nil
{
DescribeEvents
(
events
,
w
)
DescribeEvents
(
events
,
w
)
}
}
...
...
pkg/printers/internalversion/describe_test.go
View file @
ad8506c3
...
@@ -172,15 +172,46 @@ func TestDescribeService(t *testing.T) {
...
@@ -172,15 +172,46 @@ func TestDescribeService(t *testing.T) {
Name
:
"bar"
,
Name
:
"bar"
,
Namespace
:
"foo"
,
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
,
},
})
})
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
}
c
:=
&
describeClient
{
T
:
t
,
Namespace
:
"foo"
,
Interface
:
fake
}
d
:=
ServiceDescriber
{
c
}
d
:=
ServiceDescriber
{
c
}
out
,
err
:=
d
.
Describe
(
"foo"
,
"bar"
,
printers
.
DescriberSettings
{
ShowEvents
:
true
})
out
,
err
:=
d
.
Describe
(
"foo"
,
"bar"
,
printers
.
DescriberSettings
{
ShowEvents
:
true
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
if
!
strings
.
Contains
(
out
,
"Labels:"
)
||
!
strings
.
Contains
(
out
,
"bar"
)
{
for
_
,
expected
:=
range
expectedElements
{
t
.
Errorf
(
"unexpected out: %s"
,
out
)
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