From 4ce2f296f5f0da2491a2c92153bd4ba041ec7b3e Mon Sep 17 00:00:00 2001 From: caiweidong Date: Fri, 31 May 2019 00:20:08 +0800 Subject: [PATCH] Simplify func ConstructVolumeSpec --- pkg/volume/csi/csi_plugin.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pkg/volume/csi/csi_plugin.go b/pkg/volume/csi/csi_plugin.go index 0e323f1d18d..19cd4772a90 100644 --- a/pkg/volume/csi/csi_plugin.go +++ b/pkg/volume/csi/csi_plugin.go @@ -482,20 +482,18 @@ func (p *csiPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*volume.S var spec *volume.Spec inlineEnabled := utilfeature.DefaultFeatureGate.Enabled(features.CSIInlineVolume) + // If inlineEnabled is true and mode is ephemeralDriverMode, + // use constructVolSourceSpec to construct volume source spec. + // If inlineEnabled is false or mode is persistentDriverMode, + // use constructPVSourceSpec to construct volume construct pv source spec. if inlineEnabled { - mode := driverMode(volData[volDataKey.driverMode]) - switch { - case mode == ephemeralDriverMode: + if driverMode(volData[volDataKey.driverMode]) == ephemeralDriverMode { spec = p.constructVolSourceSpec(volData[volDataKey.specVolID], volData[volDataKey.driverName]) + return spec, nil - case mode == persistentDriverMode: - fallthrough - default: - spec = p.constructPVSourceSpec(volData[volDataKey.specVolID], volData[volDataKey.driverName], volData[volDataKey.volHandle]) } - } else { - spec = p.constructPVSourceSpec(volData[volDataKey.specVolID], volData[volDataKey.driverName], volData[volDataKey.volHandle]) } + spec = p.constructPVSourceSpec(volData[volDataKey.specVolID], volData[volDataKey.driverName], volData[volDataKey.volHandle]) return spec, nil }