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
3e342077
Unverified
Commit
3e342077
authored
Nov 19, 2017
by
Mikhail Mazurskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix potential unexpected object mutation that can lead to data races
parent
c60b35bc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
10 deletions
+42
-10
converter.go
staging/src/k8s.io/apimachinery/pkg/runtime/converter.go
+2
-1
converter_test.go
...ing/src/k8s.io/apimachinery/pkg/runtime/converter_test.go
+38
-7
garbage_collector.go
test/e2e/apimachinery/garbage_collector.go
+2
-2
No files found.
staging/src/k8s.io/apimachinery/pkg/runtime/converter.go
View file @
3e342077
...
...
@@ -411,7 +411,8 @@ func (c *unstructuredConverter) ToUnstructured(obj interface{}) (map[string]inte
var
u
map
[
string
]
interface
{}
var
err
error
if
unstr
,
ok
:=
obj
.
(
Unstructured
);
ok
{
u
=
DeepCopyJSON
(
unstr
.
UnstructuredContent
())
// UnstructuredContent() mutates the object so we need to make a copy first
u
=
unstr
.
DeepCopyObject
()
.
(
Unstructured
)
.
UnstructuredContent
()
}
else
{
t
:=
reflect
.
TypeOf
(
obj
)
value
:=
reflect
.
ValueOf
(
obj
)
...
...
staging/src/k8s.io/apimachinery/pkg/runtime/converter_test.go
View file @
3e342077
...
...
@@ -135,7 +135,7 @@ func doRoundTrip(t *testing.T, item interface{}) {
return
}
unmarshalledObj
:=
reflect
.
New
(
reflect
.
TypeOf
(
item
)
.
Elem
())
.
Interface
()
err
=
json
.
Unmarshal
(
data
,
&
unmarshalledObj
)
err
=
json
.
Unmarshal
(
data
,
unmarshalledObj
)
if
err
!=
nil
{
t
.
Errorf
(
"Error when unmarshaling to object: %v"
,
err
)
return
...
...
@@ -170,6 +170,38 @@ func TestRoundTrip(t *testing.T) {
obj
interface
{}
}{
{
obj
:
&
unstructured
.
UnstructuredList
{
Object
:
map
[
string
]
interface
{}{
"kind"
:
"List"
,
},
// Not testing a list with nil Items because items is a non-optional field and hence
// is always marshaled into an empty array which is not equal to nil when unmarshalled and will fail.
// That is expected.
Items
:
[]
unstructured
.
Unstructured
{},
},
},
{
obj
:
&
unstructured
.
UnstructuredList
{
Object
:
map
[
string
]
interface
{}{
"kind"
:
"List"
,
},
Items
:
[]
unstructured
.
Unstructured
{
{
Object
:
map
[
string
]
interface
{}{
"kind"
:
"Pod"
,
},
},
},
},
},
{
obj
:
&
unstructured
.
Unstructured
{
Object
:
map
[
string
]
interface
{}{
"kind"
:
"Pod"
,
},
},
},
{
obj
:
&
unstructured
.
Unstructured
{
Object
:
map
[
string
]
interface
{}{
"apiVersion"
:
"v1"
,
...
...
@@ -260,7 +292,7 @@ func TestRoundTrip(t *testing.T) {
// produces the same object.
func
doUnrecognized
(
t
*
testing
.
T
,
jsonData
string
,
item
interface
{},
expectedErr
error
)
{
unmarshalledObj
:=
reflect
.
New
(
reflect
.
TypeOf
(
item
)
.
Elem
())
.
Interface
()
err
:=
json
.
Unmarshal
([]
byte
(
jsonData
),
&
unmarshalledObj
)
err
:=
json
.
Unmarshal
([]
byte
(
jsonData
),
unmarshalledObj
)
if
(
err
!=
nil
)
!=
(
expectedErr
!=
nil
)
{
t
.
Errorf
(
"Unexpected error when unmarshaling to object: %v, expected: %v"
,
err
,
expectedErr
)
return
...
...
@@ -465,11 +497,10 @@ func TestUnrecognized(t *testing.T) {
},
}
for
i
:=
range
testCases
{
doUnrecognized
(
t
,
testCases
[
i
]
.
data
,
testCases
[
i
]
.
obj
,
testCases
[
i
]
.
err
)
if
t
.
Failed
()
{
break
}
for
_
,
tc
:=
range
testCases
{
t
.
Run
(
tc
.
data
,
func
(
t
*
testing
.
T
)
{
doUnrecognized
(
t
,
tc
.
data
,
tc
.
obj
,
tc
.
err
)
})
}
}
...
...
test/e2e/apimachinery/garbage_collector.go
View file @
3e342077
...
...
@@ -919,8 +919,8 @@ var _ = SIGDescribe("Garbage collector", func() {
"kind"
:
definition
.
Spec
.
Names
.
Kind
,
"metadata"
:
map
[
string
]
interface
{}{
"name"
:
dependentName
,
"ownerReferences"
:
[]
map
[
string
]
string
{
{
"ownerReferences"
:
[]
interface
{}
{
map
[
string
]
interface
{}
{
"uid"
:
string
(
persistedOwner
.
GetUID
()),
"apiVersion"
:
apiVersion
,
"kind"
:
definition
.
Spec
.
Names
.
Kind
,
...
...
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