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
46ec13cf
Unverified
Commit
46ec13cf
authored
Oct 22, 2018
by
k8s-ci-robot
Committed by
GitHub
Oct 22, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70027 from bart0sh/PR0031-kubeadm-sort-volumes
kubeadm: sort pod Volumes and VolumeMounts
parents
2472d673
ebb0af9e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
6 deletions
+27
-6
utils.go
cmd/kubeadm/app/util/staticpod/utils.go
+9
-0
utils_test.go
cmd/kubeadm/app/util/staticpod/utils_test.go
+18
-6
No files found.
cmd/kubeadm/app/util/staticpod/utils.go
View file @
46ec13cf
...
...
@@ -23,6 +23,7 @@ import (
"net"
"net/url"
"os"
"sort"
"strings"
"k8s.io/api/core/v1"
...
...
@@ -148,6 +149,10 @@ func VolumeMapToSlice(volumes map[string]v1.Volume) []v1.Volume {
v
=
append
(
v
,
vol
)
}
sort
.
Slice
(
v
,
func
(
i
,
j
int
)
bool
{
return
strings
.
Compare
(
v
[
i
]
.
Name
,
v
[
j
]
.
Name
)
==
-
1
})
return
v
}
...
...
@@ -159,6 +164,10 @@ func VolumeMountMapToSlice(volumeMounts map[string]v1.VolumeMount) []v1.VolumeMo
v
=
append
(
v
,
volMount
)
}
sort
.
Slice
(
v
,
func
(
i
,
j
int
)
bool
{
return
strings
.
Compare
(
v
[
i
]
.
Name
,
v
[
j
]
.
Name
)
==
-
1
})
return
v
}
...
...
cmd/kubeadm/app/util/staticpod/utils_test.go
View file @
46ec13cf
...
...
@@ -482,13 +482,19 @@ func TestVolumeMapToSlice(t *testing.T) {
"foo"
:
{
Name
:
"foo"
,
},
"bar"
:
{
Name
:
"bar"
,
},
}
volumeSlice
:=
VolumeMapToSlice
(
testVolumes
)
if
len
(
volumeSlice
)
!=
1
{
if
len
(
volumeSlice
)
!=
2
{
t
.
Errorf
(
"Expected slice length of 1, got %d"
,
len
(
volumeSlice
))
}
if
volumeSlice
[
0
]
.
Name
!=
"foo"
{
t
.
Errorf
(
"Expected volume name
\"
foo
\"
, got %s"
,
volumeSlice
[
0
]
.
Name
)
if
volumeSlice
[
0
]
.
Name
!=
"bar"
{
t
.
Errorf
(
"Expected first volume name
\"
bar
\"
, got %s"
,
volumeSlice
[
0
]
.
Name
)
}
if
volumeSlice
[
1
]
.
Name
!=
"foo"
{
t
.
Errorf
(
"Expected second volume name
\"
foo
\"
, got %s"
,
volumeSlice
[
1
]
.
Name
)
}
}
...
...
@@ -497,13 +503,19 @@ func TestVolumeMountMapToSlice(t *testing.T) {
"foo"
:
{
Name
:
"foo"
,
},
"bar"
:
{
Name
:
"bar"
,
},
}
volumeMountSlice
:=
VolumeMountMapToSlice
(
testVolumeMounts
)
if
len
(
volumeMountSlice
)
!=
1
{
if
len
(
volumeMountSlice
)
!=
2
{
t
.
Errorf
(
"Expected slice length of 1, got %d"
,
len
(
volumeMountSlice
))
}
if
volumeMountSlice
[
0
]
.
Name
!=
"foo"
{
t
.
Errorf
(
"Expected volume mount name
\"
foo
\"
, got %s"
,
volumeMountSlice
[
0
]
.
Name
)
if
volumeMountSlice
[
0
]
.
Name
!=
"bar"
{
t
.
Errorf
(
"Expected first volume mount name
\"
bar
\"
, got %s"
,
volumeMountSlice
[
0
]
.
Name
)
}
if
volumeMountSlice
[
1
]
.
Name
!=
"foo"
{
t
.
Errorf
(
"Expected second volume name
\"
foo
\"
, got %s"
,
volumeMountSlice
[
1
]
.
Name
)
}
}
...
...
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