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
44fa48e5
Commit
44fa48e5
authored
Aug 20, 2015
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12635 from hurf/null_age
fix AGE error when resource has no creationTimeStamp
parents
a2b5be80
c20ed034
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
1 deletion
+35
-1
resource_printer.go
pkg/kubectl/resource_printer.go
+10
-1
resource_printer_test.go
pkg/kubectl/resource_printer_test.go
+25
-0
No files found.
pkg/kubectl/resource_printer.go
View file @
44fa48e5
...
@@ -363,7 +363,13 @@ func podHostString(host, ip string) string {
...
@@ -363,7 +363,13 @@ func podHostString(host, ip string) string {
}
}
func
shortHumanDuration
(
d
time
.
Duration
)
string
{
func
shortHumanDuration
(
d
time
.
Duration
)
string
{
if
seconds
:=
int
(
d
.
Seconds
());
seconds
<
60
{
// Allow deviation no more than 2 seconds(excluded) to tolerate machine time
// inconsistence, it can be considered as almost now.
if
seconds
:=
int
(
d
.
Seconds
());
seconds
<
-
1
{
return
fmt
.
Sprintf
(
"<invalid>"
)
}
else
if
seconds
<
0
{
return
fmt
.
Sprintf
(
"0s"
)
}
else
if
seconds
<
60
{
return
fmt
.
Sprintf
(
"%ds"
,
seconds
)
return
fmt
.
Sprintf
(
"%ds"
,
seconds
)
}
else
if
minutes
:=
int
(
d
.
Minutes
());
minutes
<
60
{
}
else
if
minutes
:=
int
(
d
.
Minutes
());
minutes
<
60
{
return
fmt
.
Sprintf
(
"%dm"
,
minutes
)
return
fmt
.
Sprintf
(
"%dm"
,
minutes
)
...
@@ -378,6 +384,9 @@ func shortHumanDuration(d time.Duration) string {
...
@@ -378,6 +384,9 @@ func shortHumanDuration(d time.Duration) string {
// translateTimestamp returns the elapsed time since timestamp in
// translateTimestamp returns the elapsed time since timestamp in
// human-readable approximation.
// human-readable approximation.
func
translateTimestamp
(
timestamp
util
.
Time
)
string
{
func
translateTimestamp
(
timestamp
util
.
Time
)
string
{
if
timestamp
.
IsZero
()
{
return
"<unknown>"
}
return
shortHumanDuration
(
time
.
Now
()
.
Sub
(
timestamp
.
Time
))
return
shortHumanDuration
(
time
.
Now
()
.
Sub
(
timestamp
.
Time
))
}
}
...
...
pkg/kubectl/resource_printer_test.go
View file @
44fa48e5
...
@@ -1190,3 +1190,28 @@ func TestPrintPodWithLabels(t *testing.T) {
...
@@ -1190,3 +1190,28 @@ func TestPrintPodWithLabels(t *testing.T) {
buf
.
Reset
()
buf
.
Reset
()
}
}
}
}
type
stringTestList
[]
struct
{
name
,
got
,
exp
string
}
func
TestTranslateTimestamp
(
t
*
testing
.
T
)
{
tl
:=
stringTestList
{
{
"a while from now"
,
translateTimestamp
(
util
.
Time
{
Time
:
time
.
Now
()
.
Add
(
2.1e9
)}),
"<invalid>"
},
{
"almost now"
,
translateTimestamp
(
util
.
Time
{
Time
:
time
.
Now
()
.
Add
(
1.9e9
)}),
"0s"
},
{
"now"
,
translateTimestamp
(
util
.
Time
{
Time
:
time
.
Now
()}),
"0s"
},
{
"unknown"
,
translateTimestamp
(
util
.
Time
{}),
"<unknown>"
},
{
"30 seconds ago"
,
translateTimestamp
(
util
.
Time
{
Time
:
time
.
Now
()
.
Add
(
-
3e10
)}),
"30s"
},
{
"5 minutes ago"
,
translateTimestamp
(
util
.
Time
{
Time
:
time
.
Now
()
.
Add
(
-
3e11
)}),
"5m"
},
{
"an hour ago"
,
translateTimestamp
(
util
.
Time
{
Time
:
time
.
Now
()
.
Add
(
-
6e12
)}),
"1h"
},
{
"2 days ago"
,
translateTimestamp
(
util
.
Time
{
Time
:
time
.
Now
()
.
AddDate
(
0
,
0
,
-
2
)}),
"2d"
},
{
"months ago"
,
translateTimestamp
(
util
.
Time
{
Time
:
time
.
Now
()
.
AddDate
(
0
,
-
3
,
0
)}),
"92d"
},
{
"10 years ago"
,
translateTimestamp
(
util
.
Time
{
Time
:
time
.
Now
()
.
AddDate
(
-
10
,
0
,
0
)}),
"10y"
},
}
for
_
,
test
:=
range
tl
{
if
test
.
got
!=
test
.
exp
{
t
.
Errorf
(
"On %v, expected '%v', but got '%v'"
,
test
.
name
,
test
.
exp
,
test
.
got
)
}
}
}
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