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
992aee0d
Commit
992aee0d
authored
Nov 27, 2017
by
Nikhita Raghunath
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add better error handling for unstructured helpers
parent
2aeace40
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
113 additions
and
96 deletions
+113
-96
helpers.go
....io/apimachinery/pkg/apis/meta/v1/unstructured/helpers.go
+99
-83
unstructured.go
...pimachinery/pkg/apis/meta/v1/unstructured/unstructured.go
+11
-11
unstructured_list_test.go
...y/pkg/apis/meta/v1/unstructured/unstructured_list_test.go
+3
-2
No files found.
staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/helpers.go
View file @
992aee0d
This diff is collapsed.
Click to expand it.
staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructured.go
View file @
992aee0d
...
...
@@ -138,8 +138,8 @@ func (u *Unstructured) setNestedMap(value map[string]string, fields ...string) {
}
func
(
u
*
Unstructured
)
GetOwnerReferences
()
[]
metav1
.
OwnerReference
{
field
,
ok
:=
nestedFieldNoCopy
(
u
.
Object
,
"metadata"
,
"ownerReferences"
)
if
!
ok
{
field
,
found
,
err
:=
nestedFieldNoCopy
(
u
.
Object
,
"metadata"
,
"ownerReferences"
)
if
!
found
||
err
!=
nil
{
return
nil
}
original
,
ok
:=
field
.
([]
interface
{})
...
...
@@ -228,8 +228,8 @@ func (u *Unstructured) SetResourceVersion(version string) {
}
func
(
u
*
Unstructured
)
GetGeneration
()
int64
{
val
,
ok
:=
NestedInt64
(
u
.
Object
,
"metadata"
,
"generation"
)
if
!
ok
{
val
,
found
,
err
:=
NestedInt64
(
u
.
Object
,
"metadata"
,
"generation"
)
if
!
found
||
err
!=
nil
{
return
0
}
return
val
...
...
@@ -289,8 +289,8 @@ func (u *Unstructured) SetDeletionTimestamp(timestamp *metav1.Time) {
}
func
(
u
*
Unstructured
)
GetDeletionGracePeriodSeconds
()
*
int64
{
val
,
ok
:=
NestedInt64
(
u
.
Object
,
"metadata"
,
"deletionGracePeriodSeconds"
)
if
!
ok
{
val
,
found
,
err
:=
NestedInt64
(
u
.
Object
,
"metadata"
,
"deletionGracePeriodSeconds"
)
if
!
found
||
err
!=
nil
{
return
nil
}
return
&
val
...
...
@@ -305,7 +305,7 @@ func (u *Unstructured) SetDeletionGracePeriodSeconds(deletionGracePeriodSeconds
}
func
(
u
*
Unstructured
)
GetLabels
()
map
[
string
]
string
{
m
,
_
:=
NestedStringMap
(
u
.
Object
,
"metadata"
,
"labels"
)
m
,
_
,
_
:=
NestedStringMap
(
u
.
Object
,
"metadata"
,
"labels"
)
return
m
}
...
...
@@ -314,7 +314,7 @@ func (u *Unstructured) SetLabels(labels map[string]string) {
}
func
(
u
*
Unstructured
)
GetAnnotations
()
map
[
string
]
string
{
m
,
_
:=
NestedStringMap
(
u
.
Object
,
"metadata"
,
"annotations"
)
m
,
_
,
_
:=
NestedStringMap
(
u
.
Object
,
"metadata"
,
"annotations"
)
return
m
}
...
...
@@ -337,8 +337,8 @@ func (u *Unstructured) GroupVersionKind() schema.GroupVersionKind {
}
func
(
u
*
Unstructured
)
GetInitializers
()
*
metav1
.
Initializers
{
m
,
ok
:=
nestedMapNoCopy
(
u
.
Object
,
"metadata"
,
"initializers"
)
if
!
ok
{
m
,
found
,
err
:=
nestedMapNoCopy
(
u
.
Object
,
"metadata"
,
"initializers"
)
if
!
found
||
err
!=
nil
{
return
nil
}
out
:=
&
metav1
.
Initializers
{}
...
...
@@ -362,7 +362,7 @@ func (u *Unstructured) SetInitializers(initializers *metav1.Initializers) {
}
func
(
u
*
Unstructured
)
GetFinalizers
()
[]
string
{
val
,
_
:=
NestedStringSlice
(
u
.
Object
,
"metadata"
,
"finalizers"
)
val
,
_
,
_
:=
NestedStringSlice
(
u
.
Object
,
"metadata"
,
"finalizers"
)
return
val
}
...
...
staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructured_list_test.go
View file @
992aee0d
...
...
@@ -35,8 +35,9 @@ func TestUnstructuredList(t *testing.T) {
content
:=
list
.
UnstructuredContent
()
items
:=
content
[
"items"
]
.
([]
interface
{})
require
.
Len
(
t
,
items
,
1
)
val
,
ok
:=
NestedFieldCopy
(
items
[
0
]
.
(
map
[
string
]
interface
{}),
"metadata"
,
"name"
)
require
.
True
(
t
,
ok
)
val
,
found
,
err
:=
NestedFieldCopy
(
items
[
0
]
.
(
map
[
string
]
interface
{}),
"metadata"
,
"name"
)
require
.
True
(
t
,
found
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
"test"
,
val
)
}
...
...
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