From d8c9dc5bb5a0f227f7253626bdc313fdaf48f85c Mon Sep 17 00:00:00 2001 From: David Zhu Date: Thu, 17 Jan 2019 11:56:14 -0800 Subject: [PATCH] Add IsMigratableToCSI to volume plugin interface --- .../attachdetach/testing/testvolumespec.go | 4 ++ .../volume/persistentvolume/framework_test.go | 4 ++ pkg/volume/awsebs/aws_ebs.go | 5 +++ pkg/volume/azure_dd/azure_dd.go | 4 ++ pkg/volume/azure_file/azure_file.go | 4 ++ pkg/volume/cephfs/cephfs.go | 4 ++ pkg/volume/cinder/cinder.go | 4 ++ pkg/volume/configmap/configmap.go | 4 ++ pkg/volume/csi/csi_plugin.go | 4 ++ pkg/volume/downwardapi/downwardapi.go | 4 ++ pkg/volume/emptydir/empty_dir.go | 4 ++ pkg/volume/fc/fc.go | 4 ++ pkg/volume/flexvolume/plugin.go | 4 ++ pkg/volume/flocker/flocker.go | 4 ++ pkg/volume/gcepd/gce_pd.go | 5 +++ pkg/volume/git_repo/git_repo.go | 4 ++ pkg/volume/glusterfs/glusterfs.go | 4 ++ pkg/volume/host_path/host_path.go | 4 ++ pkg/volume/iscsi/iscsi.go | 4 ++ pkg/volume/local/local.go | 4 ++ pkg/volume/nfs/nfs.go | 4 ++ pkg/volume/noop_expandable_plugin.go | 4 ++ pkg/volume/photon_pd/photon_pd.go | 4 ++ pkg/volume/plugins.go | 35 +++++++++++++++++ pkg/volume/plugins_test.go | 4 ++ pkg/volume/portworx/portworx.go | 4 ++ pkg/volume/projected/projected.go | 4 ++ pkg/volume/quobyte/quobyte.go | 4 ++ pkg/volume/rbd/rbd.go | 4 ++ pkg/volume/scaleio/sio_plugin.go | 4 ++ pkg/volume/secret/secret.go | 4 ++ pkg/volume/storageos/storageos.go | 4 ++ pkg/volume/testing/testing.go | 12 ++++++ pkg/volume/util/operationexecutor/BUILD | 1 + .../operationexecutor/operation_generator.go | 38 +++++++++++++++++-- pkg/volume/vsphere_volume/vsphere_volume.go | 4 ++ 36 files changed, 212 insertions(+), 4 deletions(-) diff --git a/pkg/controller/volume/attachdetach/testing/testvolumespec.go b/pkg/controller/volume/attachdetach/testing/testvolumespec.go index a243e724b2..2c9d5eec32 100644 --- a/pkg/controller/volume/attachdetach/testing/testvolumespec.go +++ b/pkg/controller/volume/attachdetach/testing/testvolumespec.go @@ -253,6 +253,10 @@ func (plugin *TestPlugin) CanSupport(spec *volume.Spec) bool { return true } +func (plugin *TestPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *TestPlugin) RequiresRemount() bool { return false } diff --git a/pkg/controller/volume/persistentvolume/framework_test.go b/pkg/controller/volume/persistentvolume/framework_test.go index 7552a2cb44..f2f4ea2624 100644 --- a/pkg/controller/volume/persistentvolume/framework_test.go +++ b/pkg/controller/volume/persistentvolume/framework_test.go @@ -1258,6 +1258,10 @@ func (plugin *mockVolumePlugin) CanSupport(spec *vol.Spec) bool { return true } +func (plugin *mockVolumePlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *mockVolumePlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/awsebs/aws_ebs.go b/pkg/volume/awsebs/aws_ebs.go index ac934eccaf..f10f89e690 100644 --- a/pkg/volume/awsebs/aws_ebs.go +++ b/pkg/volume/awsebs/aws_ebs.go @@ -86,6 +86,11 @@ func (plugin *awsElasticBlockStorePlugin) CanSupport(spec *volume.Spec) bool { (spec.Volume != nil && spec.Volume.AWSElasticBlockStore != nil) } +func (plugin *awsElasticBlockStorePlugin) IsMigratedToCSI() bool { + return utilfeature.DefaultFeatureGate.Enabled(features.CSIMigration) && + utilfeature.DefaultFeatureGate.Enabled(features.CSIMigrationAWS) +} + func (plugin *awsElasticBlockStorePlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/azure_dd/azure_dd.go b/pkg/volume/azure_dd/azure_dd.go index 4a082addf1..0a2dfa1842 100644 --- a/pkg/volume/azure_dd/azure_dd.go +++ b/pkg/volume/azure_dd/azure_dd.go @@ -121,6 +121,10 @@ func (plugin *azureDataDiskPlugin) CanSupport(spec *volume.Spec) bool { (spec.Volume != nil && spec.Volume.AzureDisk != nil) } +func (plugin *azureDataDiskPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *azureDataDiskPlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/azure_file/azure_file.go b/pkg/volume/azure_file/azure_file.go index e0234ce780..7b88e2c601 100644 --- a/pkg/volume/azure_file/azure_file.go +++ b/pkg/volume/azure_file/azure_file.go @@ -80,6 +80,10 @@ func (plugin *azureFilePlugin) CanSupport(spec *volume.Spec) bool { (spec.Volume != nil && spec.Volume.AzureFile != nil) } +func (plugin *azureFilePlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *azureFilePlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/cephfs/cephfs.go b/pkg/volume/cephfs/cephfs.go index 748fe11a47..c18c82e93c 100644 --- a/pkg/volume/cephfs/cephfs.go +++ b/pkg/volume/cephfs/cephfs.go @@ -71,6 +71,10 @@ func (plugin *cephfsPlugin) CanSupport(spec *volume.Spec) bool { return (spec.Volume != nil && spec.Volume.CephFS != nil) || (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.CephFS != nil) } +func (plugin *cephfsPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *cephfsPlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/cinder/cinder.go b/pkg/volume/cinder/cinder.go index 1cc38d4f7a..7376e49b7b 100644 --- a/pkg/volume/cinder/cinder.go +++ b/pkg/volume/cinder/cinder.go @@ -108,6 +108,10 @@ func (plugin *cinderPlugin) CanSupport(spec *volume.Spec) bool { return (spec.Volume != nil && spec.Volume.Cinder != nil) || (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.Cinder != nil) } +func (plugin *cinderPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *cinderPlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/configmap/configmap.go b/pkg/volume/configmap/configmap.go index bd35aa5055..5711b95924 100644 --- a/pkg/volume/configmap/configmap.go +++ b/pkg/volume/configmap/configmap.go @@ -77,6 +77,10 @@ func (plugin *configMapPlugin) CanSupport(spec *volume.Spec) bool { return spec.Volume != nil && spec.Volume.ConfigMap != nil } +func (plugin *configMapPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *configMapPlugin) RequiresRemount() bool { return true } diff --git a/pkg/volume/csi/csi_plugin.go b/pkg/volume/csi/csi_plugin.go index 35f20dc691..295aed85c8 100644 --- a/pkg/volume/csi/csi_plugin.go +++ b/pkg/volume/csi/csi_plugin.go @@ -279,6 +279,10 @@ func (p *csiPlugin) CanSupport(spec *volume.Spec) bool { return spec.PersistentVolume != nil && spec.PersistentVolume.Spec.CSI != nil } +func (p *csiPlugin) IsMigratedToCSI() bool { + return false +} + func (p *csiPlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/downwardapi/downwardapi.go b/pkg/volume/downwardapi/downwardapi.go index 9616f33573..d6239fdf04 100644 --- a/pkg/volume/downwardapi/downwardapi.go +++ b/pkg/volume/downwardapi/downwardapi.go @@ -81,6 +81,10 @@ func (plugin *downwardAPIPlugin) CanSupport(spec *volume.Spec) bool { return spec.Volume != nil && spec.Volume.DownwardAPI != nil } +func (plugin *downwardAPIPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *downwardAPIPlugin) RequiresRemount() bool { return true } diff --git a/pkg/volume/emptydir/empty_dir.go b/pkg/volume/emptydir/empty_dir.go index 0dd6c6508a..a050b932cb 100644 --- a/pkg/volume/emptydir/empty_dir.go +++ b/pkg/volume/emptydir/empty_dir.go @@ -89,6 +89,10 @@ func (plugin *emptyDirPlugin) CanSupport(spec *volume.Spec) bool { return false } +func (plugin *emptyDirPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *emptyDirPlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/fc/fc.go b/pkg/volume/fc/fc.go index af25701107..9b06c36933 100644 --- a/pkg/volume/fc/fc.go +++ b/pkg/volume/fc/fc.go @@ -85,6 +85,10 @@ func (plugin *fcPlugin) CanSupport(spec *volume.Spec) bool { return (spec.Volume != nil && spec.Volume.FC != nil) || (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.FC != nil) } +func (plugin *fcPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *fcPlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/flexvolume/plugin.go b/pkg/volume/flexvolume/plugin.go index 2e2a9f7e53..4721d78bd3 100644 --- a/pkg/volume/flexvolume/plugin.go +++ b/pkg/volume/flexvolume/plugin.go @@ -149,6 +149,10 @@ func (plugin *flexVolumePlugin) CanSupport(spec *volume.Spec) bool { return sourceDriver == plugin.driverName } +func (plugin *flexVolumePlugin) IsMigratedToCSI() bool { + return false +} + // RequiresRemount is part of the volume.VolumePlugin interface. func (plugin *flexVolumePlugin) RequiresRemount() bool { return false diff --git a/pkg/volume/flocker/flocker.go b/pkg/volume/flocker/flocker.go index 8651ba4908..0218c4a043 100644 --- a/pkg/volume/flocker/flocker.go +++ b/pkg/volume/flocker/flocker.go @@ -108,6 +108,10 @@ func (p *flockerPlugin) CanSupport(spec *volume.Spec) bool { (spec.Volume != nil && spec.Volume.Flocker != nil) } +func (p *flockerPlugin) IsMigratedToCSI() bool { + return false +} + func (p *flockerPlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/gcepd/gce_pd.go b/pkg/volume/gcepd/gce_pd.go index 74cf74ce62..d4dd825c7d 100644 --- a/pkg/volume/gcepd/gce_pd.go +++ b/pkg/volume/gcepd/gce_pd.go @@ -98,6 +98,11 @@ func (plugin *gcePersistentDiskPlugin) CanSupport(spec *volume.Spec) bool { (spec.Volume != nil && spec.Volume.GCEPersistentDisk != nil) } +func (plugin *gcePersistentDiskPlugin) IsMigratedToCSI() bool { + return utilfeature.DefaultFeatureGate.Enabled(features.CSIMigration) && + utilfeature.DefaultFeatureGate.Enabled(features.CSIMigrationGCE) +} + func (plugin *gcePersistentDiskPlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/git_repo/git_repo.go b/pkg/volume/git_repo/git_repo.go index 332f33e5ab..bba6c719e0 100644 --- a/pkg/volume/git_repo/git_repo.go +++ b/pkg/volume/git_repo/git_repo.go @@ -78,6 +78,10 @@ func (plugin *gitRepoPlugin) CanSupport(spec *volume.Spec) bool { return spec.Volume != nil && spec.Volume.GitRepo != nil } +func (plugin *gitRepoPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *gitRepoPlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/glusterfs/glusterfs.go b/pkg/volume/glusterfs/glusterfs.go index 408898c114..9f370b763e 100644 --- a/pkg/volume/glusterfs/glusterfs.go +++ b/pkg/volume/glusterfs/glusterfs.go @@ -114,6 +114,10 @@ func (plugin *glusterfsPlugin) CanSupport(spec *volume.Spec) bool { (spec.Volume != nil && spec.Volume.Glusterfs != nil) } +func (plugin *glusterfsPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *glusterfsPlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/host_path/host_path.go b/pkg/volume/host_path/host_path.go index 9090e4a34d..dfbe01bf27 100644 --- a/pkg/volume/host_path/host_path.go +++ b/pkg/volume/host_path/host_path.go @@ -83,6 +83,10 @@ func (plugin *hostPathPlugin) CanSupport(spec *volume.Spec) bool { (spec.Volume != nil && spec.Volume.HostPath != nil) } +func (plugin *hostPathPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *hostPathPlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/iscsi/iscsi.go b/pkg/volume/iscsi/iscsi.go index 54ad75febf..3e6b30c6ba 100644 --- a/pkg/volume/iscsi/iscsi.go +++ b/pkg/volume/iscsi/iscsi.go @@ -76,6 +76,10 @@ func (plugin *iscsiPlugin) CanSupport(spec *volume.Spec) bool { return (spec.Volume != nil && spec.Volume.ISCSI != nil) || (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.ISCSI != nil) } +func (plugin *iscsiPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *iscsiPlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/local/local.go b/pkg/volume/local/local.go index 4524931342..69d916a9a9 100644 --- a/pkg/volume/local/local.go +++ b/pkg/volume/local/local.go @@ -82,6 +82,10 @@ func (plugin *localVolumePlugin) CanSupport(spec *volume.Spec) bool { return (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.Local != nil) } +func (plugin *localVolumePlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *localVolumePlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/nfs/nfs.go b/pkg/volume/nfs/nfs.go index 92384b3db0..75a95f0896 100644 --- a/pkg/volume/nfs/nfs.go +++ b/pkg/volume/nfs/nfs.go @@ -84,6 +84,10 @@ func (plugin *nfsPlugin) CanSupport(spec *volume.Spec) bool { (spec.Volume != nil && spec.Volume.NFS != nil) } +func (plugin *nfsPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *nfsPlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/noop_expandable_plugin.go b/pkg/volume/noop_expandable_plugin.go index 3d3d5e1dfd..e4052d3138 100644 --- a/pkg/volume/noop_expandable_plugin.go +++ b/pkg/volume/noop_expandable_plugin.go @@ -48,6 +48,10 @@ func (n *noopExpandableVolumePluginInstance) CanSupport(spec *Spec) bool { return true } +func (n *noopExpandableVolumePluginInstance) IsMigratedToCSI() bool { + return false +} + func (n *noopExpandableVolumePluginInstance) RequiresRemount() bool { return false } diff --git a/pkg/volume/photon_pd/photon_pd.go b/pkg/volume/photon_pd/photon_pd.go index 03cbd9b0ec..e0903a2e66 100644 --- a/pkg/volume/photon_pd/photon_pd.go +++ b/pkg/volume/photon_pd/photon_pd.go @@ -74,6 +74,10 @@ func (plugin *photonPersistentDiskPlugin) CanSupport(spec *volume.Spec) bool { (spec.Volume != nil && spec.Volume.PhotonPersistentDisk != nil) } +func (plugin *photonPersistentDiskPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *photonPersistentDiskPlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/plugins.go b/pkg/volume/plugins.go index a0cb571646..b80149718e 100644 --- a/pkg/volume/plugins.go +++ b/pkg/volume/plugins.go @@ -118,6 +118,10 @@ type VolumePlugin interface { // const. CanSupport(spec *Spec) bool + // IsMigratedToCSI tests whether a CSIDriver implements this plugin's + // functionality + IsMigratedToCSI() bool + // RequiresRemount returns true if this plugin requires mount calls to be // reexecuted. Atomically updating volumes, like Downward API, depend on // this to update the contents of the volume. @@ -601,6 +605,37 @@ func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) { return matches[0], nil } +// IsPluginMigratableBySpec looks for a plugin that can support a given volume +// specification and whether that plugin is Migratable. If no plugins can +// support or more than one plugin can support it, return error. +func (pm *VolumePluginMgr) IsPluginMigratableBySpec(spec *Spec) (bool, error) { + pm.mutex.Lock() + defer pm.mutex.Unlock() + + if spec == nil { + return false, fmt.Errorf("could not find if plugin is migratable because volume spec is nil") + } + + matchedPluginNames := []string{} + matches := []VolumePlugin{} + for k, v := range pm.plugins { + if v.CanSupport(spec) { + matchedPluginNames = append(matchedPluginNames, k) + matches = append(matches, v) + } + } + + if len(matches) == 0 { + // Not a known plugin (flex) in which case it is not migratable + return false, nil + } + if len(matches) > 1 { + return false, fmt.Errorf("multiple volume plugins matched: %s", strings.Join(matchedPluginNames, ",")) + } + + return matches[0].IsMigratedToCSI(), nil +} + // FindPluginByName fetches a plugin by name or by legacy name. If no plugin // is found, returns error. func (pm *VolumePluginMgr) FindPluginByName(name string) (VolumePlugin, error) { diff --git a/pkg/volume/plugins_test.go b/pkg/volume/plugins_test.go index 167a47e6fa..dd0a7397d8 100644 --- a/pkg/volume/plugins_test.go +++ b/pkg/volume/plugins_test.go @@ -75,6 +75,10 @@ func (plugin *testPlugins) CanSupport(spec *Spec) bool { return true } +func (plugin *testPlugins) IsMigratedToCSI() bool { + return false +} + func (plugin *testPlugins) RequiresRemount() bool { return false } diff --git a/pkg/volume/portworx/portworx.go b/pkg/volume/portworx/portworx.go index e2cb898298..6083f69416 100644 --- a/pkg/volume/portworx/portworx.go +++ b/pkg/volume/portworx/portworx.go @@ -95,6 +95,10 @@ func (plugin *portworxVolumePlugin) CanSupport(spec *volume.Spec) bool { (spec.Volume != nil && spec.Volume.PortworxVolume != nil) } +func (plugin *portworxVolumePlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *portworxVolumePlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/projected/projected.go b/pkg/volume/projected/projected.go index 06ea997292..6b18ca3175 100644 --- a/pkg/volume/projected/projected.go +++ b/pkg/volume/projected/projected.go @@ -96,6 +96,10 @@ func (plugin *projectedPlugin) CanSupport(spec *volume.Spec) bool { return spec.Volume != nil && spec.Volume.Projected != nil } +func (plugin *projectedPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *projectedPlugin) RequiresRemount() bool { return true } diff --git a/pkg/volume/quobyte/quobyte.go b/pkg/volume/quobyte/quobyte.go index c9d9e773fa..a0c85c5b77 100644 --- a/pkg/volume/quobyte/quobyte.go +++ b/pkg/volume/quobyte/quobyte.go @@ -110,6 +110,10 @@ func (plugin *quobytePlugin) CanSupport(spec *volume.Spec) bool { return false } +func (plugin *quobytePlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *quobytePlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/rbd/rbd.go b/pkg/volume/rbd/rbd.go index 454b96045c..0d3c932166 100644 --- a/pkg/volume/rbd/rbd.go +++ b/pkg/volume/rbd/rbd.go @@ -107,6 +107,10 @@ func (plugin *rbdPlugin) CanSupport(spec *volume.Spec) bool { return (spec.Volume != nil && spec.Volume.RBD != nil) || (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.RBD != nil) } +func (plugin *rbdPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *rbdPlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/scaleio/sio_plugin.go b/pkg/volume/scaleio/sio_plugin.go index eda8556f7a..775d9315b7 100644 --- a/pkg/volume/scaleio/sio_plugin.go +++ b/pkg/volume/scaleio/sio_plugin.go @@ -72,6 +72,10 @@ func (p *sioPlugin) CanSupport(spec *volume.Spec) bool { (spec.Volume != nil && spec.Volume.ScaleIO != nil) } +func (p *sioPlugin) IsMigratedToCSI() bool { + return false +} + func (p *sioPlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/secret/secret.go b/pkg/volume/secret/secret.go index 14485181f9..3714d0d3ab 100644 --- a/pkg/volume/secret/secret.go +++ b/pkg/volume/secret/secret.go @@ -80,6 +80,10 @@ func (plugin *secretPlugin) CanSupport(spec *volume.Spec) bool { return spec.Volume != nil && spec.Volume.Secret != nil } +func (plugin *secretPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *secretPlugin) RequiresRemount() bool { return true } diff --git a/pkg/volume/storageos/storageos.go b/pkg/volume/storageos/storageos.go index 9cb56b353a..745aefb41e 100644 --- a/pkg/volume/storageos/storageos.go +++ b/pkg/volume/storageos/storageos.go @@ -91,6 +91,10 @@ func (plugin *storageosPlugin) CanSupport(spec *volume.Spec) bool { (spec.Volume != nil && spec.Volume.StorageOS != nil) } +func (plugin *storageosPlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *storageosPlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/testing/testing.go b/pkg/volume/testing/testing.go index 2791d9bd91..26acb12811 100644 --- a/pkg/volume/testing/testing.go +++ b/pkg/volume/testing/testing.go @@ -313,6 +313,10 @@ func (plugin *FakeVolumePlugin) CanSupport(spec *Spec) bool { return true } +func (plugin *FakeVolumePlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *FakeVolumePlugin) RequiresRemount() bool { return false } @@ -526,6 +530,10 @@ func (f *FakeBasicVolumePlugin) CanSupport(spec *Spec) bool { return strings.HasPrefix(spec.Name(), f.GetPluginName()) } +func (plugin *FakeBasicVolumePlugin) IsMigratedToCSI() bool { + return false +} + func (f *FakeBasicVolumePlugin) ConstructVolumeSpec(ame, mountPath string) (*Spec, error) { return f.Plugin.ConstructVolumeSpec(ame, mountPath) } @@ -611,6 +619,10 @@ func (plugin *FakeFileVolumePlugin) CanSupport(spec *Spec) bool { return true } +func (plugin *FakeFileVolumePlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *FakeFileVolumePlugin) RequiresRemount() bool { return false } diff --git a/pkg/volume/util/operationexecutor/BUILD b/pkg/volume/util/operationexecutor/BUILD index 3b2cd65d5d..a4a97f9db8 100644 --- a/pkg/volume/util/operationexecutor/BUILD +++ b/pkg/volume/util/operationexecutor/BUILD @@ -30,6 +30,7 @@ go_library( "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", "//staging/src/k8s.io/client-go/kubernetes:go_default_library", "//staging/src/k8s.io/client-go/tools/record:go_default_library", + "//staging/src/k8s.io/csi-translation-lib:go_default_library", "//vendor/k8s.io/klog:go_default_library", ], ) diff --git a/pkg/volume/util/operationexecutor/operation_generator.go b/pkg/volume/util/operationexecutor/operation_generator.go index a185a5f33f..9288f63519 100644 --- a/pkg/volume/util/operationexecutor/operation_generator.go +++ b/pkg/volume/util/operationexecutor/operation_generator.go @@ -29,6 +29,7 @@ import ( utilfeature "k8s.io/apiserver/pkg/util/feature" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/record" + csilib "k8s.io/csi-translation-lib" "k8s.io/klog" expandcache "k8s.io/kubernetes/pkg/controller/volume/expand/cache" "k8s.io/kubernetes/pkg/features" @@ -75,11 +76,11 @@ func NewOperationGenerator(kubeClient clientset.Interface, blkUtil volumepathhandler.BlockVolumePathHandler) OperationGenerator { return &operationGenerator{ - kubeClient: kubeClient, - volumePluginMgr: volumePluginMgr, - recorder: recorder, + kubeClient: kubeClient, + volumePluginMgr: volumePluginMgr, + recorder: recorder, checkNodeCapabilitiesBeforeMount: checkNodeCapabilitiesBeforeMount, - blkUtil: blkUtil, + blkUtil: blkUtil, } } @@ -1437,3 +1438,32 @@ func isDeviceOpened(deviceToDetach AttachedVolume, mounter mount.Interface) (boo } return deviceOpened, nil } + +// TODO(dyzz): need to also add logic to check CSINodeInfo for Kubelet migration status +func useCSIPlugin(vpm *volume.VolumePluginMgr, spec *volume.Spec) bool { + if csilib.IsPVMigratable(spec.PersistentVolume) || csilib.IsInlineMigratable(spec.Volume) { + migratable, err := vpm.IsPluginMigratableBySpec(spec) + if err == nil && migratable { + return true + } + } + return false +} + +func translateSpec(spec *volume.Spec) (*volume.Spec, error) { + if spec.PersistentVolume != nil { + // TranslateInTreePVToCSI will create a new PV + csiPV, err := csilib.TranslateInTreePVToCSI(spec.PersistentVolume) + if err != nil { + return nil, fmt.Errorf("failed to translate in tree pv to CSI: %v", err) + } + return &volume.Spec{ + PersistentVolume: csiPV, + ReadOnly: spec.ReadOnly, + }, nil + } else if spec.Volume != nil { + return &volume.Spec{}, fmt.Errorf("translation is not supported for in-line volumes yet") + } else { + return &volume.Spec{}, fmt.Errorf("not a valid volume spec") + } +} diff --git a/pkg/volume/vsphere_volume/vsphere_volume.go b/pkg/volume/vsphere_volume/vsphere_volume.go index 7097005ef9..62fbe2e3af 100644 --- a/pkg/volume/vsphere_volume/vsphere_volume.go +++ b/pkg/volume/vsphere_volume/vsphere_volume.go @@ -81,6 +81,10 @@ func (plugin *vsphereVolumePlugin) CanSupport(spec *volume.Spec) bool { (spec.Volume != nil && spec.Volume.VsphereVolume != nil) } +func (plugin *vsphereVolumePlugin) IsMigratedToCSI() bool { + return false +} + func (plugin *vsphereVolumePlugin) RequiresRemount() bool { return false }