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
4cbdbae6
Commit
4cbdbae6
authored
Mar 13, 2018
by
Davanum Srinivas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing binaryData field to the ConfigMap Hash
In
7e158fb4
, we added a BinaryData to ConfigMap, but totally forgot to add it to the hash method.
parent
34001d8c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
2 deletions
+22
-2
hash.go
pkg/kubectl/util/hash/hash.go
+5
-1
hash_test.go
pkg/kubectl/util/hash/hash_test.go
+17
-1
No files found.
pkg/kubectl/util/hash/hash.go
View file @
4cbdbae6
...
@@ -56,7 +56,11 @@ func SecretHash(sec *v1.Secret) (string, error) {
...
@@ -56,7 +56,11 @@ func SecretHash(sec *v1.Secret) (string, error) {
// Data, Kind, and Name are taken into account.
// Data, Kind, and Name are taken into account.
func
encodeConfigMap
(
cm
*
v1
.
ConfigMap
)
(
string
,
error
)
{
func
encodeConfigMap
(
cm
*
v1
.
ConfigMap
)
(
string
,
error
)
{
// json.Marshal sorts the keys in a stable order in the encoding
// json.Marshal sorts the keys in a stable order in the encoding
data
,
err
:=
json
.
Marshal
(
map
[
string
]
interface
{}{
"kind"
:
"ConfigMap"
,
"name"
:
cm
.
Name
,
"data"
:
cm
.
Data
})
m
:=
map
[
string
]
interface
{}{
"kind"
:
"ConfigMap"
,
"name"
:
cm
.
Name
,
"data"
:
cm
.
Data
}
if
len
(
cm
.
BinaryData
)
>
0
{
m
[
"binaryData"
]
=
cm
.
BinaryData
}
data
,
err
:=
json
.
Marshal
(
m
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
...
...
pkg/kubectl/util/hash/hash_test.go
View file @
4cbdbae6
...
@@ -32,11 +32,19 @@ func TestConfigMapHash(t *testing.T) {
...
@@ -32,11 +32,19 @@ func TestConfigMapHash(t *testing.T) {
err
string
err
string
}{
}{
// empty map
// empty map
{
"empty data"
,
&
v1
.
ConfigMap
{
Data
:
map
[
string
]
string
{}},
"42745tchd9"
,
""
},
{
"empty data"
,
&
v1
.
ConfigMap
{
Data
:
map
[
string
]
string
{}
,
BinaryData
:
map
[
string
][]
byte
{}
},
"42745tchd9"
,
""
},
// one key
// one key
{
"one key"
,
&
v1
.
ConfigMap
{
Data
:
map
[
string
]
string
{
"one"
:
""
}},
"9g67k2htb6"
,
""
},
{
"one key"
,
&
v1
.
ConfigMap
{
Data
:
map
[
string
]
string
{
"one"
:
""
}},
"9g67k2htb6"
,
""
},
// three keys (tests sorting order)
// three keys (tests sorting order)
{
"three keys"
,
&
v1
.
ConfigMap
{
Data
:
map
[
string
]
string
{
"two"
:
"2"
,
"one"
:
""
,
"three"
:
"3"
}},
"f5h7t85m9b"
,
""
},
{
"three keys"
,
&
v1
.
ConfigMap
{
Data
:
map
[
string
]
string
{
"two"
:
"2"
,
"one"
:
""
,
"three"
:
"3"
}},
"f5h7t85m9b"
,
""
},
// empty binary data map
{
"empty binary data"
,
&
v1
.
ConfigMap
{
BinaryData
:
map
[
string
][]
byte
{}},
"dk855m5d49"
,
""
},
// one key with binary data
{
"one key with binary data"
,
&
v1
.
ConfigMap
{
BinaryData
:
map
[
string
][]
byte
{
"one"
:
[]
byte
(
""
)}},
"mk79584b8c"
,
""
},
// three keys with binary data (tests sorting order)
{
"three keys with binary data"
,
&
v1
.
ConfigMap
{
BinaryData
:
map
[
string
][]
byte
{
"two"
:
[]
byte
(
"2"
),
"one"
:
[]
byte
(
""
),
"three"
:
[]
byte
(
"3"
)}},
"t458mc6db2"
,
""
},
// two keys, one with string and another with binary data
{
"two keys with one each"
,
&
v1
.
ConfigMap
{
Data
:
map
[
string
]
string
{
"one"
:
""
},
BinaryData
:
map
[
string
][]
byte
{
"two"
:
[]
byte
(
""
)}},
"698h7c7t9m"
,
""
},
}
}
for
_
,
c
:=
range
cases
{
for
_
,
c
:=
range
cases
{
...
@@ -89,6 +97,14 @@ func TestEncodeConfigMap(t *testing.T) {
...
@@ -89,6 +97,14 @@ func TestEncodeConfigMap(t *testing.T) {
{
"one key"
,
&
v1
.
ConfigMap
{
Data
:
map
[
string
]
string
{
"one"
:
""
}},
`{"data":{"one":""},"kind":"ConfigMap","name":""}`
,
""
},
{
"one key"
,
&
v1
.
ConfigMap
{
Data
:
map
[
string
]
string
{
"one"
:
""
}},
`{"data":{"one":""},"kind":"ConfigMap","name":""}`
,
""
},
// three keys (tests sorting order)
// three keys (tests sorting order)
{
"three keys"
,
&
v1
.
ConfigMap
{
Data
:
map
[
string
]
string
{
"two"
:
"2"
,
"one"
:
""
,
"three"
:
"3"
}},
`{"data":{"one":"","three":"3","two":"2"},"kind":"ConfigMap","name":""}`
,
""
},
{
"three keys"
,
&
v1
.
ConfigMap
{
Data
:
map
[
string
]
string
{
"two"
:
"2"
,
"one"
:
""
,
"three"
:
"3"
}},
`{"data":{"one":"","three":"3","two":"2"},"kind":"ConfigMap","name":""}`
,
""
},
// empty binary map
{
"empty data"
,
&
v1
.
ConfigMap
{
BinaryData
:
map
[
string
][]
byte
{}},
`{"data":null,"kind":"ConfigMap","name":""}`
,
""
},
// one key with binary data
{
"one key"
,
&
v1
.
ConfigMap
{
BinaryData
:
map
[
string
][]
byte
{
"one"
:
[]
byte
(
""
)}},
`{"binaryData":{"one":""},"data":null,"kind":"ConfigMap","name":""}`
,
""
},
// three keys with binary data (tests sorting order)
{
"three keys"
,
&
v1
.
ConfigMap
{
BinaryData
:
map
[
string
][]
byte
{
"two"
:
[]
byte
(
"2"
),
"one"
:
[]
byte
(
""
),
"three"
:
[]
byte
(
"3"
)}},
`{"binaryData":{"one":"","three":"Mw==","two":"Mg=="},"data":null,"kind":"ConfigMap","name":""}`
,
""
},
// two keys, one string and one binary values
{
"two keys with one each"
,
&
v1
.
ConfigMap
{
Data
:
map
[
string
]
string
{
"one"
:
""
},
BinaryData
:
map
[
string
][]
byte
{
"two"
:
[]
byte
(
""
)}},
`{"binaryData":{"two":""},"data":{"one":""},"kind":"ConfigMap","name":""}`
,
""
},
}
}
for
_
,
c
:=
range
cases
{
for
_
,
c
:=
range
cases
{
s
,
err
:=
encodeConfigMap
(
c
.
cm
)
s
,
err
:=
encodeConfigMap
(
c
.
cm
)
...
...
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