Skip to content

Commit

Permalink
Merge pull request kubernetes-csi#308 from chrishenzie/single-node-ac…
Browse files Browse the repository at this point in the history
…cess-modes

Map PV access modes to CSI access modes based on driver capability
  • Loading branch information
k8s-ci-robot authored Aug 5, 2021
2 parents 5840385 + bbc9af1 commit 6718e0b
Show file tree
Hide file tree
Showing 10 changed files with 280 additions and 140 deletions.
55 changes: 31 additions & 24 deletions cmd/csi-attacher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,36 +191,50 @@ func main() {
klog.Error(err.Error())
os.Exit(1)
}

var (
supportsAttach bool
supportsReadOnly bool
supportsListVolumesPublishedNodes bool
supportsSingleNodeMultiWriter bool
)
if !supportsService {
handler = controller.NewTrivialHandler(clientset)
klog.V(2).Infof("CSI driver does not support Plugin Controller Service, using trivial handler")
} else {
// Find out if the driver supports attach/detach.
supportsAttach, supportsReadOnly, err := supportsControllerPublish(ctx, csiConn)
supportsAttach, supportsReadOnly, supportsListVolumesPublishedNodes, supportsSingleNodeMultiWriter, err = supportsControllerCapabilities(ctx, csiConn)
if err != nil {
klog.Error(err.Error())
os.Exit(1)
}

if supportsAttach {
pvLister := factory.Core().V1().PersistentVolumes().Lister()
vaLister := factory.Storage().V1().VolumeAttachments().Lister()
csiNodeLister := factory.Storage().V1().CSINodes().Lister()
volAttacher := attacher.NewAttacher(csiConn)
CSIVolumeLister := attacher.NewVolumeLister(csiConn)
handler = controller.NewCSIHandler(clientset, csiAttacher, volAttacher, CSIVolumeLister, pvLister, csiNodeLister, vaLister, timeout, supportsReadOnly, csitrans.New())
handler = controller.NewCSIHandler(
clientset,
csiAttacher,
volAttacher,
CSIVolumeLister,
pvLister,
csiNodeLister,
vaLister,
timeout,
supportsReadOnly,
supportsSingleNodeMultiWriter,
csitrans.New(),
)
klog.V(2).Infof("CSI driver supports ControllerPublishUnpublish, using real CSI handler")
} else {
handler = controller.NewTrivialHandler(clientset)
klog.V(2).Infof("CSI driver does not support ControllerPublishUnpublish, using trivial handler")
}
}

slvpn, err := supportsListVolumesPublishedNodes(ctx, csiConn)
if err != nil {
klog.Errorf("Failed to check if driver supports ListVolumesPublishedNodes, assuming it does not: %v", err)
}

if slvpn {
if supportsListVolumesPublishedNodes {
klog.V(2).Infof("CSI driver supports list volumes published nodes. Using capability to reconcile volume attachment objects with actual backend state")
}

Expand All @@ -232,7 +246,7 @@ func main() {
factory.Core().V1().PersistentVolumes(),
workqueue.NewItemExponentialFailureRateLimiter(*retryIntervalStart, *retryIntervalMax),
workqueue.NewItemExponentialFailureRateLimiter(*retryIntervalStart, *retryIntervalMax),
slvpn,
supportsListVolumesPublishedNodes,
*reconcileSync,
)

Expand Down Expand Up @@ -281,24 +295,17 @@ func buildConfig(kubeconfig string) (*rest.Config, error) {
return rest.InClusterConfig()
}

func supportsControllerPublish(ctx context.Context, csiConn *grpc.ClientConn) (supportsControllerPublish bool, supportsPublishReadOnly bool, err error) {
caps, err := rpc.GetControllerCapabilities(ctx, csiConn)
if err != nil {
return false, false, err
}

supportsControllerPublish = caps[csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME]
supportsPublishReadOnly = caps[csi.ControllerServiceCapability_RPC_PUBLISH_READONLY]
return supportsControllerPublish, supportsPublishReadOnly, nil
}

func supportsListVolumesPublishedNodes(ctx context.Context, csiConn *grpc.ClientConn) (bool, error) {
func supportsControllerCapabilities(ctx context.Context, csiConn *grpc.ClientConn) (bool, bool, bool, bool, error) {
caps, err := rpc.GetControllerCapabilities(ctx, csiConn)
if err != nil {
return false, fmt.Errorf("failed to get controller capabilities: %v", err)
return false, false, false, false, err
}

return caps[csi.ControllerServiceCapability_RPC_LIST_VOLUMES] && caps[csi.ControllerServiceCapability_RPC_LIST_VOLUMES_PUBLISHED_NODES], nil
supportsControllerPublish := caps[csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME]
supportsPublishReadOnly := caps[csi.ControllerServiceCapability_RPC_PUBLISH_READONLY]
supportsListVolumesPublishedNodes := caps[csi.ControllerServiceCapability_RPC_LIST_VOLUMES] && caps[csi.ControllerServiceCapability_RPC_LIST_VOLUMES_PUBLISHED_NODES]
supportsSingleNodeMultiWriter := caps[csi.ControllerServiceCapability_RPC_SINGLE_NODE_MULTI_WRITER]
return supportsControllerPublish, supportsPublishReadOnly, supportsListVolumesPublishedNodes, supportsSingleNodeMultiWriter, nil
}

func supportsPluginControllerService(ctx context.Context, csiConn *grpc.ClientConn) (bool, error) {
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/golang/protobuf v1.5.2
github.com/google/gofuzz v1.2.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/kubernetes-csi/csi-lib-utils v0.9.1
github.com/kubernetes-csi/csi-lib-utils v0.10.0
github.com/kubernetes-csi/csi-test/v4 v4.0.2
golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84 // indirect
golang.org/x/term v0.0.0-20210317153231-de623e64d2a6 // indirect
Expand All @@ -19,7 +19,6 @@ require (
k8s.io/api v0.22.0
k8s.io/apimachinery v0.22.0
k8s.io/client-go v0.22.0
k8s.io/component-base v0.22.0 // indirect
k8s.io/csi-translation-lib v0.22.0
k8s.io/klog/v2 v2.9.0
)
Loading

0 comments on commit 6718e0b

Please sign in to comment.