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
5308957d
Commit
5308957d
authored
May 14, 2018
by
lalyos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sort arguments before joining them, for reproducible return string
parent
0ba80021
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
10 deletions
+23
-10
arguments.go
cmd/kubeadm/app/util/arguments.go
+18
-3
arguments_test.go
cmd/kubeadm/app/util/arguments_test.go
+5
-7
No files found.
cmd/kubeadm/app/util/arguments.go
View file @
5308957d
...
@@ -18,17 +18,32 @@ package util
...
@@ -18,17 +18,32 @@ package util
import
(
import
(
"fmt"
"fmt"
"sort"
"strings"
"strings"
)
)
// BuildArgumentListFromMap takes two string-string maps, one with the base arguments and one with optional override arguments
// BuildArgumentListFromMap takes two string-string maps, one with the base arguments and one
// with optional override arguments. In the return list override arguments will precede base
// arguments
func
BuildArgumentListFromMap
(
baseArguments
map
[
string
]
string
,
overrideArguments
map
[
string
]
string
)
[]
string
{
func
BuildArgumentListFromMap
(
baseArguments
map
[
string
]
string
,
overrideArguments
map
[
string
]
string
)
[]
string
{
var
command
[]
string
var
command
[]
string
for
k
,
v
:=
range
overrideArguments
{
var
keys
[]
string
for
k
:=
range
overrideArguments
{
keys
=
append
(
keys
,
k
)
}
sort
.
Strings
(
keys
)
for
_
,
k
:=
range
keys
{
v
:=
overrideArguments
[
k
]
// values of "" are allowed as well
// values of "" are allowed as well
command
=
append
(
command
,
fmt
.
Sprintf
(
"--%s=%s"
,
k
,
v
))
command
=
append
(
command
,
fmt
.
Sprintf
(
"--%s=%s"
,
k
,
v
))
}
}
for
k
,
v
:=
range
baseArguments
{
keys
=
[]
string
{}
for
k
:=
range
baseArguments
{
keys
=
append
(
keys
,
k
)
}
sort
.
Strings
(
keys
)
for
_
,
k
:=
range
keys
{
v
:=
baseArguments
[
k
]
if
_
,
overrideExists
:=
overrideArguments
[
k
];
!
overrideExists
{
if
_
,
overrideExists
:=
overrideArguments
[
k
];
!
overrideExists
{
command
=
append
(
command
,
fmt
.
Sprintf
(
"--%s=%s"
,
k
,
v
))
command
=
append
(
command
,
fmt
.
Sprintf
(
"--%s=%s"
,
k
,
v
))
}
}
...
...
cmd/kubeadm/app/util/arguments_test.go
View file @
5308957d
...
@@ -39,8 +39,8 @@ func TestBuildArgumentListFromMap(t *testing.T) {
...
@@ -39,8 +39,8 @@ func TestBuildArgumentListFromMap(t *testing.T) {
},
},
expected
:
[]
string
{
expected
:
[]
string
{
"--admission-control=NamespaceLifecycle,LimitRanger"
,
"--admission-control=NamespaceLifecycle,LimitRanger"
,
"--insecure-bind-address=127.0.0.1"
,
"--allow-privileged=true"
,
"--allow-privileged=true"
,
"--insecure-bind-address=127.0.0.1"
,
},
},
},
},
{
// add an argument that is not in base
{
// add an argument that is not in base
...
@@ -53,8 +53,8 @@ func TestBuildArgumentListFromMap(t *testing.T) {
...
@@ -53,8 +53,8 @@ func TestBuildArgumentListFromMap(t *testing.T) {
},
},
expected
:
[]
string
{
expected
:
[]
string
{
"--admission-control=NamespaceLifecycle,LimitRanger"
,
"--admission-control=NamespaceLifecycle,LimitRanger"
,
"--insecure-bind-address=127.0.0.1"
,
"--allow-privileged=true"
,
"--allow-privileged=true"
,
"--insecure-bind-address=127.0.0.1"
,
},
},
},
},
{
// allow empty strings in base
{
// allow empty strings in base
...
@@ -68,8 +68,8 @@ func TestBuildArgumentListFromMap(t *testing.T) {
...
@@ -68,8 +68,8 @@ func TestBuildArgumentListFromMap(t *testing.T) {
},
},
expected
:
[]
string
{
expected
:
[]
string
{
"--admission-control=NamespaceLifecycle,LimitRanger"
,
"--admission-control=NamespaceLifecycle,LimitRanger"
,
"--insecure-bind-address=127.0.0.1"
,
"--allow-privileged=true"
,
"--allow-privileged=true"
,
"--insecure-bind-address=127.0.0.1"
,
"--something-that-allows-empty-string="
,
"--something-that-allows-empty-string="
,
},
},
},
},
...
@@ -85,17 +85,15 @@ func TestBuildArgumentListFromMap(t *testing.T) {
...
@@ -85,17 +85,15 @@ func TestBuildArgumentListFromMap(t *testing.T) {
},
},
expected
:
[]
string
{
expected
:
[]
string
{
"--admission-control=NamespaceLifecycle,LimitRanger"
,
"--admission-control=NamespaceLifecycle,LimitRanger"
,
"--insecure-bind-address=127.0.0.1"
,
"--allow-privileged=true"
,
"--something-that-allows-empty-string="
,
"--something-that-allows-empty-string="
,
"--allow-privileged=true"
,
"--insecure-bind-address=127.0.0.1"
,
},
},
},
},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
actual
:=
BuildArgumentListFromMap
(
rt
.
base
,
rt
.
overrides
)
actual
:=
BuildArgumentListFromMap
(
rt
.
base
,
rt
.
overrides
)
sort
.
Strings
(
actual
)
sort
.
Strings
(
rt
.
expected
)
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
expected
)
{
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
expected
)
{
t
.
Errorf
(
"failed BuildArgumentListFromMap:
\n
expected:
\n
%v
\n
saw:
\n
%v"
,
rt
.
expected
,
actual
)
t
.
Errorf
(
"failed BuildArgumentListFromMap:
\n
expected:
\n
%v
\n
saw:
\n
%v"
,
rt
.
expected
,
actual
)
}
}
...
...
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