From a6539f5611fd4542ae6183c2c3b84cc40625216d Mon Sep 17 00:00:00 2001 From: Krish Chowdhary Date: Thu, 18 Mar 2021 12:47:50 -0400 Subject: [PATCH] add identity server to sample-driver --- cmd/sample-driver/driver-server.go | 20 ----------- cmd/sample-driver/identity-server.go | 53 ++++++++++++++++++++++++++++ cmd/sample-driver/sample-driver.go | 6 ++-- pkg/grpcserver/server.go | 11 +++--- 4 files changed, 63 insertions(+), 27 deletions(-) create mode 100644 cmd/sample-driver/identity-server.go diff --git a/cmd/sample-driver/driver-server.go b/cmd/sample-driver/driver-server.go index 9d5e795..00d2cdf 100644 --- a/cmd/sample-driver/driver-server.go +++ b/cmd/sample-driver/driver-server.go @@ -35,34 +35,14 @@ import ( cosi "sigs.k8s.io/container-object-storage-interface-spec" ) -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.Name = fmt.Sprintf("%s-%s", ds.Name, ds.Version) - return rsp, nil -} - func (ds DriverServer) ProvisionerCreateBucket(ctx context.Context, req *cosi.ProvisionerCreateBucketRequest) (*cosi.ProvisionerCreateBucketResponse, error) { klog.Infof("Using minio to create Backend Bucket") - if ds.Name == "" { - return nil, status.Error(codes.Unavailable, "Driver name not configured") - } - - if ds.Version == "" { - return nil, status.Error(codes.Unavailable, "Driver is missing version") - } - s3 := req.Protocol.GetS3() if s3 == nil { return nil, status.Error(codes.Unavailable, "Driver is missing protocol") diff --git a/cmd/sample-driver/identity-server.go b/cmd/sample-driver/identity-server.go new file mode 100644 index 0000000..6438221 --- /dev/null +++ b/cmd/sample-driver/identity-server.go @@ -0,0 +1,53 @@ +/* +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 ( + "fmt" + + "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" + + cosi "sigs.k8s.io/container-object-storage-interface-spec" +) + +var ( + PROVISIONER_NAME = "sample-provisioner.objectstorage.k8s.io" + VERSION = "dev" +) + +type IdentityServer struct { + Name, Version string + S3Client *minio.Client + S3AdminClient *madmin.AdminClient +} + +func (id *IdentityServer) ProvisionerGetInfo(context.Context, *cosi.ProvisionerGetInfoRequest) (*cosi.ProvisionerGetInfoResponse, error) { + if id.Name == "" { + return nil, status.Error(codes.Unavailable, "Driver name not configured") + } + + if id.Version == "" { + return nil, status.Error(codes.Unavailable, "Driver is missing version") + } + rsp := &cosi.ProvisionerGetInfoResponse{} + rsp.Name = fmt.Sprintf("%s-%s", id.Name, id.Version) + return rsp, nil +} diff --git a/cmd/sample-driver/sample-driver.go b/cmd/sample-driver/sample-driver.go index 9aaab8b..af1c2b1 100644 --- a/cmd/sample-driver/sample-driver.go +++ b/cmd/sample-driver/sample-driver.go @@ -29,7 +29,6 @@ import ( "github.com/minio/minio/pkg/madmin" "github.com/spf13/cobra" "github.com/spf13/viper" - "k8s.io/klog/v2" "sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/grpcserver" @@ -119,9 +118,10 @@ func run(args []string, endpoint string) error { if err != nil { klog.Fatalln(err) } - cds := DriverServer{Name: PROVISIONER_NAME, Version: VERSION, S3Client: minioClient, S3AdminClient: minioAdminClient} + cds := DriverServer{S3Client: minioClient, S3AdminClient: minioAdminClient} + ids := IdentityServer{Name: PROVISIONER_NAME, Version: VERSION} s := grpcserver.NewNonBlockingGRPCServer() - s.Start(endpoint, &cds) + s.Start(endpoint, &cds, &ids) s.Wait() return nil } diff --git a/pkg/grpcserver/server.go b/pkg/grpcserver/server.go index 5684808..a78901e 100644 --- a/pkg/grpcserver/server.go +++ b/pkg/grpcserver/server.go @@ -35,7 +35,7 @@ import ( // Defines Non blocking GRPC server interfaces type NonBlockingGRPCServer interface { // Start services at the endpoint - Start(endpoint string, cds osi.ProvisionerServer) + Start(endpoint string, cds osi.ProvisionerServer, ids osi.IdentityServer) // Waits for the service to stop Wait() // Stops the service gracefully @@ -76,11 +76,11 @@ func ParseEndpoint(ep string) (string, string, error) { return "", "", fmt.Errorf("Invalid endpoint: %v", ep) } -func (s *nonBlockingGRPCServer) Start(endpoint string, cds osi.ProvisionerServer) { +func (s *nonBlockingGRPCServer) Start(endpoint string, cds osi.ProvisionerServer, ids osi.IdentityServer) { s.wg.Add(1) - go s.serve(endpoint, cds) + go s.serve(endpoint, cds, ids) return } @@ -97,7 +97,7 @@ func (s *nonBlockingGRPCServer) ForceStop() { s.server.Stop() } -func (s *nonBlockingGRPCServer) serve(endpoint string, driver osi.ProvisionerServer) { +func (s *nonBlockingGRPCServer) serve(endpoint string, driver osi.ProvisionerServer, identity osi.IdentityServer) { proto, addr, err := ParseEndpoint(endpoint) if err != nil { @@ -128,6 +128,9 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, driver osi.ProvisionerSer if driver != nil { osi.RegisterProvisionerServer(server, driver) } + if identity != nil { + osi.RegisterIdentityServer(server, identity) + } klog.Infof("Listening for connections on address: %#v", listener.Addr())