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

Commit 754296b

Browse files
authored
Merge pull request #21 from rrati/binaries
Added binary source and build target
2 parents f3f77c7 + 28f6e63 commit 754296b

File tree

7 files changed

+143
-3
lines changed

7 files changed

+143
-3
lines changed

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
CMDS=objectstorage-sidecar
16+
1517
all: reltools build
1618
.PHONY: reltools
1719
reltools: release-tools/build.make
@@ -23,6 +25,5 @@ release-tools/build.make:
2325
$(shell rm -rf ${TMP})
2426
ln -s release-tools/travis.yml travis.yml
2527

26-
#CMDS=provisioner-sidecar
2728

2829
include release-tools/build.make
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package app
2+
3+
import (
4+
"context"
5+
"os"
6+
"time"
7+
8+
"github.com/kubernetes-sigs/container-object-storage-interface-provisioner-sidecar/pkg/controller/bucket"
9+
"github.com/kubernetes-sigs/container-object-storage-interface-provisioner-sidecar/pkg/controller/bucketaccess"
10+
"github.com/kubernetes-sigs/container-object-storage-interface-provisioner-sidecar/pkg/grpcclient"
11+
12+
osspec "github.com/kubernetes-sigs/container-object-storage-interface-spec"
13+
14+
"github.com/spf13/cobra"
15+
16+
"google.golang.org/grpc"
17+
18+
"k8s.io/klog"
19+
)
20+
21+
const (
22+
// Interval of logging connection errors
23+
connectionLoggingInterval = 10 * time.Second
24+
defaultDriverAddress = "tcp://0.0.0.0:9000"
25+
)
26+
27+
// SidecarOptions defines the options
28+
type SidecarOptions struct {
29+
driverAddress string
30+
}
31+
32+
// NewSidecarOptions returns an initialized SidecarOptions instance
33+
func NewSidecarOptions() *SidecarOptions {
34+
return &SidecarOptions{driverAddress: defaultDriverAddress}
35+
}
36+
37+
// Run starts the sidecar with the configured options
38+
func (so *SidecarOptions) Run() {
39+
klog.V(1).Infof("attempting to open a gRPC connection with: %q", so.driverAddress)
40+
grpcClient, err := grpcclient.NewGRPCClient(so.driverAddress, []grpc.DialOption{}, nil)
41+
if err != nil {
42+
klog.Errorf("error creating GRPC Client: %v", err)
43+
os.Exit(1)
44+
}
45+
46+
grpcConn, err := grpcClient.ConnectWithLogging(connectionLoggingInterval)
47+
if err != nil {
48+
klog.Errorf("error connecting to COSI driver: %v", err)
49+
os.Exit(1)
50+
}
51+
52+
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
53+
defer cancel()
54+
55+
klog.V(1).Infof("creating provisioner client")
56+
provisionerClient := osspec.NewProvisionerClient(grpcConn)
57+
58+
klog.Infof("discovering driver name")
59+
req := osspec.ProvisionerGetInfoRequest{}
60+
rsp, err := provisionerClient.ProvisionerGetInfo(ctx, &req)
61+
if err != nil {
62+
klog.Errorf("error calling ProvisionerGetInfo: %v", err)
63+
os.Exit(1)
64+
}
65+
66+
provisionerName := rsp.Name
67+
// TODO: Register provisioner using internal type
68+
klog.Info("This sidecar is working with the driver identified as: ", provisionerName)
69+
70+
so.startControllers(ctx, provisionerName, provisionerClient)
71+
<-ctx.Done()
72+
}
73+
74+
func (so *SidecarOptions) startControllers(ctx context.Context, name string, client osspec.ProvisionerClient) {
75+
bucketController, err := bucket.NewBucketController(name, client)
76+
if err != nil {
77+
klog.Fatalf("Error creating bucket controller: %v", err)
78+
}
79+
80+
bucketAccessController, err := bucketaccess.NewBucketAccessController(name, client)
81+
if err != nil {
82+
klog.Fatalf("Error creating bucket access controller: %v", err)
83+
}
84+
85+
go bucketController.Run(ctx)
86+
go bucketAccessController.Run(ctx)
87+
}
88+
89+
// NewControllerManagerCommand creates a *cobra.Command object with default parameters
90+
func NewControllerManagerCommand() *cobra.Command {
91+
opts := NewSidecarOptions()
92+
93+
cmd := &cobra.Command{
94+
Use: "objectstorage-sidecar",
95+
DisableFlagsInUseLine: true,
96+
Short: "",
97+
Long: ``,
98+
Run: func(cmd *cobra.Command, args []string) {
99+
opts.Run()
100+
},
101+
}
102+
103+
cmd.Flags().StringVarP(&opts.driverAddress, "connect-address", "c", opts.driverAddress, "The address that the sidecar should connect to")
104+
105+
return cmd
106+
}

cmd/objectstorage-sidecar/main.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
"os"
21+
22+
"github.com/kubernetes-sigs/container-object-storage-interface-provisioner-sidecar/cmd/objectstorage-sidecar/app"
23+
)
24+
25+
func main() {
26+
command := app.NewControllerManagerCommand()
27+
if err := command.Execute(); err != nil {
28+
os.Exit(1)
29+
}
30+
}

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/kubernetes-csi/csi-lib-utils v0.9.0
77
github.com/kubernetes-sigs/container-object-storage-interface-api v0.0.0-20201217233824-6b4158ff7e28
88
github.com/kubernetes-sigs/container-object-storage-interface-spec v0.0.0-20201217184109-8cbf84dde8d3
9+
github.com/spf13/cobra v0.0.5
910
golang.org/x/net v0.0.0-20200707034311-ab3426394381
1011
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
1112
google.golang.org/grpc v1.34.0

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
233233
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
234234
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
235235
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
236+
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
236237
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
237238
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
238239
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
@@ -342,6 +343,7 @@ github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTd
342343
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
343344
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
344345
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
346+
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
345347
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
346348
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
347349
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=

pkg/controller/bucket/bucket_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func NewBucketController(provisionerName string, client osspec.ProvisionerClient
5959
&workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(10), 100)},
6060
)
6161

62-
identity := fmt.Sprintf("object-storage-sidecar-%s", provisionerName)
62+
identity := fmt.Sprintf("objectstorage-sidecar-%s", provisionerName)
6363
bc, err := controller.NewObjectStorageController(identity, "bucket-controller", 5, rateLimit)
6464
if err != nil {
6565
return nil, err

pkg/controller/bucketaccess/bucket_access_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func NewBucketAccessController(provisionerName string, client osspec.Provisioner
6666
&workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(10), 100)},
6767
)
6868

69-
identity := fmt.Sprintf("object-storage-sidecar-%s", provisionerName)
69+
identity := fmt.Sprintf("objectstorage-sidecar-%s", provisionerName)
7070
bc, err := controller.NewObjectStorageController(identity, "bucket-access-controller", 5, rateLimit)
7171
if err != nil {
7272
return nil, err

0 commit comments

Comments
 (0)