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
1fd45cfb
Unverified
Commit
1fd45cfb
authored
Nov 29, 2018
by
k8s-ci-robot
Committed by
GitHub
Nov 29, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #71272 from sttts/sttts-unstructured-accessor-intermediate-not-found
unstructured: return not-found if intermediate path is not found
parents
a08d89c0
52b1718a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
0 deletions
+16
-0
helpers.go
....io/apimachinery/pkg/apis/meta/v1/unstructured/helpers.go
+3
-0
helpers_test.go
...pimachinery/pkg/apis/meta/v1/unstructured/helpers_test.go
+13
-0
No files found.
staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/helpers.go
View file @
1fd45cfb
...
@@ -47,6 +47,9 @@ func NestedFieldNoCopy(obj map[string]interface{}, fields ...string) (interface{
...
@@ -47,6 +47,9 @@ func NestedFieldNoCopy(obj map[string]interface{}, fields ...string) (interface{
var
val
interface
{}
=
obj
var
val
interface
{}
=
obj
for
i
,
field
:=
range
fields
{
for
i
,
field
:=
range
fields
{
if
val
==
nil
{
return
nil
,
false
,
nil
}
if
m
,
ok
:=
val
.
(
map
[
string
]
interface
{});
ok
{
if
m
,
ok
:=
val
.
(
map
[
string
]
interface
{});
ok
{
val
,
ok
=
m
[
field
]
val
,
ok
=
m
[
field
]
if
!
ok
{
if
!
ok
{
...
...
staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/helpers_test.go
View file @
1fd45cfb
...
@@ -95,6 +95,19 @@ func TestNestedFieldNoCopy(t *testing.T) {
...
@@ -95,6 +95,19 @@ func TestNestedFieldNoCopy(t *testing.T) {
assert
.
False
(
t
,
exists
)
assert
.
False
(
t
,
exists
)
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
res
)
assert
.
Nil
(
t
,
res
)
// case 5: intermediate field does not exist
res
,
exists
,
err
=
NestedFieldNoCopy
(
obj
,
"a"
,
"e"
,
"f"
)
assert
.
False
(
t
,
exists
)
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
res
)
// case 6: intermediate field is null
// (background: happens easily in YAML)
res
,
exists
,
err
=
NestedFieldNoCopy
(
obj
,
"a"
,
"c"
,
"f"
)
assert
.
False
(
t
,
exists
)
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
res
)
}
}
func
TestNestedFieldCopy
(
t
*
testing
.
T
)
{
func
TestNestedFieldCopy
(
t
*
testing
.
T
)
{
...
...
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