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
b7da8747
Commit
b7da8747
authored
Oct 17, 2016
by
Lukasz Zajaczkowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add NodePort value in kubectl output
parent
609b9e51
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
0 deletions
+53
-0
resource_printer.go
pkg/kubectl/resource_printer.go
+3
-0
resource_printer_test.go
pkg/kubectl/resource_printer_test.go
+50
-0
No files found.
pkg/kubectl/resource_printer.go
View file @
b7da8747
...
@@ -1100,6 +1100,9 @@ func makePortString(ports []api.ServicePort) string {
...
@@ -1100,6 +1100,9 @@ func makePortString(ports []api.ServicePort) string {
for
ix
:=
range
ports
{
for
ix
:=
range
ports
{
port
:=
&
ports
[
ix
]
port
:=
&
ports
[
ix
]
pieces
[
ix
]
=
fmt
.
Sprintf
(
"%d/%s"
,
port
.
Port
,
port
.
Protocol
)
pieces
[
ix
]
=
fmt
.
Sprintf
(
"%d/%s"
,
port
.
Port
,
port
.
Protocol
)
if
port
.
NodePort
>
0
{
pieces
[
ix
]
=
fmt
.
Sprintf
(
"%d:%d/%s"
,
port
.
Port
,
port
.
NodePort
,
port
.
Protocol
)
}
}
}
return
strings
.
Join
(
pieces
,
","
)
return
strings
.
Join
(
pieces
,
","
)
}
}
...
...
pkg/kubectl/resource_printer_test.go
View file @
b7da8747
...
@@ -1572,3 +1572,53 @@ func TestPrintPodShowLabels(t *testing.T) {
...
@@ -1572,3 +1572,53 @@ func TestPrintPodShowLabels(t *testing.T) {
buf
.
Reset
()
buf
.
Reset
()
}
}
}
}
func
TestPrintService
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
service
api
.
Service
expect
string
}{
{
// Test name, cluster ip, port with protocol
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test1"
},
Spec
:
api
.
ServiceSpec
{
Type
:
api
.
ServiceTypeClusterIP
,
Ports
:
[]
api
.
ServicePort
{
{
Protocol
:
"tcp"
,
Port
:
2233
},
},
ClusterIP
:
"0.0.0.0"
,
},
},
"test1
\t
0.0.0.0
\t
<none>
\t
2233/tcp
\t
<unknown>
\n
"
,
},
{
// Test name, cluster ip, port:nodePort with protocol
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test2"
},
Spec
:
api
.
ServiceSpec
{
Type
:
api
.
ServiceTypeClusterIP
,
Ports
:
[]
api
.
ServicePort
{
{
Protocol
:
"tcp"
,
Port
:
8888
,
NodePort
:
9999
,
},
},
ClusterIP
:
"10.9.8.7"
,
},
},
"test2
\t
10.9.8.7
\t
<none>
\t
8888:9999/tcp
\t
<unknown>
\n
"
,
},
}
buf
:=
bytes
.
NewBuffer
([]
byte
{})
for
_
,
test
:=
range
tests
{
printService
(
&
test
.
service
,
buf
,
PrintOptions
{
false
,
false
,
false
,
false
,
true
,
false
,
false
,
""
,
[]
string
{}})
// We ignore time
if
buf
.
String
()
!=
test
.
expect
{
t
.
Fatalf
(
"Expected: %s, got: %s %d"
,
test
.
expect
,
buf
.
String
(),
strings
.
Compare
(
test
.
expect
,
buf
.
String
()))
}
buf
.
Reset
()
}
}
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