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
7d398058
Commit
7d398058
authored
Jan 16, 2019
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove Initializer use from pv label controller
parent
047ecae1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
80 deletions
+27
-80
pvlcontroller.go
pkg/controller/cloud/pvlcontroller.go
+9
-38
pvlcontroller_test.go
pkg/controller/cloud/pvlcontroller_test.go
+18
-42
No files found.
pkg/controller/cloud/pvlcontroller.go
View file @
7d398058
...
...
@@ -44,8 +44,6 @@ import (
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
)
const
initializerName
=
"pvlabel.kubernetes.io"
// PersistentVolumeLabelController handles adding labels to persistent volumes when they are created
type
PersistentVolumeLabelController
struct
{
cloud
cloudprovider
.
Interface
...
...
@@ -74,11 +72,9 @@ func NewPersistentVolumeLabelController(
pvlc
.
pvlIndexer
,
pvlc
.
pvlController
=
cache
.
NewIndexerInformer
(
&
cache
.
ListWatch
{
ListFunc
:
func
(
options
metav1
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
options
.
IncludeUninitialized
=
true
return
kubeClient
.
CoreV1
()
.
PersistentVolumes
()
.
List
(
options
)
},
WatchFunc
:
func
(
options
metav1
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
options
.
IncludeUninitialized
=
true
return
kubeClient
.
CoreV1
()
.
PersistentVolumes
()
.
Watch
(
options
)
},
},
...
...
@@ -184,7 +180,7 @@ func (pvlc *PersistentVolumeLabelController) addLabelsAndAffinity(key string) er
func
(
pvlc
*
PersistentVolumeLabelController
)
addLabelsAndAffinityToVolume
(
vol
*
v1
.
PersistentVolume
)
error
{
var
volumeLabels
map
[
string
]
string
// Only add labels if the next pending initializer.
if
needsInitialization
(
vol
.
Initializers
,
initializerName
)
{
if
needsInitialization
(
vol
)
{
if
labeler
,
ok
:=
(
pvlc
.
cloud
)
.
(
cloudprovider
.
PVLabeler
);
ok
{
labels
,
err
:=
labeler
.
GetLabelsForVolume
(
context
.
TODO
(),
vol
)
if
err
!=
nil
{
...
...
@@ -249,8 +245,8 @@ func (pvlc *PersistentVolumeLabelController) createPatch(vol *v1.PersistentVolum
}
}
}
newVolume
.
Initializers
=
removeInitializer
(
newVolume
.
Initializers
,
initializerNa
me
)
klog
.
V
(
4
)
.
Infof
(
"
removed initializer on PersistentVolume %s
"
,
newVolume
.
Name
)
markInitialized
(
newVolu
me
)
klog
.
V
(
4
)
.
Infof
(
"
marked PersistentVolume %s initialized
"
,
newVolume
.
Name
)
oldData
,
err
:=
json
.
Marshal
(
vol
)
if
err
!=
nil
{
...
...
@@ -286,38 +282,13 @@ func (pvlc *PersistentVolumeLabelController) updateVolume(vol *v1.PersistentVolu
return
nil
}
func
removeInitializer
(
initializers
*
metav1
.
Initializers
,
name
string
)
*
metav1
.
Initializers
{
if
initializers
==
nil
{
return
nil
}
var
updated
[]
metav1
.
Initializer
for
_
,
pending
:=
range
initializers
.
Pending
{
if
pending
.
Name
!=
name
{
updated
=
append
(
updated
,
pending
)
}
}
if
len
(
updated
)
==
len
(
initializers
.
Pending
)
{
return
initializers
}
if
len
(
updated
)
==
0
{
return
nil
}
return
&
metav1
.
Initializers
{
Pending
:
updated
}
func
markInitialized
(
vol
*
v1
.
PersistentVolume
)
{
// TODO: mark initialized using a different field, since initializers are not being promoted past alpha, or convert to an admission plugin
}
// needsInitialization checks whether or not the PVL is the next pending initializer.
func
needsInitialization
(
initializers
*
metav1
.
Initializers
,
name
string
)
bool
{
if
initializers
==
nil
{
return
false
}
if
len
(
initializers
.
Pending
)
==
0
{
return
false
}
// 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
func
needsInitialization
(
vol
*
v1
.
PersistentVolume
)
bool
{
// TODO: determine whether initialization is required based on a different attribute,
// since initializers are not being promoted past alpha, or convert to an admission plugin
return
false
}
pkg/controller/cloud/pvlcontroller_test.go
View file @
7d398058
...
...
@@ -129,13 +129,6 @@ func TestCreatePatch(t *testing.T) {
ignoredPV
:=
v1
.
PersistentVolume
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"noncloud"
,
Initializers
:
&
metav1
.
Initializers
{
Pending
:
[]
metav1
.
Initializer
{
{
Name
:
initializerName
,
},
},
},
},
Spec
:
v1
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
v1
.
PersistentVolumeSource
{
...
...
@@ -148,13 +141,6 @@ func TestCreatePatch(t *testing.T) {
awsPV
:=
v1
.
PersistentVolume
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"awsPV"
,
Initializers
:
&
metav1
.
Initializers
{
Pending
:
[]
metav1
.
Initializer
{
{
Name
:
initializerName
,
},
},
},
},
Spec
:
v1
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
v1
.
PersistentVolumeSource
{
...
...
@@ -217,13 +203,6 @@ func TestCreatePatch(t *testing.T) {
awsPVWithAffinity
:=
v1
.
PersistentVolume
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"awsPV"
,
Initializers
:
&
metav1
.
Initializers
{
Pending
:
[]
metav1
.
Initializer
{
{
Name
:
initializerName
,
},
},
},
},
Spec
:
v1
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
v1
.
PersistentVolumeSource
{
...
...
@@ -458,9 +437,12 @@ func TestCreatePatch(t *testing.T) {
}
obj
:=
&
v1
.
PersistentVolume
{}
json
.
Unmarshal
(
patch
,
obj
)
if
obj
.
ObjectMeta
.
Initializers
!=
nil
{
t
.
Errorf
(
"%s: initializer wasn't removed: %v"
,
d
,
obj
.
ObjectMeta
.
Initializers
)
}
// TODO: check if object was marked as initialized
// if ... object was not marked as initialized ... {
// t.Errorf("%s: wasn't marked as initialized: %#v", d, obj)
// }
if
tc
.
labels
==
nil
{
continue
}
...
...
@@ -491,29 +473,24 @@ func TestAddLabelsToVolume(t *testing.T) {
testCases
:=
map
[
string
]
struct
{
vol
v1
.
PersistentVolume
initializers
*
metav1
.
Initializers
shouldLabelAndSetAffinity
bool
}{
"PV without initializer"
:
{
vol
:
pv
,
initializers
:
nil
,
shouldLabelAndSetAffinity
:
false
,
},
"PV with initializer to remove"
:
{
vol
:
pv
,
initializers
:
&
metav1
.
Initializers
{
Pending
:
[]
metav1
.
Initializer
{{
Name
:
initializerName
}}},
shouldLabelAndSetAffinity
:
true
,
},
"PV with other initializers only"
:
{
vol
:
pv
,
initializers
:
&
metav1
.
Initializers
{
Pending
:
[]
metav1
.
Initializer
{{
Name
:
"OtherInit"
}}},
shouldLabelAndSetAffinity
:
false
,
},
"PV with other initializers first"
:
{
vol
:
pv
,
initializers
:
&
metav1
.
Initializers
{
Pending
:
[]
metav1
.
Initializer
{{
Name
:
"OtherInit"
},
{
Name
:
initializerName
}}},
shouldLabelAndSetAffinity
:
false
,
},
// "PV with initializer to remove": {
// vol: pv,
// shouldLabelAndSetAffinity: true,
// },
// "PV with other initializers only": {
// vol: pv,
// shouldLabelAndSetAffinity: false,
// },
// "PV with other initializers first": {
// vol: pv,
// shouldLabelAndSetAffinity: false,
// },
}
for
d
,
tc
:=
range
testCases
{
...
...
@@ -550,7 +527,6 @@ func TestAddLabelsToVolume(t *testing.T) {
VolumeLabelMap
:
map
[
string
]
map
[
string
]
string
{
"awsPV"
:
{
"a"
:
"1"
}},
}
pvlController
:=
&
PersistentVolumeLabelController
{
kubeClient
:
client
,
cloud
:
fakeCloud
}
tc
.
vol
.
ObjectMeta
.
Initializers
=
tc
.
initializers
pvlController
.
addLabelsAndAffinityToVolume
(
&
tc
.
vol
)
select
{
...
...
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