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
22fce22a
Commit
22fce22a
authored
Jan 21, 2019
by
andrewsykim
Committed by
Andrew Kim
Jan 24, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for Cinder volumes in PersistentVolumeLabel admission controller
parent
1a316015
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
3 deletions
+60
-3
admission.go
...pkg/admission/storage/persistentvolume/label/admission.go
+60
-3
No files found.
plugin/pkg/admission/storage/persistentvolume/label/admission.go
View file @
22fce22a
...
@@ -70,9 +70,9 @@ var _ kubeapiserveradmission.WantsCloudConfig = &persistentVolumeLabel{}
...
@@ -70,9 +70,9 @@ var _ kubeapiserveradmission.WantsCloudConfig = &persistentVolumeLabel{}
//
//
// As a side effect, the cloud provider may block invalid or non-existent volumes.
// As a side effect, the cloud provider may block invalid or non-existent volumes.
func
newPersistentVolumeLabel
()
*
persistentVolumeLabel
{
func
newPersistentVolumeLabel
()
*
persistentVolumeLabel
{
// DEPRECATED:
cloud-controller-manager will now start NewPersistentVolumeLabelController
// DEPRECATED:
in a future release, we will use mutating admission webhooks to apply PV labels.
//
which does exactly what this admission controller used to do. So once GCE, AWS and AZURE can
//
Once the mutating admission webhook is used for AWS, Azure, GCE, and OpenStack,
//
run externally, we can remove this admission controller
.
//
this admission controller will be removed
.
klog
.
Warning
(
"PersistentVolumeLabel admission controller is deprecated. "
+
klog
.
Warning
(
"PersistentVolumeLabel admission controller is deprecated. "
+
"Please remove this controller from your configuration files and scripts."
)
"Please remove this controller from your configuration files and scripts."
)
return
&
persistentVolumeLabel
{
return
&
persistentVolumeLabel
{
...
@@ -132,6 +132,13 @@ func (l *persistentVolumeLabel) Admit(a admission.Attributes) (err error) {
...
@@ -132,6 +132,13 @@ func (l *persistentVolumeLabel) Admit(a admission.Attributes) (err error) {
}
}
volumeLabels
=
labels
volumeLabels
=
labels
}
}
if
volume
.
Spec
.
Cinder
!=
nil
{
labels
,
err
:=
l
.
findCinderDiskLabels
(
volume
)
if
err
!=
nil
{
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"error querying Cinder volume %s: %v"
,
volume
.
Spec
.
Cinder
.
VolumeID
,
err
))
}
volumeLabels
=
labels
}
requirements
:=
make
([]
api
.
NodeSelectorRequirement
,
0
)
requirements
:=
make
([]
api
.
NodeSelectorRequirement
,
0
)
if
len
(
volumeLabels
)
!=
0
{
if
len
(
volumeLabels
)
!=
0
{
...
@@ -327,3 +334,53 @@ func (l *persistentVolumeLabel) findAzureDiskLabels(volume *api.PersistentVolume
...
@@ -327,3 +334,53 @@ func (l *persistentVolumeLabel) findAzureDiskLabels(volume *api.PersistentVolume
}
}
return
pvlabler
.
GetLabelsForVolume
(
context
.
TODO
(),
pv
)
return
pvlabler
.
GetLabelsForVolume
(
context
.
TODO
(),
pv
)
}
}
func
(
l
*
persistentVolumeLabel
)
getOpenStackPVLabeler
()
(
cloudprovider
.
PVLabeler
,
error
)
{
l
.
mutex
.
Lock
()
defer
l
.
mutex
.
Unlock
()
if
l
.
openStackPVLabeler
==
nil
{
var
cloudConfigReader
io
.
Reader
if
len
(
l
.
cloudConfig
)
>
0
{
cloudConfigReader
=
bytes
.
NewReader
(
l
.
cloudConfig
)
}
cloudProvider
,
err
:=
cloudprovider
.
GetCloudProvider
(
"openstack"
,
cloudConfigReader
)
if
err
!=
nil
||
cloudProvider
==
nil
{
return
nil
,
err
}
openStackPVLabeler
,
ok
:=
cloudProvider
.
(
cloudprovider
.
PVLabeler
)
if
!
ok
{
return
nil
,
errors
.
New
(
"OpenStack cloud provider does not implement PV labeling"
)
}
l
.
openStackPVLabeler
=
openStackPVLabeler
}
return
l
.
openStackPVLabeler
,
nil
}
func
(
l
*
persistentVolumeLabel
)
findCinderDiskLabels
(
volume
*
api
.
PersistentVolume
)
(
map
[
string
]
string
,
error
)
{
// Ignore any volumes that are being provisioned
if
volume
.
Spec
.
Cinder
.
VolumeID
==
vol
.
ProvisionedVolumeName
{
return
nil
,
nil
}
pvlabler
,
err
:=
l
.
getOpenStackPVLabeler
()
if
err
!=
nil
{
return
nil
,
err
}
if
pvlabler
==
nil
{
return
nil
,
fmt
.
Errorf
(
"unable to build OpenStack cloud provider for Cinder disk"
)
}
pv
:=
&
v1
.
PersistentVolume
{}
err
=
k8s_api_v1
.
Convert_core_PersistentVolume_To_v1_PersistentVolume
(
volume
,
pv
,
nil
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to convert PersistentVolume to core/v1: %q"
,
err
)
}
return
pvlabler
.
GetLabelsForVolume
(
context
.
TODO
(),
pv
)
}
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