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

Major refactor and bugfixes #49

Merged
merged 1 commit into from
Apr 6, 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
2 changes: 1 addition & 1 deletion cmd/objectstorage-sidecar/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM gcr.io/distroless/static:latest
LABEL maintainers="Kubernetes Authors"
LABEL maintainers="Kubernetes COSI Authors"
LABEL description="Object Storage Sidecar"

COPY ./bin/objectstorage-sidecar objectstorage-sidecar
Expand Down
6 changes: 0 additions & 6 deletions Dockerfile.sample-driver

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

CMDS=objectstorage-sidecar sample-driver
CMDS=objectstorage-sidecar minio-cosi-driver

all: reltools build
.PHONY: reltools
Expand Down
73 changes: 73 additions & 0 deletions cmd/minio-cosi-driver/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2021 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 (
"context"
"flag"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/provisioner"
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/sampledriver"

"k8s.io/klog/v2"
)

const provisionerName = "minio.objectstorage.k8s.io"

var (
driverAddress = "unix:///var/lib/cosi/cosi.sock"
)

var cmd = &cobra.Command{
Use: "minio-cosi-driver",
Short: "K8s COSI driver for MinIO object storage",
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return run(cmd.Context(), args)
},
DisableFlagsInUseLine: true,
}

func init() {
viper.AutomaticEnv()

flag.Set("alsologtostderr", "true")
kflags := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(kflags)

persistentFlags := cmd.PersistentFlags()
persistentFlags.AddGoFlagSet(kflags)

stringFlag := persistentFlags.StringVarP
stringFlag(&driverAddress,
"driver-addr",
"d",
driverAddress,
"path to unix domain socket where driver should listen")

viper.BindPFlags(cmd.PersistentFlags())
}

func run(ctx context.Context, args []string) error {
identityServer, bucketProvisioner := sampledriver.NewDriver(provisionerName)
server, err := provisioner.NewDefaultCOSIProvisionerServer(driverAddress, identityServer, bucketProvisioner)
if err != nil {
return err
}
return server.Run(ctx)
}
44 changes: 44 additions & 0 deletions cmd/minio-cosi-driver/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2021 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 (
"context"
"os"
"os/signal"
"syscall"
"time"

"k8s.io/klog/v2"
)

func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

go func() {
sig := <-sigs
klog.InfoS("Signal received", "type", sig)
cancel()
<-time.After(30 * time.Second)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this long of a pause needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a long pause. This is needed in case graceful shutdown doesn;t complete in 30 seconds.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main thread is expected to exit in these 30 seconds

os.Exit(1)
}()

if err := cmd.ExecuteContext(ctx); err != nil {
klog.ErrorS(err, "Exiting on error")
}
}
109 changes: 0 additions & 109 deletions cmd/objectstorage-sidecar/app/objectstorage-sidecar.go

This file was deleted.

101 changes: 101 additions & 0 deletions cmd/objectstorage-sidecar/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* Copyright 2021 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 (
"context"
"flag"

"sigs.k8s.io/container-object-storage-interface-api/controller"
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/bucket"
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/bucketaccess"
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/provisioner"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"k8s.io/klog/v2"
)

const DefaultProvisionerName = "provisioner.objectstorage.k8s.io"

var (
driverAddress = "unix:///var/lib/cosi/cosi.sock"
provisionerName = ""
kubeconfig = ""
debug = false
)

var cmd = &cobra.Command{
Use: "objectstorage-sidecar",
Short: "provisioner that interacts with cosi drivers to manage buckets and bucketAccesses",
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return run(cmd.Context(), args)
},
DisableFlagsInUseLine: true,
}

func init() {
viper.AutomaticEnv()

flag.Set("alsologtostderr", "true")
kflags := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(kflags)

persistentFlags := cmd.PersistentFlags()
persistentFlags.AddGoFlagSet(kflags)

stringFlag := persistentFlags.StringVarP
boolFlag := persistentFlags.BoolVarP

stringFlag(&kubeconfig, "kubeconfig", "", kubeconfig, "path to kubeconfig file")
stringFlag(&driverAddress, "driver-addr", "d", driverAddress, "path to unix domain socket where driver is listening")
stringFlag(&provisionerName, "provisioner", "p", DefaultProvisionerName, "The name of the provisioner")

boolFlag(&debug, "debug", "g", debug, "Logs all grpc requests and responses")

viper.BindPFlags(cmd.PersistentFlags())
}

func run(ctx context.Context, args []string) error {
if provisionerName == "" {
provisionerName = DefaultProvisionerName
}

ctrl, err := controller.NewDefaultObjectStorageController("cosi", provisionerName, 40)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we need to move identity and threads into command line flags?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identity is inferred from ProvisionerGetInfo, and thread count is not something that NEEDS to be configurable yet - it'll cause more confusion than any potential benefits

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good!

if err != nil {
return err
}

klog.V(3).InfoS("Attempting connection to driver", "address", driverAddress)
cosiClient, err := provisioner.NewDefaultCOSIProvisionerClient(ctx, driverAddress, debug)
if err != nil {
return err
}
klog.V(3).InfoS("Successfully connected to driver")

ctrl.AddBucketListener(bucket.NewBucketListener(provisionerName, cosiClient))

bal, err := bucketaccess.NewBucketAccessListener(provisionerName, cosiClient)
if err != nil {
return err
}
ctrl.AddBucketAccessListener(bal)

return ctrl.Run(ctx)
}
Loading