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
a15b804e
Commit
a15b804e
authored
Oct 10, 2023
by
Brad Davidson
Committed by
Brad Davidson
Oct 12, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sort snapshots by time and key in tabwriter output
Fixes snapshot list coming out in non-deterministic order Signed-off-by:
Brad Davidson
<
brad.davidson@rancher.com
>
parent
74640070
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
2 deletions
+17
-2
etcd_snapshot.go
pkg/cli/etcdsnapshot/etcd_snapshot.go
+17
-2
No files found.
pkg/cli/etcdsnapshot/etcd_snapshot.go
View file @
a15b804e
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"fmt"
"fmt"
"os"
"os"
"path/filepath"
"path/filepath"
"sort"
"strings"
"strings"
"text/tabwriter"
"text/tabwriter"
"time"
"time"
...
@@ -193,9 +194,23 @@ func list(app *cli.Context, cfg *cmds.Server) error {
...
@@ -193,9 +194,23 @@ func list(app *cli.Context, cfg *cmds.Server) error {
w
:=
tabwriter
.
NewWriter
(
os
.
Stdout
,
0
,
0
,
1
,
' '
,
0
)
w
:=
tabwriter
.
NewWriter
(
os
.
Stdout
,
0
,
0
,
1
,
' '
,
0
)
defer
w
.
Flush
()
defer
w
.
Flush
()
// Sort snapshots by creation time and key
sfKeys
:=
make
([]
string
,
0
,
len
(
sf
))
for
k
:=
range
sf
{
sfKeys
=
append
(
sfKeys
,
k
)
}
sort
.
Slice
(
sfKeys
,
func
(
i
,
j
int
)
bool
{
iKey
:=
sfKeys
[
i
]
jKey
:=
sfKeys
[
j
]
if
sf
[
iKey
]
.
CreatedAt
.
Equal
(
sf
[
jKey
]
.
CreatedAt
)
{
return
iKey
<
jKey
}
return
sf
[
iKey
]
.
CreatedAt
.
Before
(
sf
[
jKey
]
.
CreatedAt
)
})
fmt
.
Fprint
(
w
,
"Name
\t
Location
\t
Size
\t
Created
\n
"
)
fmt
.
Fprint
(
w
,
"Name
\t
Location
\t
Size
\t
Created
\n
"
)
for
_
,
s
:=
range
sf
{
for
_
,
k
:=
range
sfKeys
{
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%d
\t
%s
\n
"
,
s
.
Name
,
s
.
Location
,
s
.
Size
,
s
.
CreatedAt
.
Format
(
time
.
RFC3339
))
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%d
\t
%s
\n
"
,
s
f
[
k
]
.
Name
,
sf
[
k
]
.
Location
,
sf
[
k
]
.
Size
,
sf
[
k
]
.
CreatedAt
.
Format
(
time
.
RFC3339
))
}
}
}
}
...
...
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