Skip to content

Commit

Permalink
Merge pull request #7 from bizflycloud/fix/release-0.1
Browse files Browse the repository at this point in the history
Fix/release 0.1
  • Loading branch information
greatbn authored Jun 11, 2020
2 parents d64fab9 + cc4ac38 commit d7492db
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 217 deletions.
76 changes: 43 additions & 33 deletions cmd/csi-bizflycloud/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ import (
)

var (
endpoint string
nodeID string
authMethod string
username string
password string
appCredID string
appCredSecret string
cluster string
apiUrl string
endpoint string
nodeID string
authMethod string
username string
password string
tenantID string
appCredID string
appCredSecret string
cluster string
apiUrl string
isControlPlane bool
)

func init() {
Expand Down Expand Up @@ -88,6 +90,8 @@ func main() {
cmd.PersistentFlags().StringVar(&endpoint, "endpoint", "", "CSI endpoint")
cmd.MarkPersistentFlagRequired("endpoint")

cmd.PersistentFlags().BoolVar(&isControlPlane, "is_control_plane", false, "Is Control Plane node")

cmd.PersistentFlags().StringVar(&authMethod, "auth_method", "password", "Authentication method")

cmd.PersistentFlags().StringVar(&username, "username", "", "BizFly Cloud username")
Expand All @@ -98,6 +102,8 @@ func main() {

cmd.PersistentFlags().StringVar(&appCredSecret, "application_credential_secret", "", "BizFly Cloud Application Credential Secret")

cmd.PersistentFlags().StringVar(&tenantID, "tenant_id", "", "BizFly Cloud Tenant ID")

cmd.PersistentFlags().StringVar(&apiUrl, "api_url", "https://manage.bizflycloud.vn", "BizFly Cloud API URL")

cmd.PersistentFlags().StringVar(&cluster, "cluster", "", "The identifier of the cluster that the plugin is running in.")
Expand Down Expand Up @@ -129,29 +135,33 @@ func handle() {
klog.V(3).Infof("Failed to GetMetadataProvider: %v", err)
}

client, err := gobizfly.NewClient(gobizfly.WithTenantName(username), gobizfly.WithAPIUrl(apiUrl))
if err != nil {
klog.Errorf("failed to create bizfly client: %v", err)
return
if isControlPlane {
client, err := gobizfly.NewClient(gobizfly.WithTenantName(username), gobizfly.WithAPIUrl(apiUrl), gobizfly.WithTenantID(tenantID))
if err != nil {
klog.Errorf("failed to create bizfly client: %v", err)
return
}
ctx, cancelFunc := context.WithTimeout(context.Background(), time.Second*10)
defer cancelFunc()

tok, err := client.Token.Create(ctx, &gobizfly.TokenCreateRequest{
AuthMethod: authMethod,
Username: username,
Password: password,
AppCredID: appCredID,
AppCredSecret: appCredSecret})

client.SetKeystoneToken(tok.KeystoneToken)

if err != nil {
klog.Errorf("Failed to get bizfly client token: %v", err)
return
}
client.SetKeystoneToken(tok.KeystoneToken)
d.SetupControlDriver(client, iMount, metadatda)
d.Run()
} else {
d.SetupNodeDriver(iMount, metadatda)
d.Run()
}
ctx, cancelFunc := context.WithTimeout(context.Background(), time.Second*10)
defer cancelFunc()

tok, err := client.Token.Create(ctx, &gobizfly.TokenCreateRequest{
AuthMethod: authMethod,
Username: username,
Password: password,
AppCredID: appCredID,
AppCredSecret: appCredSecret})

client.SetKeystoneToken(tok.KeystoneToken)

if err != nil {
klog.Errorf("Failed to get bizfly client token: %v", err)
return
}
client.SetKeystoneToken(tok.KeystoneToken)

d.SetupDriver(client, iMount, metadatda)
d.Run()
}
11 changes: 8 additions & 3 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,16 @@ func (d *VolumeDriver) AddNodeServiceCapabilities(nl []csi.NodeServiceCapability
return nil
}

// SetupDriver setups driver for volume driver
func (d *VolumeDriver) SetupDriver(client *gobizfly.Client, mount mount.IMount, metadata openstack.IMetadata) {
// SetupControlDriver setups driver for control plane
func (d *VolumeDriver) SetupControlDriver(client *gobizfly.Client, mount mount.IMount, metadata openstack.IMetadata) {
d.ids = NewIdentityServer(d)
d.cs = NewControllerServer(d, client)
d.ns = NewNodeServer(d, mount, metadata, client)
}

// SetupControlDriver setups driver for control plane
func (d *VolumeDriver) SetupNodeDriver(mount mount.IMount, metadata openstack.IMetadata) {
d.ids = NewIdentityServer(d)
d.ns = NewNodeServer(d, mount, metadata)
}

// Run run driver
Expand Down
85 changes: 42 additions & 43 deletions driver/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ import (
"path/filepath"
"strings"

"github.com/bizflycloud/gobizfly"
//"github.com/bizflycloud/gobizfly"
"github.com/container-storage-interface/spec/lib/go/csi"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/cloud-provider-openstack/pkg/csi/cinder/openstack"
"k8s.io/cloud-provider-openstack/pkg/util/blockdevice"
cpoerrors "k8s.io/cloud-provider-openstack/pkg/util/errors"
"k8s.io/cloud-provider-openstack/pkg/util/metadata"
"k8s.io/cloud-provider-openstack/pkg/util/mount"
"k8s.io/klog"
Expand All @@ -42,7 +41,7 @@ type nodeServer struct {
Driver *VolumeDriver
Mount mount.IMount
Metadata openstack.IMetadata
Client *gobizfly.Client
//Client *gobizfly.Client
}

func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
Expand All @@ -68,13 +67,13 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
if len(source) == 0 {
return nil, status.Error(codes.InvalidArgument, "NodePublishVolume Staging Target Path must be provided")
}
_, err := ns.Client.Volume.Get(ctx, volumeID)
if err != nil {
if cpoerrors.IsNotFound(err) {
return nil, status.Error(codes.NotFound, "Volume not found")
}
return nil, status.Error(codes.Internal, fmt.Sprintf("GetVolume failed with error %v", err))
}
//_, err := ns.Client.Volume.Get(ctx, volumeID)
//if err != nil {
// if cpoerrors.IsNotFound(err) {
// return nil, status.Error(codes.NotFound, "Volume not found")
// }
// return nil, status.Error(codes.Internal, fmt.Sprintf("GetVolume failed with error %v", err))
//}

mountOptions := []string{"bind"}
if req.GetReadonly() {
Expand Down Expand Up @@ -163,24 +162,24 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
return nil, status.Error(codes.InvalidArgument, "NodeUnpublishVolume volumeID must be provided")
}

if _, err := ns.Client.Volume.Get(ctx, volumeID); err != nil {
if !cpoerrors.IsNotFound(err) {
return nil, status.Error(codes.Internal, fmt.Sprintf("GetVolume failed with error %v", err))
}

// if not found by id, try to search by name
volName := fmt.Sprintf("ephemeral-%s", volumeID)

vol, err := GetVolumesByName(ctx, ns.Client, volName)

//if volume not found then GetVolumesByName returns empty list
if err != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("GetVolume failed with error %v", err))
}
if vol == nil {
return nil, status.Error(codes.NotFound, fmt.Sprintf("Volume not found %s", volName))
}
}
//if _, err := ns.Client.Volume.Get(ctx, volumeID); err != nil {
// if !cpoerrors.IsNotFound(err) {
// return nil, status.Error(codes.Internal, fmt.Sprintf("GetVolume failed with error %v", err))
// }
//
// // if not found by id, try to search by name
// volName := fmt.Sprintf("ephemeral-%s", volumeID)
//
// vol, err := GetVolumesByName(ctx, ns.Client, volName)
//
// //if volume not found then GetVolumesByName returns empty list
// if err != nil {
// return nil, status.Error(codes.Internal, fmt.Sprintf("GetVolume failed with error %v", err))
// }
// if vol == nil {
// return nil, status.Error(codes.NotFound, fmt.Sprintf("Volume not found %s", volName))
// }
//}

m := ns.Mount
notMnt, err := m.IsLikelyNotMountPointDetach(targetPath)
Expand Down Expand Up @@ -220,13 +219,13 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
return nil, status.Error(codes.InvalidArgument, "NodeStageVolume Volume Capability must be provided")
}

_, err := ns.Client.Volume.Get(ctx, volumeID)
if err != nil {
if cpoerrors.IsNotFound(err) {
return nil, status.Error(codes.NotFound, "Volume not found")
}
return nil, status.Error(codes.Internal, fmt.Sprintf("GetVolume failed with error %v", err))
}
//_, err := ns.Client.Volume.Get(ctx, volumeID)
//if err != nil {
// if cpoerrors.IsNotFound(err) {
// return nil, status.Error(codes.NotFound, "Volume not found")
// }
// return nil, status.Error(codes.Internal, fmt.Sprintf("GetVolume failed with error %v", err))
//}

m := ns.Mount
// Do not trust the path provided by cinder, get the real path on node
Expand Down Expand Up @@ -281,14 +280,14 @@ func (ns *nodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag
return nil, status.Error(codes.InvalidArgument, "NodeUnstageVolume Staging Target Path must be provided")
}

_, err := ns.Client.Volume.Get(ctx, volumeID)
if err != nil {
if cpoerrors.IsNotFound(err) {
klog.V(4).Infof("NodeUnstageVolume: Unable to find volume: %v", err)
return nil, status.Error(codes.NotFound, "Volume not found")
}
return nil, status.Error(codes.Internal, fmt.Sprintf("GetVolume failed with error %v", err))
}
//_, err := ns.Client.Volume.Get(ctx, volumeID)
//if err != nil {
// if cpoerrors.IsNotFound(err) {
// klog.V(4).Infof("NodeUnstageVolume: Unable to find volume: %v", err)
// return nil, status.Error(codes.NotFound, "Volume not found")
// }
// return nil, status.Error(codes.Internal, fmt.Sprintf("GetVolume failed with error %v", err))
//}

m := ns.Mount

Expand Down
3 changes: 1 addition & 2 deletions driver/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ func NewIdentityServer(d *VolumeDriver) *identityServer {
}
}

func NewNodeServer(d *VolumeDriver, mount mount.IMount, metadata openstack.IMetadata, client *gobizfly.Client) *nodeServer {
func NewNodeServer(d *VolumeDriver, mount mount.IMount, metadata openstack.IMetadata) *nodeServer {
return &nodeServer{
Driver: d,
Mount: mount,
Metadata: metadata,
Client: client,
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/bizflycloud/csi-bizflycloud
go 1.14

require (
github.com/bizflycloud/gobizfly v0.0.0-20200514081735-03c430a0585b
github.com/bizflycloud/gobizfly v0.0.0-20200610135315-1b3e23893213
github.com/container-storage-interface/spec v1.2.0
github.com/golang/protobuf v1.4.1
github.com/spf13/cobra v1.0.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ github.com/bizflycloud/gobizfly v0.0.0-20200509022858-1dd705ff35b3 h1:3195YbHKzP
github.com/bizflycloud/gobizfly v0.0.0-20200509022858-1dd705ff35b3/go.mod h1:2otUgZd6PrKezjMrdAw9gy7byEXMrigX9Sm4ujCaFuk=
github.com/bizflycloud/gobizfly v0.0.0-20200514081735-03c430a0585b h1:9DaY0hAkK/PGs12481LXTyFmuGKfkW6u7VPsyRXuPHk=
github.com/bizflycloud/gobizfly v0.0.0-20200514081735-03c430a0585b/go.mod h1:2otUgZd6PrKezjMrdAw9gy7byEXMrigX9Sm4ujCaFuk=
github.com/bizflycloud/gobizfly v0.0.0-20200610135315-1b3e23893213 h1:Ihr811tiEnUKB0QaDJglGI+fCwFrcXy8Q17vpFTEvEc=
github.com/bizflycloud/gobizfly v0.0.0-20200610135315-1b3e23893213/go.mod h1:2otUgZd6PrKezjMrdAw9gy7byEXMrigX9Sm4ujCaFuk=
github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ spec:
- name: socket-dir
mountPath: /var/lib/csi/sockets/pluginproxy/
- name: bizflycloud-csi-plugin
image: cr-hn-1.vccloud.vn/31ff9581861a4d0ea4df5e7dda0f665d/csi-bizflycloud:v0.1
image: cr-hn-1.vccloud.vn/31ff9581861a4d0ea4df5e7dda0f665d/csi-bizflycloud:v0.1.0
args :
- /bin/csi-bizflycloud
- "--nodeid=$(NODE_ID)"
Expand All @@ -91,6 +91,8 @@ spec:
- "--auth_method=application_credential"
- "--application_credential_id=$(BIZFLYCLOUD_APPLICATION_CREDENTIAL_ID)"
- "--application_credential_secret=$(BIZFLYCLOUD_APPLICATION_CREDENTIAL_SECRET)"
- "--tenant_id=$(TENANT_ID)"
- "--is_control_plane=true"
env:
- name: NODE_ID
valueFrom:
Expand All @@ -110,7 +112,12 @@ spec:
secretKeyRef:
name: bizflycloud
key: application_credential_secret
imagePullPolicy: "IfNotPresent"
- name: TENANT_ID
valueFrom:
secretKeyRef:
name: bizflycloud
key: tenant_id
imagePullPolicy: "Always"
volumeMounts:
- name: socket-dir
mountPath: /csi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,18 @@ spec:
capabilities:
add: ["SYS_ADMIN"]
allowPrivilegeEscalation: true
image: cr-hn-1.vccloud.vn/31ff9581861a4d0ea4df5e7dda0f665d/csi-bizflycloud:v0.1
image: cr-hn-1.vccloud.vn/31ff9581861a4d0ea4df5e7dda0f665d/csi-bizflycloud:v0.1.0
args :
- /bin/csi-bizflycloud
- "--nodeid=$(NODE_ID)"
- "--endpoint=$(CSI_ENDPOINT)"
- "--auth_method=application_credential"
- "--application_credential_id=$(BIZFLYCLOUD_APPLICATION_CREDENTIAL_ID)"
- "--application_credential_secret=$(BIZFLYCLOUD_APPLICATION_CREDENTIAL_SECRET)"
env:
- name: NODE_ID
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: CSI_ENDPOINT
value: unix://csi/csi.sock
- name: BIZFLYCLOUD_APPLICATION_CREDENTIAL_ID
valueFrom:
secretKeyRef:
name: bizflycloud
key: application_credential_id
- name: BIZFLYCLOUD_APPLICATION_CREDENTIAL_SECRET
valueFrom:
secretKeyRef:
name: bizflycloud
key: application_credential_secret
imagePullPolicy: "IfNotPresent"
volumeMounts:
- name: socket-dir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ metadata:
spec:
attachRequired: true
podInfoOnMount: true
volumeLifecycleModes:
- Persistent
# volumeLifecycleModes:
# - Persistent
9 changes: 9 additions & 0 deletions releases/v0.1.0/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: bizflycloud
namespace: kube-system
stringData:
application_credential_id: "your_application_credential_id"
application_credential_secret: "your_application_credential_secret"
tenant_id: "your_tenant_id"
Loading

0 comments on commit d7492db

Please sign in to comment.