Merge pull request #72950 from ddebroy/csimig2

Enhance CSI translation plugin files with accessors and proper names
pull/564/head
Kubernetes Prow Robot 2019-01-18 01:22:07 -08:00 committed by GitHub
commit 44419ce38e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 16 deletions

View File

@ -4,8 +4,8 @@ This repository contains functions to be consumed by various Kubernetes and
out-of-tree CSI components like external provisioner to facilitate migration of
code from Kubernetes In-tree plugin code to CSI plugin repositories.
Consumers can make use of this repository can make use of functions like
`TranslateToCSI` and `TranslateToInTree` functions to translate PV sources.
Consumers of this repository can make use of functions like `TranslateToCSI` and
`TranslateToInTree` functions to translate PV sources.
## Community, discussion, contribution, and support

View File

@ -30,12 +30,19 @@ const (
AWSEBSInTreePluginName = "kubernetes.io/aws-ebs"
)
// AWSEBS handles translation of PV spec from In-tree EBS to CSI EBS and vice versa
type AWSEBS struct{}
var _ InTreePlugin = &awsElasticBlockStoreCSITranslator{}
// awsElasticBlockStoreTranslator handles translation of PV spec from In-tree EBS to CSI EBS and vice versa
type awsElasticBlockStoreCSITranslator struct{}
// NewAWSElasticBlockStoreCSITranslator returns a new instance of awsElasticBlockStoreTranslator
func NewAWSElasticBlockStoreCSITranslator() InTreePlugin {
return &awsElasticBlockStoreCSITranslator{}
}
// TranslateInTreePVToCSI takes a PV with AWSElasticBlockStore set from in-tree
// and converts the AWSElasticBlockStore source to a CSIPersistentVolumeSource
func (t *AWSEBS) TranslateInTreePVToCSI(pv *v1.PersistentVolume) (*v1.PersistentVolume, error) {
func (t *awsElasticBlockStoreCSITranslator) TranslateInTreePVToCSI(pv *v1.PersistentVolume) (*v1.PersistentVolume, error) {
if pv == nil || pv.Spec.AWSElasticBlockStore == nil {
return nil, fmt.Errorf("pv is nil or AWS EBS not defined on pv")
}
@ -59,7 +66,7 @@ func (t *AWSEBS) TranslateInTreePVToCSI(pv *v1.PersistentVolume) (*v1.Persistent
// TranslateCSIPVToInTree takes a PV with CSIPersistentVolumeSource set and
// translates the EBS CSI source to a AWSElasticBlockStore source.
func (t *AWSEBS) TranslateCSIPVToInTree(pv *v1.PersistentVolume) (*v1.PersistentVolume, error) {
func (t *awsElasticBlockStoreCSITranslator) TranslateCSIPVToInTree(pv *v1.PersistentVolume) (*v1.PersistentVolume, error) {
if pv == nil || pv.Spec.CSI == nil {
return nil, fmt.Errorf("pv is nil or CSI source not defined on pv")
}
@ -88,11 +95,11 @@ func (t *AWSEBS) TranslateCSIPVToInTree(pv *v1.PersistentVolume) (*v1.Persistent
// CanSupport tests whether the plugin supports a given volume
// specification from the API. The spec pointer should be considered
// const.
func (t *AWSEBS) CanSupport(pv *v1.PersistentVolume) bool {
func (t *awsElasticBlockStoreCSITranslator) CanSupport(pv *v1.PersistentVolume) bool {
return pv != nil && pv.Spec.AWSElasticBlockStore != nil
}
// GetInTreePluginName returns the name of the intree plugin driver
func (t *AWSEBS) GetInTreePluginName() string {
func (t *awsElasticBlockStoreCSITranslator) GetInTreePluginName() string {
return AWSEBSInTreePluginName
}

View File

@ -47,12 +47,20 @@ const (
UnspecifiedValue = "UNSPECIFIED"
)
// GCEPD handles translation of PV spec from In-tree GCE PD to CSI GCE PD and vice versa
type GCEPD struct{}
var _ InTreePlugin = &gcePersistentDiskCSITranslator{}
// gcePersistentDiskCSITranslator handles translation of PV spec from In-tree
// GCE PD to CSI GCE PD and vice versa
type gcePersistentDiskCSITranslator struct{}
// NewGCEPersistentDiskCSITranslator returns a new instance of gcePersistentDiskTranslator
func NewGCEPersistentDiskCSITranslator() InTreePlugin {
return &gcePersistentDiskCSITranslator{}
}
// TranslateInTreePVToCSI takes a PV with GCEPersistentDisk set from in-tree
// and converts the GCEPersistentDisk source to a CSIPersistentVolumeSource
func (g *GCEPD) TranslateInTreePVToCSI(pv *v1.PersistentVolume) (*v1.PersistentVolume, error) {
func (g *gcePersistentDiskCSITranslator) TranslateInTreePVToCSI(pv *v1.PersistentVolume) (*v1.PersistentVolume, error) {
var volID string
if pv == nil || pv.Spec.GCEPersistentDisk == nil {
@ -95,7 +103,7 @@ func (g *GCEPD) TranslateInTreePVToCSI(pv *v1.PersistentVolume) (*v1.PersistentV
// TranslateCSIPVToInTree takes a PV with CSIPersistentVolumeSource set and
// translates the GCE PD CSI source to a GCEPersistentDisk source.
func (g *GCEPD) TranslateCSIPVToInTree(pv *v1.PersistentVolume) (*v1.PersistentVolume, error) {
func (g *gcePersistentDiskCSITranslator) TranslateCSIPVToInTree(pv *v1.PersistentVolume) (*v1.PersistentVolume, error) {
if pv == nil || pv.Spec.CSI == nil {
return nil, fmt.Errorf("pv is nil or CSI source not defined on pv")
}
@ -130,12 +138,12 @@ func (g *GCEPD) TranslateCSIPVToInTree(pv *v1.PersistentVolume) (*v1.PersistentV
// CanSupport tests whether the plugin supports a given volume
// specification from the API. The spec pointer should be considered
// const.
func (g *GCEPD) CanSupport(pv *v1.PersistentVolume) bool {
func (g *gcePersistentDiskCSITranslator) CanSupport(pv *v1.PersistentVolume) bool {
return pv != nil && pv.Spec.GCEPersistentDisk != nil
}
// GetInTreePluginName returns the name of the intree plugin driver
func (g *GCEPD) GetInTreePluginName() string {
func (g *gcePersistentDiskCSITranslator) GetInTreePluginName() string {
return GCEPDInTreePluginName
}

View File

@ -25,8 +25,8 @@ import (
var (
inTreePlugins = map[string]plugins.InTreePlugin{
plugins.GCEPDDriverName: &plugins.GCEPD{},
plugins.AWSEBSDriverName: &plugins.AWSEBS{},
plugins.GCEPDDriverName: plugins.NewGCEPersistentDiskCSITranslator(),
plugins.AWSEBSDriverName: plugins.NewAWSElasticBlockStoreCSITranslator(),
plugins.CinderDriverName: plugins.NewOpenStackCinderCSITranslator(),
}
)