Change:
import ( "errors" "fmt" <ins> "os" </ins> "path" "strconv" "strings"

Discussion:
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks! If the matter is security related, please disclose it privately via --What happened: i use the standalone-cinder-provisioner and the backend storage is iscsi,the pv and volume can dynamic created,but the device can not attached the k8s minion the standalone-cinder-provisioner pod yaml use the web and the pod running: kube-system standalone-cinder-provisioner--5x6x6 1/1 Running 7 5d5h [root kubectl get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc--3140-11e9-bde3- 1Gi RWO Delete Bound kube-system/keystone-sc-pvc standard 6d4h the pv infomation: [root kubectl get pv pvc--3140-11e9-bde3- -o yaml apiVersion: v1 kind: PersistentVolume metadata: annotations: cinderVolumeId: -0bc7-4e8a-879d- standaloneCinderProvisionerIdentity: creationTimestamp: "2019-02-15T16:38:33Z" finalizers: external- name: pvc--3140-11e9-bde3- resourceVersion: "" selfLink: /api/v1/persistentvolumes/pvc--3140-11e9-bde3- uid: -3140-11e9-bde3- spec: accessModes: ReadWriteOnce capacity: storage: 1Gi claimRef: apiVersion: v1 kind: PersistentVolumeClaim name: keystone-sc-pvc namespace: kube-system resourceVersion: "" uid: -3140-11e9-bde3- iscsi: initiatorName: iqn.2018- iqn: iqn.2099- iscsiInterface: default lun: 1 targetPortal: 19.19.19.

252:3260 persistentVolumeReclaimPolicy: Delete storageClassName: standard volumeMode: Filesystem status: phase: Bound [root standalone]# kubectl get po --all-namespaces -w NAMESPACE NAME READY STATUS RESTARTS AGE default iscsi-standalone 0/1 ContainerCreating 0 2s [root standalone]# kubectl describe pod iscsi-standalone Name: iscsi-standalone Namespace: default Priority: 0 PriorityClassName: <noneNode: 12.12.12.30/12.12.12.30 Start Time: Tue, 26 Feb 2019 17:15:19 +0800 Labels: <noneAnnotations: <noneStatus: Pending IP: Containers: iscsi: Container ID: Image: Image ID: Port: <noneHost Port: <noneState: Waiting Reason: ContainerCreating Ready: False Restart Count: 0 Environment: <noneMounts: from default-token-frzl8 (ro) /var/www/html from mypd (rw) Conditions: Type Status Initialized True Ready False ContainersReady False PodScheduled True Volumes: mypd: Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace) ClaimName: keystone-sc-pvc-storage13 ReadOnly: false default-token-frzl8: Type: Secret (a volume populated by a Secret) SecretName: default-token-frzl8 Optional: false QoS Class: BestEffort Node-Selectors: <noneTolerations: for 300s for 300s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 4m48s default-scheduler Successfully assigned default/iscsi-standalone to 12.12.12.30 Normal SuccessfulAttachVolume 4m48s attachdetach-controller AttachVolume.Attach succeeded for volume "pvc--39a5-11e9-b3a9-" Warning FailedMount 30s (x10 over 4m40s) kubelet, 12.12.12.30 MountVolume.WaitForAttach failed for volume "pvc--39a5-11e9-b3a9-" : open /sys/class/iscsihost: no such file or directory Warning FailedMount 29s (x2 over 2m45s) kubelet, 12.12.12.

30 Unable to mount volumes for pod "iscsi-standalone_default(-39a7-11e9-bb03-)": timeout expired waiting for volumes to attach or mount for pod "default"/"iscsi-standalone". list of unmounted volumes=[mypd]. list of unattached volumes=[mypd default-token-frzl8] What you expected to happen: the pod can running How to reproduce it (as minimally and precisely as possible): Anything else we need to know?: Environment:k8s v1.13 Kubernetes version (use ): Cloud provider or hardware configuration: OS (e.g: ): Kernel (e.g. ): Install tools: Others:
the k8s not connect the iscsi,so the /sys/class/iscsihost dir not exist,then attachdisk function : // Build a map of SCSI hosts for each target portal. We will need this to // issue the bus rescans. portalHostMap, err := b.deviceUtil.GetISCSIPortalHostMapForTarget(b.Iqn) if err != nil { return "", err } the GetISCSIPortalHostMapForTarget will return err then attach failed,why set the func to the login above?or the /sys/class/iscsihost dir when exist or how can i let the dir appear before run the GetISCSIPortalHostMapForTarget function? thanks
/sig storage
/assign bswartz
/assign
can you review this issue ?thanks
I see a bug here. If the iscsi modules haven't even been loaded yet, the /sys/class/iscsi_host directory won't exist. In this case it's better to return an empty map rather than an error.
yes, if the iscsi can not Initializationthe dir will not exist,maybe return empty map rather than an error or delete the func GetISCSIPortalHostMapForTarget i have commit one pr to resove the problem,can you review it?thanks