Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 941b267

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request #50780 from vladimirvivien/scaleio-instanceid-label
Automatic merge from submit-queue ScaleIO - Specify SDC GUID value via node label **What this PR does / why we need it**: This is a ScaleIO plugin volume PR to do the following: - Reads node label `scaleio.sdcGuid` value for the SDC GUID - Uses value to look up the Scaleio SDC `instance ID` - If label not found, falls back to current way of doing instance id look up now This enhancement allows the ScaleIO plugin to work properly even if the drv_cfg binary is not installed on the kubelet node. **Special Notes** Associated issue - #51537 Closes #51537 ```release-note The ScaleIO volume plugin can now read the SDC GUID value as node label scaleio.sdcGuid; if binary drv_cfg is not installed, the plugin will still work properly; if node label not found, it defaults to drv_cfg if installed. ```
2 parents 629fea3 + 3148595 commit 941b267

5 files changed

Lines changed: 89 additions & 25 deletions

File tree

pkg/volume/scaleio/sio_client.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ type sioClient struct {
7474
spClient *sio.StoragePool
7575
provisionMode string
7676
sdcPath string
77+
sdcGuid string
7778
instanceID string
7879
inited bool
7980
diskRegex *regexp.Regexp
@@ -292,30 +293,45 @@ func (c *sioClient) DeleteVolume(id sioVolumeID) error {
292293
return nil
293294
}
294295

296+
// IID returns the scaleio instance id for node
295297
func (c *sioClient) IID() (string, error) {
296298
if err := c.init(); err != nil {
297299
return "", err
298300
}
299301

302+
// if instanceID not set, retrieve it
300303
if c.instanceID == "" {
301-
cmd := c.getSdcCmd()
302-
output, err := c.exec.Run(cmd, "--query_guid")
304+
guid, err := c.getGuid()
303305
if err != nil {
304-
glog.Error(log("drv_cfg --query_guid failed: %v", err))
305306
return "", err
306307
}
307-
guid := strings.TrimSpace(string(output))
308308
sdc, err := c.sysClient.FindSdc("SdcGuid", guid)
309309
if err != nil {
310-
glog.Error(log("failed to get sdc info %s", err))
310+
glog.Error(log("failed to retrieve sdc info %s", err))
311311
return "", err
312312
}
313313
c.instanceID = sdc.Sdc.ID
314-
glog.V(4).Info(log("got instanceID %s", c.instanceID))
314+
glog.V(4).Info(log("retrieved instanceID %s", c.instanceID))
315315
}
316316
return c.instanceID, nil
317317
}
318318

319+
// getGuid returns instance GUID, if not set using resource labels
320+
// it attemps to fallback to using drv_cfg binary
321+
func (c *sioClient) getGuid() (string, error) {
322+
if c.sdcGuid == "" {
323+
glog.V(4).Info(log("sdc guid label not set, falling back to using drv_cfg"))
324+
cmd := c.getSdcCmd()
325+
output, err := c.exec.Run(cmd, "--query_guid")
326+
if err != nil {
327+
glog.Error(log("drv_cfg --query_guid failed: %v", err))
328+
return "", err
329+
}
330+
c.sdcGuid = strings.TrimSpace(string(output))
331+
}
332+
return c.sdcGuid, nil
333+
}
334+
319335
// getSioDiskPaths traverse local disk devices to retrieve device path
320336
// The path is extracted from /dev/disk/by-id; each sio device path has format:
321337
// emc-vol-<mdmID-volID> e.g.:

pkg/volume/scaleio/sio_mgr.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func (m *sioMgr) getClient() (sioInterface, error) {
8181
client.spName = configs[confKey.storagePool]
8282
client.sdcPath = configs[confKey.sdcRootPath]
8383
client.provisionMode = configs[confKey.storageMode]
84+
client.sdcGuid = configs[confKey.sdcGuid]
8485

8586
m.client = client
8687

@@ -215,23 +216,12 @@ func (m *sioMgr) DeleteVolume(volName string) error {
215216
if err != nil {
216217
return err
217218
}
218-
iid, err := client.IID()
219-
if err != nil {
220-
glog.Error(log("failed to get instanceID: %v", err))
221-
return err
222-
}
223219

224220
vol, err := client.FindVolume(volName)
225221
if err != nil {
226222
return err
227223
}
228224

229-
// if still attached, stop
230-
if m.isSdcMappedToVol(iid, vol) {
231-
glog.Error(log("volume %s still attached, unable to delete", volName))
232-
return errors.New("volume still attached")
233-
}
234-
235225
if err := client.DeleteVolume(sioVolumeID(vol.ID)); err != nil {
236226
glog.Error(log("failed to delete volume %s: %v", volName, err))
237227
return err
@@ -242,10 +232,6 @@ func (m *sioMgr) DeleteVolume(volName string) error {
242232

243233
}
244234

245-
//*****************************************************************
246-
// Helpers
247-
//*****************************************************************
248-
249235
// isSdcMappedToVol returns true if the sdc is mapped to the volume
250236
func (m *sioMgr) isSdcMappedToVol(sdcID string, vol *siotypes.Volume) bool {
251237
if len(vol.MappedSdcInfo) == 0 {

pkg/volume/scaleio/sio_util.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ var (
4747
readOnly,
4848
username,
4949
password,
50-
namespace string
50+
namespace,
51+
sdcGuid string
5152
}{
5253
gateway: "gateway",
5354
sslEnabled: "sslEnabled",
@@ -64,9 +65,10 @@ var (
6465
username: "username",
6566
password: "password",
6667
namespace: "namespace",
68+
sdcGuid: "sdcGuid",
6769
}
68-
nsSep = "%"
69-
sdcRootPath = "/opt/emc/scaleio/sdc/bin"
70+
sdcGuidLabelName = "scaleio.sdcGuid"
71+
sdcRootPath = "/opt/emc/scaleio/sdc/bin"
7072

7173
secretNotFoundErr = errors.New("secret not found")
7274
configMapNotFoundErr = errors.New("configMap not found")
@@ -215,6 +217,33 @@ func attachSecret(plug *sioPlugin, namespace string, configData map[string]strin
215217
return nil
216218
}
217219

220+
// attachSdcGuid injects the sdc guid node label value into config
221+
func attachSdcGuid(plug *sioPlugin, conf map[string]string) error {
222+
guid, err := getSdcGuidLabel(plug)
223+
if err != nil {
224+
return err
225+
}
226+
conf[confKey.sdcGuid] = guid
227+
return nil
228+
}
229+
230+
// getSdcGuidLabel fetches the scaleio.sdcGuid node label
231+
// associated with the node executing this code.
232+
func getSdcGuidLabel(plug *sioPlugin) (string, error) {
233+
nodeLabels, err := plug.host.GetNodeLabels()
234+
if err != nil {
235+
return "", err
236+
}
237+
label, ok := nodeLabels[sdcGuidLabelName]
238+
if !ok {
239+
glog.V(4).Info(log("node label %s not found", sdcGuidLabelName))
240+
return "", nil
241+
}
242+
243+
glog.V(4).Info(log("found node label %s=%s", sdcGuidLabelName, label))
244+
return label, nil
245+
}
246+
218247
// getVolumeSourceFromSpec safely extracts ScaleIOVolumeSource from spec
219248
func getVolumeSourceFromSpec(spec *volume.Spec) (*api.ScaleIOVolumeSource, error) {
220249
if spec.Volume != nil && spec.Volume.ScaleIO != nil {

pkg/volume/scaleio/sio_volume.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,13 @@ func (v *sioVolume) setSioMgr() error {
386386
return err
387387
}
388388

389+
// merge in Sdc Guid label value
390+
if err := attachSdcGuid(v.plugin, configData); err != nil {
391+
glog.Error(log("failed to retrieve sdc guid: %v", err))
392+
return err
393+
}
389394
mgr, err := newSioMgr(configData, v.plugin.host.GetExec(v.plugin.GetPluginName()))
395+
390396
if err != nil {
391397
glog.Error(log("failed to reset sio manager: %v", err))
392398
return err
@@ -418,7 +424,14 @@ func (v *sioVolume) resetSioMgr() error {
418424
return err
419425
}
420426

427+
// merge in Sdc Guid label value
428+
if err := attachSdcGuid(v.plugin, configData); err != nil {
429+
glog.Error(log("failed to retrieve sdc guid: %v", err))
430+
return err
431+
}
432+
421433
mgr, err := newSioMgr(configData, v.plugin.host.GetExec(v.plugin.GetPluginName()))
434+
422435
if err != nil {
423436
glog.Error(log("failed to reset scaleio mgr: %v", err))
424437
return err
@@ -453,6 +466,7 @@ func (v *sioVolume) setSioMgrFromConfig() error {
453466
}
454467

455468
mgr, err := newSioMgr(data, v.plugin.host.GetExec(v.plugin.GetPluginName()))
469+
456470
if err != nil {
457471
glog.Error(log("failed while setting scaleio mgr from config: %v", err))
458472
return err
@@ -462,6 +476,8 @@ func (v *sioVolume) setSioMgrFromConfig() error {
462476
return nil
463477
}
464478

479+
// setSioMgrFromSpec sets the scaleio manager from a spec object.
480+
// The spec may be complete or incomplete depending on lifecycle phase.
465481
func (v *sioVolume) setSioMgrFromSpec() error {
466482
glog.V(4).Info(log("setting sio manager from spec"))
467483
if v.sioMgr == nil {
@@ -482,6 +498,7 @@ func (v *sioVolume) setSioMgrFromSpec() error {
482498
}
483499

484500
mgr, err := newSioMgr(configData, v.plugin.host.GetExec(v.plugin.GetPluginName()))
501+
485502
if err != nil {
486503
glog.Error(log("failed to reset sio manager: %v", err))
487504
return err

pkg/volume/scaleio/sio_volume_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,14 @@ func newPluginMgr(t *testing.T) (*volume.VolumePluginMgr, string) {
6060
"password": []byte("password"),
6161
},
6262
}
63+
6364
fakeClient := fakeclient.NewSimpleClientset(config)
64-
host := volumetest.NewFakeVolumeHost(tmpDir, fakeClient, nil)
65+
host := volumetest.NewFakeVolumeHostWithNodeLabels(
66+
tmpDir,
67+
fakeClient,
68+
nil,
69+
map[string]string{sdcGuidLabelName: "abc-123"},
70+
)
6571
plugMgr := &volume.VolumePluginMgr{}
6672
plugMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, host)
6773

@@ -195,6 +201,11 @@ func TestVolumeMounterUnmounter(t *testing.T) {
195201
t.Errorf("SetUp() - expecting multiple volume disabled by default")
196202
}
197203

204+
// did we read sdcGuid label
205+
if _, ok := sioVol.sioMgr.configData[confKey.sdcGuid]; !ok {
206+
t.Errorf("Expected to find node label scaleio.sdcGuid, but did not find it")
207+
}
208+
198209
// rebuild spec
199210
builtSpec, err := sioPlug.ConstructVolumeSpec(volume.NewSpecFromVolume(vol).Name(), path)
200211
if err != nil {
@@ -322,6 +333,11 @@ func TestVolumeProvisioner(t *testing.T) {
322333
t.Fatalf("Expected success, got: %v", err)
323334
}
324335

336+
// did we read sdcGuid label
337+
if _, ok := sioVol.sioMgr.configData[confKey.sdcGuid]; !ok {
338+
t.Errorf("Expected to find node label scaleio.sdcGuid, but did not find it")
339+
}
340+
325341
// isMultiMap applied
326342
if !sio.isMultiMap {
327343
t.Errorf("SetUp() expecting attached volume with multi-mapping")

0 commit comments

Comments
 (0)