Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node/Driver labeling mechanism #2

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (plugin *TestPlugin) CanSupport(spec *volume.Spec) bool {
return true
}

func (plugin *TestPlugin) IsMigratedToCSI() bool {
func (plugin *TestPlugin) IsMigratableToCSI() bool {
davidz627 marked this conversation as resolved.
Show resolved Hide resolved
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/volume/persistentvolume/framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ func (plugin *mockVolumePlugin) CanSupport(spec *vol.Spec) bool {
return true
}

func (plugin *mockVolumePlugin) IsMigratedToCSI() bool {
func (plugin *mockVolumePlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/awsebs/aws_ebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (plugin *awsElasticBlockStorePlugin) CanSupport(spec *volume.Spec) bool {
(spec.Volume != nil && spec.Volume.AWSElasticBlockStore != nil)
}

func (plugin *awsElasticBlockStorePlugin) IsMigratedToCSI() bool {
func (plugin *awsElasticBlockStorePlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/azure_dd/azure_dd.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (plugin *azureDataDiskPlugin) CanSupport(spec *volume.Spec) bool {
(spec.Volume != nil && spec.Volume.AzureDisk != nil)
}

func (plugin *azureDataDiskPlugin) IsMigratedToCSI() bool {
func (plugin *azureDataDiskPlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/azure_file/azure_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (plugin *azureFilePlugin) CanSupport(spec *volume.Spec) bool {
(spec.Volume != nil && spec.Volume.AzureFile != nil)
}

func (plugin *azureFilePlugin) IsMigratedToCSI() bool {
func (plugin *azureFilePlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/cephfs/cephfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ 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 {
func (plugin *cephfsPlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/cinder/cinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ 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 {
func (plugin *cinderPlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/configmap/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (plugin *configMapPlugin) CanSupport(spec *volume.Spec) bool {
return spec.Volume != nil && spec.Volume.ConfigMap != nil
}

func (plugin *configMapPlugin) IsMigratedToCSI() bool {
func (plugin *configMapPlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/csi/csi_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (p *csiPlugin) CanSupport(spec *volume.Spec) bool {
return spec.PersistentVolume != nil && spec.PersistentVolume.Spec.CSI != nil
}

func (p *csiPlugin) IsMigratedToCSI() bool {
func (p *csiPlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
1 change: 1 addition & 0 deletions pkg/volume/csi/nodeinfomanager/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ go_library(
"//staging/src/k8s.io/csi-api/pkg/apis/csi/v1alpha1:go_default_library",
"//vendor/github.com/container-storage-interface/spec/lib/go/csi/v0:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/kubernetes-csi/kubernetes-csi-migration-library/plugins:go_default_library",
],
)

Expand Down
36 changes: 30 additions & 6 deletions pkg/volume/csi/nodeinfomanager/nodeinfomanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import (
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util"

csiPlugins "github.com/kubernetes-csi/kubernetes-csi-migration-library/plugins"
)

const (
Expand All @@ -45,6 +47,12 @@ const (

var nodeKind = v1.SchemeGroupVersion.WithKind("Node")

var migratedDrivers = map[string](func() bool){
csiPlugins.GCEPDDriverName: func() bool {
return utilfeature.DefaultFeatureGate.Enabled(features.CSIMigration) && utilfeature.DefaultFeatureGate.Enabled(features.CSIMigrationGCE)
},
}

// nodeInfoManager contains necessary common dependencies to update node info on both
// the Node and CSINodeInfo objects.
type nodeInfoManager struct {
Expand Down Expand Up @@ -370,6 +378,15 @@ func (nim *nodeInfoManager) createNodeInfoObject(
return err // do not wrap error
}

isMigratable := false
if driverIsMigratableFunc, ok := migratedDrivers[driverName]; ok {
isMigratable = driverIsMigratableFunc()
glog.V(4).Infof("CSI Driver %v found in migrated driver list, and migration status is %v", driverName, isMigratable)

} else {
glog.V(4).Infof("CSI Driver %v not found in migrated driver map", driverName)
}

nodeInfo := &csiv1alpha1.CSINodeInfo{
ObjectMeta: metav1.ObjectMeta{
Name: string(nim.nodeName),
Expand All @@ -384,9 +401,10 @@ func (nim *nodeInfoManager) createNodeInfoObject(
},
CSIDrivers: []csiv1alpha1.CSIDriverInfo{
{
Driver: driverName,
NodeID: driverNodeID,
TopologyKeys: topologyKeys,
Driver: driverName,
NodeID: driverNodeID,
TopologyKeys: topologyKeys,
IsDriverMigratableOnNode: isMigratable,
},
},
}
Expand Down Expand Up @@ -429,11 +447,17 @@ func (nim *nodeInfoManager) updateNodeInfoObject(
}
}

isMigratable := false
if driverIsMigratableFunc, ok := migratedDrivers[driverName]; ok {
isMigratable = driverIsMigratableFunc()
davidz627 marked this conversation as resolved.
Show resolved Hide resolved
}

// Append new driver
driverInfo := csiv1alpha1.CSIDriverInfo{
Driver: driverName,
NodeID: driverNodeID,
TopologyKeys: topologyKeys.List(),
Driver: driverName,
NodeID: driverNodeID,
TopologyKeys: topologyKeys.List(),
IsDriverMigratableOnNode: isMigratable,
}
newDriverInfos = append(newDriverInfos, driverInfo)
nodeInfo.CSIDrivers = newDriverInfos
Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/downwardapi/downwardapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (plugin *downwardAPIPlugin) CanSupport(spec *volume.Spec) bool {
return spec.Volume != nil && spec.Volume.DownwardAPI != nil
}

func (plugin *downwardAPIPlugin) IsMigratedToCSI() bool {
func (plugin *downwardAPIPlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/emptydir/empty_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (plugin *emptyDirPlugin) CanSupport(spec *volume.Spec) bool {
return false
}

func (plugin *emptyDirPlugin) IsMigratedToCSI() bool {
func (plugin *emptyDirPlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/fc/fc.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ 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 {
func (plugin *fcPlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/flexvolume/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (plugin *flexVolumePlugin) CanSupport(spec *volume.Spec) bool {
return sourceDriver == plugin.driverName
}

func (plugin *flexVolumePlugin) IsMigratedToCSI() bool {
func (plugin *flexVolumePlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/flocker/flocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (p *flockerPlugin) CanSupport(spec *volume.Spec) bool {
(spec.Volume != nil && spec.Volume.Flocker != nil)
}

func (p *flockerPlugin) IsMigratedToCSI() bool {
func (p *flockerPlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/gcepd/gce_pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (plugin *gcePersistentDiskPlugin) CanSupport(spec *volume.Spec) bool {
(spec.Volume != nil && spec.Volume.GCEPersistentDisk != nil)
}

func (plugin *gcePersistentDiskPlugin) IsMigratedToCSI() bool {
func (plugin *gcePersistentDiskPlugin) IsMigratableToCSI() bool {
return utilfeature.DefaultFeatureGate.Enabled(features.CSIMigration) &&
utilfeature.DefaultFeatureGate.Enabled(features.CSIMigrationGCE)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/git_repo/git_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (plugin *gitRepoPlugin) CanSupport(spec *volume.Spec) bool {
return spec.Volume != nil && spec.Volume.GitRepo != nil
}

func (plugin *gitRepoPlugin) IsMigratedToCSI() bool {
func (plugin *gitRepoPlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/glusterfs/glusterfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (plugin *glusterfsPlugin) CanSupport(spec *volume.Spec) bool {
(spec.Volume != nil && spec.Volume.Glusterfs != nil)
}

func (plugin *glusterfsPlugin) IsMigratedToCSI() bool {
func (plugin *glusterfsPlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/host_path/host_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (plugin *hostPathPlugin) CanSupport(spec *volume.Spec) bool {
(spec.Volume != nil && spec.Volume.HostPath != nil)
}

func (plugin *hostPathPlugin) IsMigratedToCSI() bool {
func (plugin *hostPathPlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/iscsi/iscsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ 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 {
func (plugin *iscsiPlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (plugin *localVolumePlugin) CanSupport(spec *volume.Spec) bool {
return (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.Local != nil)
}

func (plugin *localVolumePlugin) IsMigratedToCSI() bool {
func (plugin *localVolumePlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/nfs/nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (plugin *nfsPlugin) CanSupport(spec *volume.Spec) bool {
(spec.Volume != nil && spec.Volume.NFS != nil)
}

func (plugin *nfsPlugin) IsMigratedToCSI() bool {
func (plugin *nfsPlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/photon_pd/photon_pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (plugin *photonPersistentDiskPlugin) CanSupport(spec *volume.Spec) bool {
(spec.Volume != nil && spec.Volume.PhotonPersistentDisk != nil)
}

func (plugin *photonPersistentDiskPlugin) IsMigratedToCSI() bool {
func (plugin *photonPersistentDiskPlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
35 changes: 31 additions & 4 deletions pkg/volume/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ type VolumePlugin interface {
// const.
CanSupport(spec *Spec) bool

// IsMigrated tests whether the plugin is migrated seamlessly to a CSI
// IsMigratable tests whether the plugin is migrated seamlessly to a CSI
// Driver
IsMigratedToCSI() bool
IsMigratableToCSI() bool

// RequiresRemount returns true if this plugin requires mount calls to be
// reexecuted. Atomically updating volumes, like Downward API, depend on
Expand Down Expand Up @@ -530,6 +530,9 @@ func (pm *VolumePluginMgr) initProbedPlugin(probedPlugin VolumePlugin) 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 plugin migratable because volume spec is nil")
}
Expand All @@ -545,13 +548,37 @@ func (pm *VolumePluginMgr) IsPluginMigratableBySpec(spec *Spec) (bool, error) {
}

if len(matches) == 0 {
return false, fmt.Errorf("no volume plugin matched")
// 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
return matches[0].IsMigratableToCSI(), nil
}

func (pm *VolumePluginMgr) IsPluginMigratableByName(name string) (bool, error) {
pm.mutex.Lock()
defer pm.mutex.Unlock()

// Once we can get rid of legacy names we can reduce this to a map lookup.
matchedPluginNames := []string{}
matches := []VolumePlugin{}
for k, v := range pm.plugins {
if v.GetPluginName() == name {
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].IsMigratableToCSI(), nil
}

// FindPluginBySpec looks for a plugin that can support a given volume
Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (plugin *testPlugins) CanSupport(spec *Spec) bool {
return true
}

func (plugin *testPlugins) IsMigratedToCSI() bool {
func (plugin *testPlugins) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/portworx/portworx.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (plugin *portworxVolumePlugin) CanSupport(spec *volume.Spec) bool {
(spec.Volume != nil && spec.Volume.PortworxVolume != nil)
}

func (plugin *portworxVolumePlugin) IsMigratedToCSI() bool {
func (plugin *portworxVolumePlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/projected/projected.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (plugin *projectedPlugin) CanSupport(spec *volume.Spec) bool {
return spec.Volume != nil && spec.Volume.Projected != nil
}

func (plugin *projectedPlugin) IsMigratedToCSI() bool {
func (plugin *projectedPlugin) IsMigratableToCSI() bool {
return false
}

Expand Down
Loading