diff --git a/staging/src/k8s.io/csi-translation-lib/README.md b/staging/src/k8s.io/csi-translation-lib/README.md index 7b0208405f..b2a6942129 100644 --- a/staging/src/k8s.io/csi-translation-lib/README.md +++ b/staging/src/k8s.io/csi-translation-lib/README.md @@ -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 diff --git a/staging/src/k8s.io/csi-translation-lib/plugins/aws_ebs.go b/staging/src/k8s.io/csi-translation-lib/plugins/aws_ebs.go index 1933fe3367..eda70843fe 100644 --- a/staging/src/k8s.io/csi-translation-lib/plugins/aws_ebs.go +++ b/staging/src/k8s.io/csi-translation-lib/plugins/aws_ebs.go @@ -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 } diff --git a/staging/src/k8s.io/csi-translation-lib/plugins/gce_pd.go b/staging/src/k8s.io/csi-translation-lib/plugins/gce_pd.go index 3b1c938769..740e54f5fe 100644 --- a/staging/src/k8s.io/csi-translation-lib/plugins/gce_pd.go +++ b/staging/src/k8s.io/csi-translation-lib/plugins/gce_pd.go @@ -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 } diff --git a/staging/src/k8s.io/csi-translation-lib/translate.go b/staging/src/k8s.io/csi-translation-lib/translate.go index 91398d6bf3..754cab9e0e 100644 --- a/staging/src/k8s.io/csi-translation-lib/translate.go +++ b/staging/src/k8s.io/csi-translation-lib/translate.go @@ -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(), } )