Skip to content

Commit a6539f5

Browse files
author
Krish Chowdhary
committed
add identity server to sample-driver
1 parent 59ab667 commit a6539f5

File tree

4 files changed

+63
-27
lines changed

4 files changed

+63
-27
lines changed

cmd/sample-driver/driver-server.go

-20
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,14 @@ import (
3535
cosi "sigs.k8s.io/container-object-storage-interface-spec"
3636
)
3737

38-
var (
39-
PROVISIONER_NAME = "sample-provisioner.objectstorage.k8s.io"
40-
VERSION = "dev"
41-
)
42-
4338
type DriverServer struct {
44-
Name, Version string
4539
S3Client *minio.Client
4640
S3AdminClient *madmin.AdminClient
4741
}
4842

49-
func (ds *DriverServer) ProvisionerGetInfo(context.Context, *cosi.ProvisionerGetInfoRequest) (*cosi.ProvisionerGetInfoResponse, error) {
50-
rsp := &cosi.ProvisionerGetInfoResponse{}
51-
rsp.Name = fmt.Sprintf("%s-%s", ds.Name, ds.Version)
52-
return rsp, nil
53-
}
54-
5543
func (ds DriverServer) ProvisionerCreateBucket(ctx context.Context, req *cosi.ProvisionerCreateBucketRequest) (*cosi.ProvisionerCreateBucketResponse, error) {
5644
klog.Infof("Using minio to create Backend Bucket")
5745

58-
if ds.Name == "" {
59-
return nil, status.Error(codes.Unavailable, "Driver name not configured")
60-
}
61-
62-
if ds.Version == "" {
63-
return nil, status.Error(codes.Unavailable, "Driver is missing version")
64-
}
65-
6646
s3 := req.Protocol.GetS3()
6747
if s3 == nil {
6848
return nil, status.Error(codes.Unavailable, "Driver is missing protocol")

cmd/sample-driver/identity-server.go

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/minio/minio-go"
23+
"github.com/minio/minio/pkg/madmin"
24+
"golang.org/x/net/context"
25+
"google.golang.org/grpc/codes"
26+
"google.golang.org/grpc/status"
27+
28+
cosi "sigs.k8s.io/container-object-storage-interface-spec"
29+
)
30+
31+
var (
32+
PROVISIONER_NAME = "sample-provisioner.objectstorage.k8s.io"
33+
VERSION = "dev"
34+
)
35+
36+
type IdentityServer struct {
37+
Name, Version string
38+
S3Client *minio.Client
39+
S3AdminClient *madmin.AdminClient
40+
}
41+
42+
func (id *IdentityServer) ProvisionerGetInfo(context.Context, *cosi.ProvisionerGetInfoRequest) (*cosi.ProvisionerGetInfoResponse, error) {
43+
if id.Name == "" {
44+
return nil, status.Error(codes.Unavailable, "Driver name not configured")
45+
}
46+
47+
if id.Version == "" {
48+
return nil, status.Error(codes.Unavailable, "Driver is missing version")
49+
}
50+
rsp := &cosi.ProvisionerGetInfoResponse{}
51+
rsp.Name = fmt.Sprintf("%s-%s", id.Name, id.Version)
52+
return rsp, nil
53+
}

cmd/sample-driver/sample-driver.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/minio/minio/pkg/madmin"
3030
"github.com/spf13/cobra"
3131
"github.com/spf13/viper"
32-
3332
"k8s.io/klog/v2"
3433

3534
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/grpcserver"
@@ -119,9 +118,10 @@ func run(args []string, endpoint string) error {
119118
if err != nil {
120119
klog.Fatalln(err)
121120
}
122-
cds := DriverServer{Name: PROVISIONER_NAME, Version: VERSION, S3Client: minioClient, S3AdminClient: minioAdminClient}
121+
cds := DriverServer{S3Client: minioClient, S3AdminClient: minioAdminClient}
122+
ids := IdentityServer{Name: PROVISIONER_NAME, Version: VERSION}
123123
s := grpcserver.NewNonBlockingGRPCServer()
124-
s.Start(endpoint, &cds)
124+
s.Start(endpoint, &cds, &ids)
125125
s.Wait()
126126
return nil
127127
}

pkg/grpcserver/server.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
// Defines Non blocking GRPC server interfaces
3636
type NonBlockingGRPCServer interface {
3737
// Start services at the endpoint
38-
Start(endpoint string, cds osi.ProvisionerServer)
38+
Start(endpoint string, cds osi.ProvisionerServer, ids osi.IdentityServer)
3939
// Waits for the service to stop
4040
Wait()
4141
// Stops the service gracefully
@@ -76,11 +76,11 @@ func ParseEndpoint(ep string) (string, string, error) {
7676
return "", "", fmt.Errorf("Invalid endpoint: %v", ep)
7777
}
7878

79-
func (s *nonBlockingGRPCServer) Start(endpoint string, cds osi.ProvisionerServer) {
79+
func (s *nonBlockingGRPCServer) Start(endpoint string, cds osi.ProvisionerServer, ids osi.IdentityServer) {
8080

8181
s.wg.Add(1)
8282

83-
go s.serve(endpoint, cds)
83+
go s.serve(endpoint, cds, ids)
8484

8585
return
8686
}
@@ -97,7 +97,7 @@ func (s *nonBlockingGRPCServer) ForceStop() {
9797
s.server.Stop()
9898
}
9999

100-
func (s *nonBlockingGRPCServer) serve(endpoint string, driver osi.ProvisionerServer) {
100+
func (s *nonBlockingGRPCServer) serve(endpoint string, driver osi.ProvisionerServer, identity osi.IdentityServer) {
101101

102102
proto, addr, err := ParseEndpoint(endpoint)
103103
if err != nil {
@@ -128,6 +128,9 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, driver osi.ProvisionerSer
128128
if driver != nil {
129129
osi.RegisterProvisionerServer(server, driver)
130130
}
131+
if identity != nil {
132+
osi.RegisterIdentityServer(server, identity)
133+
}
131134

132135
klog.Infof("Listening for connections on address: %#v", listener.Addr())
133136

0 commit comments

Comments
 (0)