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

Added binary source and build target #21

Merged
merged 1 commit into from
Dec 22, 2020
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

CMDS=objectstorage-sidecar

all: reltools build
.PHONY: reltools
reltools: release-tools/build.make
Expand All @@ -23,6 +25,5 @@ release-tools/build.make:
$(shell rm -rf ${TMP})
ln -s release-tools/travis.yml travis.yml

#CMDS=provisioner-sidecar

include release-tools/build.make
106 changes: 106 additions & 0 deletions cmd/objectstorage-sidecar/app/objectstorage-sidecar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package app

import (
"context"
"os"
"time"

"github.com/kubernetes-sigs/container-object-storage-interface-provisioner-sidecar/pkg/controller/bucket"
"github.com/kubernetes-sigs/container-object-storage-interface-provisioner-sidecar/pkg/controller/bucketaccess"
"github.com/kubernetes-sigs/container-object-storage-interface-provisioner-sidecar/pkg/grpcclient"

osspec "github.com/kubernetes-sigs/container-object-storage-interface-spec"

"github.com/spf13/cobra"

"google.golang.org/grpc"

"k8s.io/klog"
)

const (
// Interval of logging connection errors
connectionLoggingInterval = 10 * time.Second
defaultDriverAddress = "tcp://0.0.0.0:9000"
)

// SidecarOptions defines the options
type SidecarOptions struct {
driverAddress string
}

// NewSidecarOptions returns an initialized SidecarOptions instance
func NewSidecarOptions() *SidecarOptions {
return &SidecarOptions{driverAddress: defaultDriverAddress}
}

// Run starts the sidecar with the configured options
func (so *SidecarOptions) Run() {
klog.V(1).Infof("attempting to open a gRPC connection with: %q", so.driverAddress)
grpcClient, err := grpcclient.NewGRPCClient(so.driverAddress, []grpc.DialOption{}, nil)
if err != nil {
klog.Errorf("error creating GRPC Client: %v", err)
os.Exit(1)
}

grpcConn, err := grpcClient.ConnectWithLogging(connectionLoggingInterval)
if err != nil {
klog.Errorf("error connecting to COSI driver: %v", err)
os.Exit(1)
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

klog.V(1).Infof("creating provisioner client")
provisionerClient := osspec.NewProvisionerClient(grpcConn)

klog.Infof("discovering driver name")
req := osspec.ProvisionerGetInfoRequest{}
rsp, err := provisionerClient.ProvisionerGetInfo(ctx, &req)
if err != nil {
klog.Errorf("error calling ProvisionerGetInfo: %v", err)
os.Exit(1)
}

provisionerName := rsp.Name
// TODO: Register provisioner using internal type
klog.Info("This sidecar is working with the driver identified as: ", provisionerName)

so.startControllers(ctx, provisionerName, provisionerClient)
<-ctx.Done()
}

func (so *SidecarOptions) startControllers(ctx context.Context, name string, client osspec.ProvisionerClient) {
bucketController, err := bucket.NewBucketController(name, client)
if err != nil {
klog.Fatalf("Error creating bucket controller: %v", err)
}

bucketAccessController, err := bucketaccess.NewBucketAccessController(name, client)
if err != nil {
klog.Fatalf("Error creating bucket access controller: %v", err)
}

go bucketController.Run(ctx)
go bucketAccessController.Run(ctx)
}

// NewControllerManagerCommand creates a *cobra.Command object with default parameters
func NewControllerManagerCommand() *cobra.Command {
opts := NewSidecarOptions()

cmd := &cobra.Command{
Use: "objectstorage-sidecar",
DisableFlagsInUseLine: true,
Short: "",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
opts.Run()
},
}

cmd.Flags().StringVarP(&opts.driverAddress, "connect-address", "c", opts.driverAddress, "The address that the sidecar should connect to")

return cmd
}
30 changes: 30 additions & 0 deletions cmd/objectstorage-sidecar/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
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 (
"os"

"github.com/kubernetes-sigs/container-object-storage-interface-provisioner-sidecar/cmd/objectstorage-sidecar/app"
)

func main() {
command := app.NewControllerManagerCommand()
if err := command.Execute(); err != nil {
os.Exit(1)
}
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/kubernetes-csi/csi-lib-utils v0.9.0
github.com/kubernetes-sigs/container-object-storage-interface-api v0.0.0-20201217233824-6b4158ff7e28
github.com/kubernetes-sigs/container-object-storage-interface-spec v0.0.0-20201217184109-8cbf84dde8d3
github.com/spf13/cobra v0.0.5
golang.org/x/net v0.0.0-20200707034311-ab3426394381
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
google.golang.org/grpc v1.34.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
Expand Down Expand Up @@ -342,6 +343,7 @@ github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTd
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/bucket/bucket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewBucketController(provisionerName string, client osspec.ProvisionerClient
&workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(10), 100)},
)

identity := fmt.Sprintf("object-storage-sidecar-%s", provisionerName)
identity := fmt.Sprintf("objectstorage-sidecar-%s", provisionerName)
bc, err := controller.NewObjectStorageController(identity, "bucket-controller", 5, rateLimit)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/bucketaccess/bucket_access_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewBucketAccessController(provisionerName string, client osspec.Provisioner
&workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(10), 100)},
)

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