Skip to content

Commit

Permalink
Rename sdc (#153)
Browse files Browse the repository at this point in the history
* added support for renaming SDC

* node.go updated

* node.go updated

* unit tests added

* unit tests updated

* node.go updated

* node.go updated

* node.go updated

* node.go updated

* UTs updated

* node.go updated

* UTs updated

* modified renameSdc unit-tests and hostName logic.

* added the  missing comment in values.yaml for renamesdc.

---------

Co-authored-by: VamsiSiddu-7 <[email protected]>
  • Loading branch information
khareRajshree and VamsiSiddu-7 authored Feb 1, 2023
1 parent 2f4c263 commit 499e2ec
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 14 deletions.
8 changes: 8 additions & 0 deletions helm/csi-vxflexos/templates/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ spec:
- name: X_CSI_HEALTH_MONITOR_ENABLED
value: "{{ .Values.node.healthMonitor.enabled }}"
{{- end }}
{{- if hasKey .Values.node "renameSDC" }}
- name: X_CSI_RENAME_SDC_ENABLED
value: "{{ .Values.node.renameSDC.enabled }}"
{{- if eq .Values.node.renameSDC.enabled true }}
- name: X_CSI_RENAME_SDC_PREFIX
value: "{{ .Values.node.renameSDC.prefix }}"
{{- end }}
{{- end }}
volumeMounts:
- name: driver-path
mountPath: {{ .Values.kubeletConfigDir }}/plugins/vxflexos.emc.dell.com
Expand Down
16 changes: 16 additions & 0 deletions helm/csi-vxflexos/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,22 @@ node:
# - key: "isilon.podmon.storage.dell.com"
# operator: "Exists"
# effect: "NoSchedule"

# "renameSDC" defines the rename operation for SDC
# Default value: None
renameSDC:
# enabled: Enable/Disable rename of SDC
# Allowed values:
# true: enable renaming
# false: disable renaming
# Default value: "false"
enabled: false
# "prefix" defines a string for the new name of the SDC.
# "prefix" + "worker_node_hostname" should not exceed 31 chars.
# Default value: none
# Examples: "rhel-sdc", "sdc-test"
prefix: "sdc-test"

# monitoring pod details
# These options control the running of the monitoring container
# This container gather diagnostic information in case of failure
Expand Down
16 changes: 12 additions & 4 deletions service/envvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@ const (
// violation of the CSI spec
EnvAutoProbe = "X_CSI_VXFLEXOS_AUTOPROBE"

// EnvAllowRWOMultiPodAccess is the name of the environment variable that specifes
// EnvAllowRWOMultiPodAccess is the name of the environment variable that specifies
// within a single node multiple pods should be able to access the same Filesystem volume with access mode ReadWriteOnce.
// Multi-node access is still not allowed for ReadWriteOnce Filesystem volumes.
// Enabling this option techincally violates the CSI 1.3 spec in the NodePublishVolume stating the required error returns.
EnvAllowRWOMultiPodAccess = "X_CSI_ALLOW_RWO_MULTI_POD_ACCESS"

//EnvIsHealthMonitorEnabled is the name of the environment variable that specifes if
//the driver should be reporting on volume condition. To do so, requires the alpha feature gate CSIVolumeHealth set
//to true in the cluster. If the feature gate is on, this should be enabled. Otherwise, this should be set to false.
// EnvIsHealthMonitorEnabled is the name of the environment variable that specifies if
// the driver should be reporting on volume condition. To do so, requires the alpha feature gate CSIVolumeHealth set
// to true in the cluster. If the feature gate is on, this should be enabled. Otherwise, this should be set to false.
EnvIsHealthMonitorEnabled = "X_CSI_HEALTH_MONITOR_ENABLED"

// EnvIsSDCRenameEnabled is the name of the environment variable that specifies if the renaming for SDC is to be
// carried out or not. This is only used by the Node Service.
EnvIsSDCRenameEnabled = "X_CSI_RENAME_SDC_ENABLED"

// EnvSDCPrefix is the name of the environment variable used to set the prefix for SDC name. This is only used by
// the Node Service.
EnvSDCPrefix = "X_CSI_RENAME_SDC_PREFIX"
)
37 changes: 37 additions & 0 deletions service/features/get_sdc_instances.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"versionInfo": null,
"perfProfile": "Default",
"sdcApproved": true,
"osType": "Linux",
"mdmConnectionState": "Connected",
"memoryAllocationFailure": null,
"socketAllocationFailure": null,
"softwareVersionInfo": null,
"sdcGuid": "9E56672F-2F4B-4A42-BFF4-88B6846FBFDA",
"installedSoftwareVersionInfo": "R2_6.0.0",
"kernelVersion": "3.10.0",
"kernelBuildNumber": null,
"sdcIp": "127.1.1.11",
"sdcApprovedIps": null,
"systemId": "14dbbf5617523654",
"name": "__NAME__",
"id": "__ID__",
"links": [
{
"rel": "self",
"href": "/api/instances/Sdc::d0f055a700000000"
},
{
"rel": "/api/Sdc/relationship/Statistics",
"href": "/api/instances/Sdc::d0f055a700000000/relationships/Statistics"
},
{
"rel": "/api/Sdc/relationship/Volume",
"href": "/api/instances/Sdc::d0f055a700000000/relationships/Volume"
},
{
"rel": "/api/parent/relationship/systemId",
"href": "/api/instances/System::14dbbf5617523654"
}
]
}
30 changes: 30 additions & 0 deletions service/features/service.feature
Original file line number Diff line number Diff line change
Expand Up @@ -942,3 +942,33 @@ Feature: VxFlex OS CSI interface
When I call Probe
And I call setQoSParameters with systemID "15dbbf5617523655" sdcID "d0f055a700000000" bandwidthLimit "10240" iopsLimit "10" volumeName "k8s-a031818af5" csiVolID "15dbbf5617523655-456ca4fc00000009" nodeID "9E56672F-2F4B-4A42-BFF4-88B6846FBFDA"
Then the error contains "error setting QoS parameters"

Scenario: Call probe for renaming SDC with prefix
Given a VxFlexOS service
And I set renameSDC with renameEnabled "true" prefix "t"
And I call Probe
When I call Node Probe
Then the error contains "none"

Scenario: Call probe for renaming SDC without prefix
Given a VxFlexOS service
And I set renameSDC with renameEnabled "true" prefix ""
And I call Probe
When I call Node Probe
Then the error contains "none"

Scenario: Call probe for renaming SDC, renameSdc error
Given a VxFlexOS service
And I induce error "SetSdcNameError"
And I set renameSDC with renameEnabled "true" prefix "t"
And I call Probe
When I call Node Probe
Then the error contains "Failed to rename SDC"

Scenario: Call probe for renaming SDC, sdc error
Given a VxFlexOS service
And I induce error "GetSdcInstancesError"
And I set renameSDC with renameEnabled "true" prefix "t"
And I call Probe
When I call Node Probe
Then the error contains "induced error"
62 changes: 62 additions & 0 deletions service/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,18 @@ func (s *service) nodeProbe(ctx context.Context) error {
}
}

// rename SDC
/*
case1: if IsSdcRenameEnabled=true and prefix given then set the prefix+worker_node_name for sdc name.
case2: if IsSdcRenameEnabled=true and prefix not given then set worker_node_name for sdc name.
*/
if s.opts.IsSdcRenameEnabled {
err = s.renameSDC(s.opts)
if err != nil {
return err
}
}

// get all the system names and IDs.
s.getSystemName(ctx, connectedSystemID)

Expand All @@ -408,6 +420,56 @@ func (s *service) nodeProbe(ctx context.Context) error {
return nil
}

func (s *service) renameSDC(opts Opts) error {
// fetch hostname
hostName, ok := os.LookupEnv("HOSTNAME")
if !ok {
return status.Errorf(codes.FailedPrecondition, "%s not set", "HOSTNAME")
}

// fetch SDC details
for _, systemID := range connectedSystemID {
sdc, err := s.systems[systemID].FindSdc("SdcGUID", opts.SdcGUID)
if err != nil {
return status.Errorf(codes.FailedPrecondition, "%s", err)
}
sdcID := sdc.Sdc.ID

var newName string
if len(opts.SdcPrefix) > 0 {
// case1: if IsSdcRenameEnabled=true and prefix given then set the prefix+worker_node_name for sdc name.
newName = opts.SdcPrefix + "-" + hostName
} else {
// case2: if IsSdcRenameEnabled=true and prefix not given then set worker_node_name for sdc name.
newName = hostName
}
if sdc.Sdc.Name == newName {
Log.Infof("SDC is already named: %s.", newName)
} else {
Log.Infof("Assigning name: %s to SDC with GUID %s on system %s", newName, s.opts.SdcGUID,
systemID)
err = s.adminClients[systemID].RenameSdc(sdcID, newName)
if err != nil {
return status.Errorf(codes.FailedPrecondition, "Failed to rename SDC: %s", err)
}
err = s.getSDCName(opts.SdcGUID, systemID)
if err != nil {
return err
}
}
}
return nil
}

func (s *service) getSDCName(sdcGUID string, systemID string) error {
sdc, err := s.systems[systemID].FindSdc("SdcGUID", sdcGUID)
if err != nil {
return status.Errorf(codes.FailedPrecondition, "%s", err)
}
Log.Infof("SDC name set to: %s.", sdc.Sdc.Name)
return nil
}

func kmodLoaded(opts Opts) bool {
// opts.Lsmod is introduced solely for unit testing.
var out []byte
Expand Down
26 changes: 20 additions & 6 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ var KubeConfig string
// K8sClientset is the client to query k8s
var K8sClientset kubernetes.Interface

//Log controlls the logger
//give default value, will be overwritten by configmap
// Log controlls the logger
// give default value, will be overwritten by configmap
var Log = logrus.New()

// ArrayConnectionData contains data required to connect to array
Expand Down Expand Up @@ -133,6 +133,8 @@ type Opts struct {
EnableListVolumesSnapshots bool // when listing volumes, include snapshots and volumes
AllowRWOMultiPodAccess bool // allow multiple pods to access a RWO volume on the same node
IsHealthMonitorEnabled bool // allow driver to make use of the alpha feature gate, CSIVolumeHealth
IsSdcRenameEnabled bool // allow driver to enable renaming SDC
SdcPrefix string // prefix to be set for SDC name
}

type service struct {
Expand Down Expand Up @@ -265,7 +267,7 @@ func (s *service) logCsiNodeTopologyKeys() error {

}

//New returns a handle to service
// New returns a handle to service
func New() Service {
return &service{
storagePoolIDToName: map[string]string{},
Expand Down Expand Up @@ -321,6 +323,8 @@ func (s *service) BeforeServe(
"mode": s.mode,
"allowRWOMultiPodAccess": s.opts.AllowRWOMultiPodAccess,
"IsHealthMonitorEnabled": s.opts.IsHealthMonitorEnabled,
"IsSdcRenameEnabled": s.opts.IsSdcRenameEnabled,
"sdcPrefix": s.opts.SdcPrefix,
}

Log.WithFields(fields).Infof("configured %s", Name)
Expand Down Expand Up @@ -374,6 +378,16 @@ func (s *service) BeforeServe(
} else {
opts.IsHealthMonitorEnabled = false
}
if renameSDC, ok := csictx.LookupEnv(ctx, EnvIsSDCRenameEnabled); ok {
if renameSDC == "true" {
opts.IsSdcRenameEnabled = true
}
} else {
opts.IsSdcRenameEnabled = false
}
if sdcPrefix, ok := csictx.LookupEnv(ctx, EnvSDCPrefix); ok {
opts.SdcPrefix = sdcPrefix
}
if s.privDir == "" {
s.privDir = defaultPrivDir
}
Expand Down Expand Up @@ -726,9 +740,9 @@ func (s *service) getSystemIDFromCsiVolumeID(csiVolID string) string {
return ""
}

//this function updates volumePrefixToSystems, a map of volume ID prefixes -> system IDs
//this is needed for checkSystemVolumes, a function that verifies that any legacy vol ID
//is found on the default system, only
// this function updates volumePrefixToSystems, a map of volume ID prefixes -> system IDs
// this is needed for checkSystemVolumes, a function that verifies that any legacy vol ID
// is found on the default system, only
func (s *service) UpdateVolumePrefixToSystemsMap(systemID string) error {
//get one vol from system
vols, _, err := s.listVolumes(systemID, 0, 1, true, false, "", "")
Expand Down
13 changes: 12 additions & 1 deletion service/step_defs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (f *feature) CreateCSINode() (*storage.CSINode, error) {
{
Name: "csi-vxflexos.dellemc.com",
NodeID: "9E56672F-2F4B-4A42-BFF4-88B6846FBFDA",
TopologyKeys: []string{"csi-vxflexos.dellemc.com/000000000001"},
TopologyKeys: []string{"csi-vxflexos.dellemc.com/14dbbf5617523654"},
},
},
},
Expand Down Expand Up @@ -990,6 +990,8 @@ func (f *feature) iInduceError(errtype string) error {
stepHandlersErrors.NoVolIDError = true
case "NoVolIDSDCError":
stepHandlersErrors.NoVolIDSDCError = true
case "SetSdcNameError":
stepHandlersErrors.SetSdcNameError = true
case "NoVolError":
stepHandlersErrors.NoVolError = true
case "SetVolumeSizeError":
Expand Down Expand Up @@ -3369,6 +3371,14 @@ func (f *feature) aReplicationCapabilitiesStructureIsReturned(arg1 string) error
return nil
}

func (f *feature) iSetRenameSdcEnabledWithPrefix(renameEnabled string, prefix string) error {
if renameEnabled == "true" {
f.service.opts.IsSdcRenameEnabled = true
}
f.service.opts.SdcPrefix = prefix
return nil
}

func FeatureContext(s *godog.ScenarioContext) {
f := &feature{}
s.Step(`^a VxFlexOS service$`, f.aVxFlexOSService)
Expand Down Expand Up @@ -3528,6 +3538,7 @@ func FeatureContext(s *godog.ScenarioContext) {
s.Step(`^I use config "([^"]*)"$`, f.iUseConfig)
s.Step(`^I call GetReplicationCapabilities$`, f.iCallGetReplicationCapabilities)
s.Step(`^a "([^"]*)" replication capabilities structure is returned$`, f.aReplicationCapabilitiesStructureIsReturned)
s.Step(`^I set renameSDC with renameEnabled "([^"]*)" prefix "([^"]*)"$`, f.iSetRenameSdcEnabledWithPrefix)

s.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) {
if f.server != nil {
Expand Down
Loading

0 comments on commit 499e2ec

Please sign in to comment.