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
1f840944
Commit
1f840944
authored
Dec 04, 2017
by
Josh Horwitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure PVL controller is next pending initializer before labeling the PV
parent
21751996
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
11 deletions
+17
-11
pvlcontroller.go
pkg/controller/cloud/pvlcontroller.go
+11
-10
pvlcontroller_test.go
pkg/controller/cloud/pvlcontroller_test.go
+6
-1
No files found.
pkg/controller/cloud/pvlcontroller.go
View file @
1f840944
...
...
@@ -182,7 +182,7 @@ func (pvlc *PersistentVolumeLabelController) addLabels(key string) error {
func
(
pvlc
*
PersistentVolumeLabelController
)
addLabelsToVolume
(
vol
*
v1
.
PersistentVolume
)
error
{
var
volumeLabels
map
[
string
]
string
// Only add labels if
in the list of initializers
// Only add labels if
the next pending initializer.
if
needsInitialization
(
vol
.
Initializers
,
initializerName
)
{
if
labeler
,
ok
:=
(
pvlc
.
cloud
)
.
(
cloudprovider
.
PVLabeler
);
ok
{
labels
,
err
:=
labeler
.
GetLabelsForVolume
(
vol
)
...
...
@@ -265,16 +265,17 @@ func removeInitializer(initializers *metav1.Initializers, name string) *metav1.I
return
&
metav1
.
Initializers
{
Pending
:
updated
}
}
// needsInitialization checks whether or not the PVL is the next pending initializer.
func
needsInitialization
(
initializers
*
metav1
.
Initializers
,
name
string
)
bool
{
hasInitializer
:=
false
if
initializers
==
nil
{
return
false
}
if
initializers
!=
nil
{
for
_
,
pending
:=
range
initializers
.
Pending
{
if
pending
.
Name
==
name
{
hasInitializer
=
true
break
}
}
if
len
(
initializers
.
Pending
)
==
0
{
return
false
}
return
hasInitializer
// There is at least one initializer still pending so check to
// see if the PVL is the next in line.
return
initializers
.
Pending
[
0
]
.
Name
==
name
}
pkg/controller/cloud/pvlcontroller_test.go
View file @
1f840944
...
...
@@ -146,11 +146,16 @@ func TestAddLabelsToVolume(t *testing.T) {
initializers
:
&
metav1
.
Initializers
{
Pending
:
[]
metav1
.
Initializer
{{
Name
:
initializerName
}}},
shouldLabel
:
true
,
},
"PV with other initializers"
:
{
"PV with other initializers
only
"
:
{
vol
:
pv
,
initializers
:
&
metav1
.
Initializers
{
Pending
:
[]
metav1
.
Initializer
{{
Name
:
"OtherInit"
}}},
shouldLabel
:
false
,
},
"PV with other initializers first"
:
{
vol
:
pv
,
initializers
:
&
metav1
.
Initializers
{
Pending
:
[]
metav1
.
Initializer
{{
Name
:
"OtherInit"
},
{
Name
:
initializerName
}}},
shouldLabel
:
false
,
},
}
for
d
,
tc
:=
range
testCases
{
...
...
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