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
a269491f
Commit
a269491f
authored
Feb 22, 2018
by
Ayush Pateria
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify tests
parent
1beed0f4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
22 deletions
+28
-22
controller_history.go
pkg/controller/history/controller_history.go
+6
-3
controller_history_test.go
pkg/controller/history/controller_history_test.go
+21
-17
stateful_set_utils.go
pkg/controller/statefulset/stateful_set_utils.go
+1
-2
No files found.
pkg/controller/history/controller_history.go
View file @
a269491f
...
...
@@ -56,17 +56,20 @@ func ControllerRevisionName(prefix string, hash uint32) string {
}
// NewControllerRevision returns a ControllerRevision with a ControllerRef pointing to parent and indicating that
// parent is of parentKind. The ControllerRevision has labels matching
pod
, contains Data equal to data, and
// parent is of parentKind. The ControllerRevision has labels matching
template labels
, contains Data equal to data, and
// has a Revision equal to revision. The collisionCount is used when creating the name of the ControllerRevision
// so the name is likely unique. If the returned error is nil, the returned ControllerRevision is valid. If the
// returned error is not nil, the returned ControllerRevision is invalid for use.
func
NewControllerRevision
(
parent
metav1
.
Object
,
parentKind
schema
.
GroupVersionKind
,
pod
Labels
map
[
string
]
string
,
template
Labels
map
[
string
]
string
,
data
runtime
.
RawExtension
,
revision
int64
,
collisionCount
*
int32
)
(
*
apps
.
ControllerRevision
,
error
)
{
labelMap
:=
podLabels
labelMap
:=
make
(
map
[
string
]
string
)
for
k
,
v
:=
range
templateLabels
{
labelMap
[
k
]
=
v
}
blockOwnerDeletion
:=
true
isController
:=
true
cr
:=
&
apps
.
ControllerRevision
{
...
...
pkg/controller/history/controller_history_test.go
View file @
a269491f
...
...
@@ -77,8 +77,10 @@ func TestRealHistory_ListControllerRevisions(t *testing.T) {
}
ss1
:=
newStatefulSet
(
3
,
"ss1"
,
types
.
UID
(
"ss1"
),
map
[
string
]
string
{
"foo"
:
"bar"
})
ss2
:=
newStatefulSet
(
3
,
"ss2"
,
types
.
UID
(
"ss2"
),
map
[
string
]
string
{
"goo"
:
"car"
})
sel1
:=
labels
.
Set
(
ss1
.
Spec
.
Template
.
Labels
)
.
AsSelector
()
sel1
,
err
:=
metav1
.
LabelSelectorAsSelector
(
ss1
.
Spec
.
Selector
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
ss1Rev1
,
err
:=
NewControllerRevision
(
ss1
,
parentKind
,
ss1
.
Spec
.
Template
.
Labels
,
rawTemplate
(
&
ss1
.
Spec
.
Template
),
1
,
nil
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -172,7 +174,10 @@ func TestFakeHistory_ListControllerRevisions(t *testing.T) {
}
ss1
:=
newStatefulSet
(
3
,
"ss1"
,
types
.
UID
(
"ss1"
),
map
[
string
]
string
{
"foo"
:
"bar"
})
ss2
:=
newStatefulSet
(
3
,
"ss2"
,
types
.
UID
(
"ss2"
),
map
[
string
]
string
{
"goo"
:
"car"
})
sel1
:=
labels
.
Set
(
ss1
.
Spec
.
Template
.
Labels
)
.
AsSelector
()
sel1
,
err
:=
metav1
.
LabelSelectorAsSelector
(
ss1
.
Spec
.
Selector
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
ss1Rev1
,
err
:=
NewControllerRevision
(
ss1
,
parentKind
,
ss1
.
Spec
.
Template
.
Labels
,
rawTemplate
(
&
ss1
.
Spec
.
Template
),
1
,
nil
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -1539,6 +1544,7 @@ func TestSortControllerRevisions(t *testing.T) {
}
ss1
:=
newStatefulSet
(
3
,
"ss1"
,
types
.
UID
(
"ss1"
),
map
[
string
]
string
{
"foo"
:
"bar"
})
ss1
.
Status
.
CollisionCount
=
new
(
int32
)
ss1Rev1
,
err
:=
NewControllerRevision
(
ss1
,
parentKind
,
ss1
.
Spec
.
Template
.
Labels
,
rawTemplate
(
&
ss1
.
Spec
.
Template
),
1
,
ss1
.
Status
.
CollisionCount
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -1583,13 +1589,15 @@ func TestSortControllerRevisions(t *testing.T) {
}
func
newStatefulSet
(
replicas
int
,
name
string
,
uid
types
.
UID
,
labels
map
[
string
]
string
)
*
apps
.
StatefulSet
{
var
testLabelKey
string
var
testLabelValue
string
// Get the first label's key, value to be used for set based selector.
// Converting all the map-only selectors to set-based selectors.
var
testMatchExpressions
[]
metav1
.
LabelSelectorRequirement
for
key
,
value
:=
range
labels
{
testLabelKey
=
key
testLabelValue
=
value
break
sel
:=
metav1
.
LabelSelectorRequirement
{
Key
:
key
,
Operator
:
metav1
.
LabelSelectorOpIn
,
Values
:
[]
string
{
value
},
}
testMatchExpressions
=
append
(
testMatchExpressions
,
sel
)
}
return
&
apps
.
StatefulSet
{
TypeMeta
:
metav1
.
TypeMeta
{
...
...
@@ -1603,14 +1611,10 @@ func newStatefulSet(replicas int, name string, uid types.UID, labels map[string]
},
Spec
:
apps
.
StatefulSetSpec
{
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
labels
,
MatchExpressions
:
[]
metav1
.
LabelSelectorRequirement
{
{
Key
:
testLabelKey
,
Operator
:
metav1
.
LabelSelectorOpIn
,
Values
:
[]
string
{
testLabelValue
},
},
},
// Purposely leaving MatchLabels nil, so to ensure it will break if any link
// in the chain ignores the set-based MatchExpressions.
MatchLabels
:
nil
,
MatchExpressions
:
testMatchExpressions
,
},
Replicas
:
func
()
*
int32
{
i
:=
int32
(
replicas
);
return
&
i
}(),
Template
:
v1
.
PodTemplateSpec
{
...
...
pkg/controller/statefulset/stateful_set_utils.go
View file @
a269491f
...
...
@@ -312,10 +312,9 @@ func newRevision(set *apps.StatefulSet, revision int64, collisionCount *int32) (
if
err
!=
nil
{
return
nil
,
err
}
podLabels
:=
set
.
Spec
.
Template
.
Labels
cr
,
err
:=
history
.
NewControllerRevision
(
set
,
controllerKind
,
pod
Labels
,
set
.
Spec
.
Template
.
Labels
,
runtime
.
RawExtension
{
Raw
:
patch
},
revision
,
collisionCount
)
...
...
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