Skip to content

Commit

Permalink
Merge pull request kubernetes-csi#213 from Danil-Grigorev/node-annota…
Browse files Browse the repository at this point in the history
…tion-removal

Removed dependency on node annotation in favor of CSINode resource
  • Loading branch information
k8s-ci-robot authored Feb 3, 2020
2 parents 57193d7 + 8847215 commit ce4d513
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 186 deletions.
3 changes: 1 addition & 2 deletions cmd/csi-attacher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,11 @@ func main() {
}
if supportsAttach {
pvLister := factory.Core().V1().PersistentVolumes().Lister()
nodeLister := factory.Core().V1().Nodes().Lister()
vaLister := factory.Storage().V1beta1().VolumeAttachments().Lister()
csiNodeLister := factory.Storage().V1beta1().CSINodes().Lister()
volAttacher := attacher.NewAttacher(csiConn)
CSIVolumeLister := attacher.NewVolumeLister(csiConn)
handler = controller.NewCSIHandler(clientset, csiAttacher, volAttacher, CSIVolumeLister, pvLister, nodeLister, csiNodeLister, vaLister, timeout, supportsReadOnly, csitrans.New())
handler = controller.NewCSIHandler(clientset, csiAttacher, volAttacher, CSIVolumeLister, pvLister, csiNodeLister, vaLister, timeout, supportsReadOnly, csitrans.New())
klog.V(2).Infof("CSI driver supports ControllerPublishUnpublish, using real CSI handler")
} else {
handler = controller.NewTrivialHandler(clientset)
Expand Down
5 changes: 1 addition & 4 deletions deploy/kubernetes/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ metadata:
namespace: default

---
# Attacher must be able to work with PVs, nodes and VolumeAttachments
# Attacher must be able to work with PVs, CSINodes and VolumeAttachments
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
Expand All @@ -25,9 +25,6 @@ rules:
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["get", "list", "watch", "update", "patch"]
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list", "watch"]
- apiGroups: ["storage.k8s.io"]
resources: ["csinodes"]
verbs: ["get", "list", "watch"]
Expand Down
22 changes: 7 additions & 15 deletions pkg/controller/csi_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ type csiHandler struct {
attacher attacher.Attacher
CSIVolumeLister VolumeLister
pvLister corelisters.PersistentVolumeLister
nodeLister corelisters.NodeLister
csiNodeLister storagelisters.CSINodeLister
vaLister storagelisters.VolumeAttachmentLister
vaQueue, pvQueue workqueue.RateLimitingInterface
Expand All @@ -82,7 +81,6 @@ func NewCSIHandler(
attacher attacher.Attacher,
CSIVolumeLister VolumeLister,
pvLister corelisters.PersistentVolumeLister,
nodeLister corelisters.NodeLister,
csiNodeLister storagelisters.CSINodeLister,
vaLister storagelisters.VolumeAttachmentLister,
timeout *time.Duration,
Expand All @@ -95,7 +93,6 @@ func NewCSIHandler(
attacher: attacher,
CSIVolumeLister: CSIVolumeLister,
pvLister: pvLister,
nodeLister: nodeLister,
csiNodeLister: csiNodeLister,
vaLister: vaLister,
timeout: *timeout,
Expand Down Expand Up @@ -682,7 +679,7 @@ func (h *csiHandler) getCredentialsFromPV(csiSource *v1.CSIPersistentVolumeSourc
return credentials, nil
}

// getNodeID finds node ID from Node API object. If caller wants, it can find
// getNodeID finds node ID from CSINode API object. If caller wants, it can find
// node ID stored in VolumeAttachment annotation.
func (h *csiHandler) getNodeID(driver string, nodeName string, va *storage.VolumeAttachment) (string, error) {
// Try to find CSINode first.
Expand All @@ -692,19 +689,14 @@ func (h *csiHandler) getNodeID(driver string, nodeName string, va *storage.Volum
klog.V(4).Infof("Found NodeID %s in CSINode %s", nodeID, nodeName)
return nodeID, nil
}
klog.V(4).Infof("CSINode %s does not contain driver %s", nodeName, driver)
// CSINode exists, but does not have the requested driver.
// Fall through to Node annotation.
} else {
// Can't get CSINode, fall through to Node annotation.
klog.V(4).Infof("Can't get CSINode %s: %s", nodeName, err)
errMessage := fmt.Sprintf("CSINode %s does not contain driver %s", nodeName, driver)
klog.V(4).Info(errMessage)
return "", errors.New(errMessage)
}

// Check Node annotation.
node, err := h.nodeLister.Get(nodeName)
if err == nil {
return GetNodeIDFromNode(driver, node)
}
// Can't get CSINode, check Volume Attachment.
klog.V(4).Infof("Can't get CSINode %s: %s", nodeName, err)

// Check VolumeAttachment annotation as the last resort if caller wants so (i.e. has provided one).
if va == nil {
Expand All @@ -714,7 +706,7 @@ func (h *csiHandler) getNodeID(driver string, nodeName string, va *storage.Volum
return nodeID, nil
}

// return nodeLister.Get error
// return csiNodeLister.Get error
return "", err
}

Expand Down
Loading

0 comments on commit ce4d513

Please sign in to comment.