2018-07-14 08:48:22 +00:00
|
|
|
/*
|
|
|
|
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 s3
|
|
|
|
|
|
|
|
import (
|
2019-02-28 18:34:03 +00:00
|
|
|
"github.com/container-storage-interface/spec/lib/go/csi"
|
2018-07-14 08:48:22 +00:00
|
|
|
"github.com/golang/glog"
|
|
|
|
|
2019-03-10 11:19:02 +00:00
|
|
|
csicommon "github.com/kubernetes-csi/drivers/pkg/csi-common"
|
2018-07-14 08:48:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type s3 struct {
|
|
|
|
driver *csicommon.CSIDriver
|
|
|
|
endpoint string
|
|
|
|
|
|
|
|
ids *identityServer
|
|
|
|
ns *nodeServer
|
|
|
|
cs *controllerServer
|
|
|
|
}
|
|
|
|
|
|
|
|
type s3Volume struct {
|
|
|
|
VolName string `json:"volName"`
|
|
|
|
VolID string `json:"volID"`
|
|
|
|
VolSize int64 `json:"volSize"`
|
|
|
|
VolPath string `json:"volPath"`
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2019-05-14 19:53:44 +00:00
|
|
|
vendorVersion = "1.1.0"
|
2018-07-14 08:48:22 +00:00
|
|
|
driverName = "ch.ctrox.csi.s3-driver"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewS3 initializes the driver
|
2019-03-10 11:19:02 +00:00
|
|
|
func NewS3(nodeID string, endpoint string) (*s3, error) {
|
2018-07-14 08:48:22 +00:00
|
|
|
driver := csicommon.NewCSIDriver(driverName, vendorVersion, nodeID)
|
|
|
|
if driver == nil {
|
|
|
|
glog.Fatalln("Failed to initialize CSI Driver.")
|
|
|
|
}
|
|
|
|
|
|
|
|
s3Driver := &s3{
|
|
|
|
endpoint: endpoint,
|
|
|
|
driver: driver,
|
|
|
|
}
|
|
|
|
return s3Driver, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s3 *s3) newIdentityServer(d *csicommon.CSIDriver) *identityServer {
|
|
|
|
return &identityServer{
|
|
|
|
DefaultIdentityServer: csicommon.NewDefaultIdentityServer(d),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s3 *s3) newControllerServer(d *csicommon.CSIDriver) *controllerServer {
|
|
|
|
return &controllerServer{
|
|
|
|
DefaultControllerServer: csicommon.NewDefaultControllerServer(d),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s3 *s3) newNodeServer(d *csicommon.CSIDriver) *nodeServer {
|
|
|
|
return &nodeServer{
|
|
|
|
DefaultNodeServer: csicommon.NewDefaultNodeServer(d),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s3 *s3) Run() {
|
|
|
|
glog.Infof("Driver: %v ", driverName)
|
2019-01-19 13:40:58 +00:00
|
|
|
glog.Infof("Version: %v ", vendorVersion)
|
2018-07-14 08:48:22 +00:00
|
|
|
// Initialize default library driver
|
|
|
|
|
|
|
|
s3.driver.AddControllerServiceCapabilities([]csi.ControllerServiceCapability_RPC_Type{csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME})
|
|
|
|
s3.driver.AddVolumeCapabilityAccessModes([]csi.VolumeCapability_AccessMode_Mode{csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER})
|
|
|
|
|
|
|
|
// Create GRPC servers
|
|
|
|
s3.ids = s3.newIdentityServer(s3.driver)
|
|
|
|
s3.ns = s3.newNodeServer(s3.driver)
|
|
|
|
s3.cs = s3.newControllerServer(s3.driver)
|
|
|
|
|
|
|
|
s := csicommon.NewNonBlockingGRPCServer()
|
|
|
|
s.Start(s3.endpoint, s3.ids, s3.cs, s3.ns)
|
|
|
|
s.Wait()
|
|
|
|
}
|