This repository has been archived by the owner on Dec 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge flexadapter related commits from drivers
- Loading branch information
Showing
14 changed files
with
1,175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/kubernetes-csi/drivers/pkg/flexadapter" | ||
) | ||
|
||
var ( | ||
endpoint string | ||
driverName string | ||
driverPath string | ||
nodeID string | ||
) | ||
|
||
func init() { | ||
flag.Set("logtostderr", "true") | ||
} | ||
|
||
func main() { | ||
|
||
flag.CommandLine.Parse([]string{}) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "flexadapter", | ||
Short: "Flex volume adapter for CSI", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
handle() | ||
}, | ||
} | ||
|
||
cmd.Flags().AddGoFlagSet(flag.CommandLine) | ||
|
||
cmd.PersistentFlags().StringVar(&nodeID, "nodeid", "", "node id") | ||
cmd.MarkPersistentFlagRequired("nodeid") | ||
|
||
cmd.PersistentFlags().StringVar(&endpoint, "endpoint", "", "CSI endpoint") | ||
cmd.MarkPersistentFlagRequired("endpoint") | ||
|
||
cmd.PersistentFlags().StringVar(&driverPath, "driverpath", "", "path to flexvolume driver path") | ||
cmd.MarkPersistentFlagRequired("driverpath") | ||
|
||
cmd.PersistentFlags().StringVar(&driverName, "drivername", "", "name of the driver") | ||
cmd.MarkPersistentFlagRequired("drivername") | ||
|
||
if err := cmd.Execute(); err != nil { | ||
fmt.Fprintf(os.Stderr, "%s", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
os.Exit(0) | ||
} | ||
|
||
func handle() { | ||
adapter := flexadapter.New() | ||
adapter.Run(driverName, driverPath, nodeID, endpoint) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# CSI to Flexvolume adapter | ||
|
||
## Usage: | ||
|
||
### Start Flexvolume adapter for simple nfs flexvolume driver | ||
``` | ||
$ sudo ./_output/flexadapter --endpoint tcp://127.0.0.1:10000 --drivername simplenfs --driverpath ./pkg/flexadapter/examples/simplenfs-flexdriver/driver/nfs --nodeid CSINode -v=5 | ||
``` | ||
|
||
### Test using csc | ||
Get ```csc``` tool from https://github.com/rexray/gocsi/tree/master/csc | ||
|
||
#### Get plugin info | ||
``` | ||
$ csc identity plugin-info --endpoint tcp://127.0.0.1:10000 | ||
"simplenfs" "0.1.0" | ||
``` | ||
|
||
#### NodePublish a volume | ||
``` | ||
$ csc node publish --endpoint tcp://127.0.0.1:10000 --target-path /mnt/nfs --attrib server=a.b.c.d --attrib share=nfs_share nfstestvol | ||
nfstestvol | ||
``` | ||
|
||
#### NodeUnpublish a volume | ||
``` | ||
$ csc node unpublish --endpoint tcp://127.0.0.1:10000 --target-path /mnt/nfs nfstestvol | ||
nfstestvol | ||
``` | ||
|
||
#### Get NodeID | ||
``` | ||
$ csc node get-id --endpoint tcp://127.0.0.1:10000 | ||
CSINode | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package flexadapter | ||
|
||
import ( | ||
"github.com/container-storage-interface/spec/lib/go/csi" | ||
"golang.org/x/net/context" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
||
"github.com/kubernetes-csi/drivers/pkg/csi-common" | ||
) | ||
|
||
const ( | ||
deviceID = "deviceID" | ||
) | ||
|
||
type controllerServer struct { | ||
flexDriver *flexVolumeDriver | ||
*csicommon.DefaultControllerServer | ||
} | ||
|
||
func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) { | ||
if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME); err != nil { | ||
return nil, err | ||
} | ||
|
||
cap := req.GetVolumeCapability() | ||
fsType := "ext4" | ||
if cap != nil { | ||
mount := req.GetVolumeCapability().GetMount() | ||
fsType = mount.FsType | ||
} | ||
|
||
call := cs.flexDriver.NewDriverCall(attachCmd) | ||
call.AppendSpec(req.GetVolumeId(), fsType, req.GetReadonly(), req.GetVolumeContext()) | ||
call.Append(req.GetNodeId()) | ||
|
||
callStatus, err := call.Run() | ||
if isCmdNotSupportedErr(err) { | ||
return nil, status.Error(codes.Unimplemented, "") | ||
} else if err != nil { | ||
return nil, status.Error(codes.Internal, err.Error()) | ||
} | ||
|
||
publishContext := map[string]string{} | ||
|
||
publishContext[deviceID] = callStatus.DevicePath | ||
|
||
return &csi.ControllerPublishVolumeResponse{ | ||
PublishContext: publishContext, | ||
}, nil | ||
} | ||
|
||
func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) { | ||
if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME); err != nil { | ||
return nil, err | ||
} | ||
|
||
call := cs.flexDriver.NewDriverCall(detachCmd) | ||
call.Append(req.GetVolumeId()) | ||
call.Append(req.GetNodeId()) | ||
|
||
_, err := call.Run() | ||
if isCmdNotSupportedErr(err) { | ||
return nil, status.Error(codes.Unimplemented, "") | ||
} else if err != nil { | ||
return nil, status.Error(codes.Internal, err.Error()) | ||
} | ||
|
||
return &csi.ControllerUnpublishVolumeResponse{}, nil | ||
} | ||
|
||
func (cs *controllerServer) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) { | ||
return cs.DefaultControllerServer.ValidateVolumeCapabilities(ctx, req) | ||
} |
Oops, something went wrong.