Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.

Adding minio-driver #11

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions examples/sample-provisioner/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
Copyright 2020 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 (
"context"
"flag"
"fmt"
"os"
"os/signal"
"strings"
"syscall"

"github.com/kubernetes-sigs/container-object-storage-interface-provisioner-sidecar/examples/sample-provisioner/driver"
server "github.com/kubernetes-sigs/container-object-storage-interface-provisioner-sidecar/pkg/grpcserver"
"github.com/minio/minio-go"
"github.com/minio/minio/pkg/madmin"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"k8s.io/klog"
)

var (
cosiAddress = "tcp://0.0.0.0:9000"
s3Endpoint = "tcp://0.0.0.0:9000"
accessKey = "AKIAIOSFODNN7EXAMPLE"
secretKey = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
ctx context.Context
)

var cmd = &cobra.Command{
Use: os.Args[0],
Short: "sample provisoner for provisioning bucket instance to the backend bucket",
SilenceErrors: true,
SilenceUsage: true,
RunE: func(c *cobra.Command, args []string) error {
return run(args, cosiAddress)
},
DisableFlagsInUseLine: true,
Version: driver.VERSION,
}

func init() {
viper.AutomaticEnv()

cmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
flag.Set("logtostderr", "true")

strFlag := func(c *cobra.Command, ptr *string, name string, short string, dfault string, desc string) {
c.PersistentFlags().
StringVarP(ptr, name, short, dfault, desc)
}
strFlag(cmd, &cosiAddress, "listen-address", "", cosiAddress, "The address for the driver to listen on")
strFlag(cmd, &s3Endpoint, "s3-endpoint", "", "", "S3-endpont")
strFlag(cmd, &accessKey, "access-key", "", "", "S3-AccessKey")
strFlag(cmd, &secretKey, "secret-key", "", "", "S3-SecretKey")
hideFlag := func(name string) {
cmd.PersistentFlags().MarkHidden(name)
}
hideFlag("alsologtostderr")
hideFlag("log_backtrace_at")
hideFlag("log_dir")
hideFlag("logtostderr")
hideFlag("master")
hideFlag("stderrthreshold")
hideFlag("vmodule")

// Substitute _ for -
replacer := strings.NewReplacer("-", "_")
viper.SetEnvKeyReplacer(replacer)

// suppress the incorrect prefix in glog output
flag.CommandLine.Parse([]string{})
viper.BindPFlags(cmd.PersistentFlags())

var cancel context.CancelFunc

ctx, cancel = context.WithCancel(context.Background())
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGSEGV)

go func() {
s := <-sigs
cancel()
klog.Error(fmt.Sprintf("%s %s", s.String(), "Signal received. Exiting"))
}()

}

func main() {
if err := cmd.Execute(); err != nil {
klog.Fatal(err.Error())

}
}

func run(args []string, endpoint string) error {
// Initialize minio client object.
minioClient, err := minio.New(s3Endpoint, accessKey, secretKey, false)
if err != nil {
klog.Fatalln(err)
}
minioAdminClient, err := madmin.New(s3Endpoint, accessKey, secretKey, false)
if err != nil {
klog.Fatalln(err)
}
cds := driver.DriverServer{Name: driver.PROVISIONER_NAME, Version: driver.VERSION, S3Client: minioClient, S3AdminClient: minioAdminClient}
s := server.NewNonBlockingGRPCServer()
s.Start(endpoint, &cds)
s.Wait()
return nil
}
66 changes: 66 additions & 0 deletions examples/sample-provisioner/driver/driverserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright 2020 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 driver

import (
"fmt"

cosi "github.com/kubernetes-sigs/container-object-storage-interface-spec"
"github.com/minio/minio-go"

"github.com/minio/minio/pkg/madmin"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

var (
PROVISIONER_NAME = "sample-provisioner.objectstorage.k8s.io"
VERSION = "dev"
)

type DriverServer struct {
Name, Version string
S3Client *minio.Client
S3AdminClient *madmin.AdminClient
}

func (ds *DriverServer) ProvisionerGetInfo(context.Context, *cosi.ProvisionerGetInfoRequest) (*cosi.ProvisionerGetInfoResponse, error) {
rsp := &cosi.ProvisionerGetInfoResponse{}

rsp.ProvisionerIdentity = fmt.Sprintf("%s-%s", ds.Name, ds.Version)
return rsp, nil
}

func (ds DriverServer) ProvisionerCreateBucket(ctx context.Context, req *cosi.ProvisionerCreateBucketRequest) (*cosi.ProvisionerCreateBucketResponse, error) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is empty?

return nil, status.Error(codes.Unavailable, "Method not implemented")
}

func (ds *DriverServer) ProvisionerDeleteBucket(ctx context.Context, req *cosi.ProvisionerDeleteBucketRequest) (*cosi.ProvisionerDeleteBucketResponse, error) {

return nil, status.Error(codes.Unavailable, "Method not implemented")
}

func (ds *DriverServer) ProvisionerGrantBucketAccess(ctx context.Context, req *cosi.ProvisionerGrantBucketAccessRequest) (*cosi.ProvisionerGrantBucketAccessResponse, error) {
return nil, status.Error(codes.Unavailable, "Method not implemented")
}

func (ds *DriverServer) ProvisionerRevokeBucketAccess(ctx context.Context, req *cosi.ProvisionerRevokeBucketAccessRequest) (*cosi.ProvisionerRevokeBucketAccessResponse, error) {

return nil, status.Error(codes.Unavailable, "Method not implemented")
}
12 changes: 10 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ module github.com/kubernetes-sigs/container-object-storage-interface-provisioner
go 1.14

require (
google.golang.org/grpc v1.34.0 // indirect
k8s.io/klog v1.0.0 // indirect
github.com/go-ini/ini v1.62.0 // indirect
github.com/kubernetes-csi/csi-lib-utils v0.9.0
github.com/kubernetes-sigs/container-object-storage-interface-spec v0.0.0-20201208142312-59e00cb00687
github.com/minio/minio v0.0.0-20201209163743-e65ed2e44fdd
github.com/minio/minio-go v6.0.14+incompatible
github.com/spf13/cobra v1.1.1
github.com/spf13/viper v1.7.1
golang.org/x/net v0.0.0-20200904194848-62affa334b73
google.golang.org/grpc v1.34.0
k8s.io/klog v1.0.0
)
Loading