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

add identity server to sample-driver #41

Merged
merged 1 commit into from
Mar 19, 2021
Merged
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
20 changes: 0 additions & 20 deletions cmd/sample-driver/driver-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
53 changes: 53 additions & 0 deletions cmd/sample-driver/identity-server.go
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 3 additions & 3 deletions cmd/sample-driver/sample-driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
11 changes: 7 additions & 4 deletions pkg/grpcserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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())

Expand Down