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
9b00a665
Commit
9b00a665
authored
Aug 21, 2016
by
Marcin Wielgus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Comments and extra tests for federated ObjectMeta utils
parent
b0ec300c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
+28
-2
meta.go
federation/pkg/federation-controller/util/meta.go
+6
-0
meta_test.go
federation/pkg/federation-controller/util/meta_test.go
+22
-2
No files found.
federation/pkg/federation-controller/util/meta.go
View file @
9b00a665
...
@@ -22,6 +22,9 @@ import (
...
@@ -22,6 +22,9 @@ import (
api_v1
"k8s.io/kubernetes/pkg/api/v1"
api_v1
"k8s.io/kubernetes/pkg/api/v1"
)
)
// Copies cluster-independent, user provided data from the given ObjectMeta struct. If in
// the future the ObjectMeta structure is expanded then any field that is not populared
// by the api server should be included here.
func
CopyObjectMeta
(
obj
api_v1
.
ObjectMeta
)
api_v1
.
ObjectMeta
{
func
CopyObjectMeta
(
obj
api_v1
.
ObjectMeta
)
api_v1
.
ObjectMeta
{
return
api_v1
.
ObjectMeta
{
return
api_v1
.
ObjectMeta
{
Name
:
obj
.
Name
,
Name
:
obj
.
Name
,
...
@@ -31,6 +34,9 @@ func CopyObjectMeta(obj api_v1.ObjectMeta) api_v1.ObjectMeta {
...
@@ -31,6 +34,9 @@ func CopyObjectMeta(obj api_v1.ObjectMeta) api_v1.ObjectMeta {
}
}
}
}
// Checks if cluster-independed, user provided data in two given ObjectMeta are eqaul. If in
// the future the ObjectMeta structure is expanded then any field that is not populared
// by the api server should be included here.
func
ObjectMetaEquivalent
(
a
,
b
api_v1
.
ObjectMeta
)
bool
{
func
ObjectMetaEquivalent
(
a
,
b
api_v1
.
ObjectMeta
)
bool
{
if
a
.
Name
!=
b
.
Name
{
if
a
.
Name
!=
b
.
Name
{
return
false
return
false
...
...
federation/pkg/federation-controller/util/meta_test.go
View file @
9b00a665
...
@@ -31,17 +31,37 @@ func TestObjectMeta(t *testing.T) {
...
@@ -31,17 +31,37 @@ func TestObjectMeta(t *testing.T) {
UID
:
"1231231412"
,
UID
:
"1231231412"
,
ResourceVersion
:
"999"
,
ResourceVersion
:
"999"
,
}
}
o2
:=
CopyObjectMeta
(
o1
)
o3
:=
api_v1
.
ObjectMeta
{
o3
:=
api_v1
.
ObjectMeta
{
Namespace
:
"ns1"
,
Namespace
:
"ns1"
,
Name
:
"s1"
,
Name
:
"s1"
,
UID
:
"1231231412"
,
UID
:
"1231231412"
,
Annotations
:
map
[
string
]
string
{
"A"
:
"B"
},
Annotations
:
map
[
string
]
string
{
"A"
:
"B"
},
}
}
o4
:=
api_v1
.
ObjectMeta
{
o2
:=
CopyObjectMeta
(
o1
)
Namespace
:
"ns1"
,
Name
:
"s1"
,
UID
:
"1231255531412"
,
Annotations
:
map
[
string
]
string
{
"A"
:
"B"
},
}
o5
:=
api_v1
.
ObjectMeta
{
Namespace
:
"ns1"
,
Name
:
"s1"
,
ResourceVersion
:
"1231231412"
,
Annotations
:
map
[
string
]
string
{
"A"
:
"B"
},
}
o6
:=
api_v1
.
ObjectMeta
{
Namespace
:
"ns1"
,
Name
:
"s1"
,
ResourceVersion
:
"1231255531412"
,
Annotations
:
map
[
string
]
string
{
"A"
:
"B"
},
}
assert
.
Equal
(
t
,
0
,
len
(
o2
.
UID
))
assert
.
Equal
(
t
,
0
,
len
(
o2
.
UID
))
assert
.
Equal
(
t
,
0
,
len
(
o2
.
ResourceVersion
))
assert
.
Equal
(
t
,
0
,
len
(
o2
.
ResourceVersion
))
assert
.
Equal
(
t
,
o1
.
Name
,
o2
.
Name
)
assert
.
Equal
(
t
,
o1
.
Name
,
o2
.
Name
)
assert
.
True
(
t
,
ObjectMetaEquivalent
(
o1
,
o2
))
assert
.
True
(
t
,
ObjectMetaEquivalent
(
o1
,
o2
))
assert
.
False
(
t
,
ObjectMetaEquivalent
(
o1
,
o3
))
assert
.
False
(
t
,
ObjectMetaEquivalent
(
o1
,
o3
))
assert
.
True
(
t
,
ObjectMetaEquivalent
(
o3
,
o4
))
assert
.
True
(
t
,
ObjectMetaEquivalent
(
o5
,
o6
))
assert
.
True
(
t
,
ObjectMetaEquivalent
(
o3
,
o5
))
}
}
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