Skip to content

Commit

Permalink
WIP Unit tests for migration
Browse files Browse the repository at this point in the history
  • Loading branch information
davidz627 committed Sep 12, 2019
1 parent 61b9e46 commit 7bbb6b2
Show file tree
Hide file tree
Showing 5 changed files with 315 additions and 135 deletions.
2 changes: 1 addition & 1 deletion cmd/csi-provisioner/csi-provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func main() {

// Create the provisioner: it implements the Provisioner interface expected by
// the controller
csiProvisioner := ctrl.NewCSIProvisioner(clientset, *operationTimeout, identity, *volumeNamePrefix, *volumeNameUUIDLength, grpcClient, snapClient, provisionerName, pluginCapabilities, controllerCapabilities, supportsMigrationFromInTreePluginName, *strictTopology)
csiProvisioner := ctrl.NewCSIProvisioner(clientset, *operationTimeout, identity, *volumeNamePrefix, *volumeNameUUIDLength, grpcClient, snapClient, provisionerName, pluginCapabilities, controllerCapabilities, supportsMigrationFromInTreePluginName, *strictTopology, &csitranslationlib.CSITranslationLibrary{})
provisionController = controller.NewProvisionController(
clientset,
provisionerName,
Expand Down
14 changes: 8 additions & 6 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
csitranslationlib "k8s.io/csi-translation-lib"
"k8s.io/klog"

"google.golang.org/grpc"
Expand Down Expand Up @@ -180,6 +179,7 @@ type csiProvisioner struct {
controllerCapabilities connection.ControllerCapabilitySet
supportsMigrationFromInTreePluginName string
strictTopology bool
csiTranslationLibrary CSITranslationLibraryInterface
}

var _ controller.Provisioner = &csiProvisioner{}
Expand Down Expand Up @@ -237,7 +237,8 @@ func NewCSIProvisioner(client kubernetes.Interface,
pluginCapabilities connection.PluginCapabilitySet,
controllerCapabilities connection.ControllerCapabilitySet,
supportsMigrationFromInTreePluginName string,
strictTopology bool) controller.Provisioner {
strictTopology bool,
csiTranslationLibrary CSITranslationLibraryInterface) controller.Provisioner {

csiClient := csi.NewControllerClient(grpcClient)
provisioner := &csiProvisioner{
Expand All @@ -254,6 +255,7 @@ func NewCSIProvisioner(client kubernetes.Interface,
controllerCapabilities: controllerCapabilities,
supportsMigrationFromInTreePluginName: supportsMigrationFromInTreePluginName,
strictTopology: strictTopology,
csiTranslationLibrary: csiTranslationLibrary,
}
return provisioner
}
Expand Down Expand Up @@ -377,7 +379,7 @@ func (p *csiProvisioner) ProvisionExt(options controller.ProvisionOptions) (*v1.
// so that external provisioner can correctly pick up the PVC pointing to an in-tree plugin
if options.StorageClass.Provisioner == p.supportsMigrationFromInTreePluginName {
klog.V(2).Infof("translating storage class for in-tree plugin %s to CSI", options.StorageClass.Provisioner)
storageClass, err := csitranslationlib.TranslateInTreeStorageClassToCSI(p.supportsMigrationFromInTreePluginName, options.StorageClass)
storageClass, err := p.csiTranslationLibrary.TranslateInTreeStorageClassToCSI(p.supportsMigrationFromInTreePluginName, options.StorageClass)
if err != nil {
return nil, controller.ProvisioningFinished, fmt.Errorf("failed to translate storage class: %v", err)
}
Expand Down Expand Up @@ -620,7 +622,7 @@ func (p *csiProvisioner) ProvisionExt(options controller.ProvisionOptions) (*v1.
klog.V(2).Infof("successfully created PV %v for PVC %v and csi volume name %v", pv.Name, options.PVC.Name, pv.Spec.CSI.VolumeHandle)

if migratedVolume {
pv, err = csitranslationlib.TranslateCSIPVToInTree(pv)
pv, err = p.csiTranslationLibrary.TranslateCSIPVToInTree(pv)
if err != nil {
klog.Warningf("failed to translate CSI PV to in-tree due to: %v. Deleting provisioned PV", err)
deleteErr := p.Delete(pv)
Expand Down Expand Up @@ -808,12 +810,12 @@ func (p *csiProvisioner) Delete(volume *v1.PersistentVolume) error {
}

var err error
if csitranslationlib.IsPVMigratable(volume) {
if p.csiTranslationLibrary.IsPVMigratable(volume) {
// we end up here only if CSI migration is enabled in-tree (both overall
// and for the specific plugin that is migratable) causing in-tree PV
// controller to yield deletion of PVs with in-tree source to external provisioner
// based on AnnDynamicallyProvisioned annotation.
volume, err = csitranslationlib.TranslateInTreePVToCSI(volume)
volume, err = p.csiTranslationLibrary.TranslateInTreePVToCSI(volume)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 7bbb6b2

Please sign in to comment.