Skip to content

Commit 1e86a65

Browse files
committed
Major refactor and bugfixes
- Requires changes to API from this PR github.com/kubernetes-retired/container-object-storage-interface-api/pull/35 - Requires changes to API from this PR github.com/kubernetes-retired/container-object-storage-interface-spec/pull/25
1 parent 88931d8 commit 1e86a65

35 files changed

+1617
-2902
lines changed

Diff for: cmd/objectstorage-sidecar/Dockerfile renamed to Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM gcr.io/distroless/static:latest
2-
LABEL maintainers="Kubernetes Authors"
2+
LABEL maintainers="Kubernetes COSI Authors"
33
LABEL description="Object Storage Sidecar"
44

55
COPY ./bin/objectstorage-sidecar objectstorage-sidecar

Diff for: Dockerfile.sample-driver

-6
This file was deleted.

Diff for: Makefile

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

15-
CMDS=objectstorage-sidecar sample-driver
15+
CMDS=objectstorage-sidecar minio-cosi-driver
1616

1717
all: reltools build
1818
.PHONY: reltools

Diff for: cmd/minio-cosi-driver/cmd.go

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2021 The Kubernetes Authors.
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// You may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package main
15+
16+
import (
17+
"context"
18+
"flag"
19+
20+
"github.com/spf13/cobra"
21+
"github.com/spf13/viper"
22+
23+
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/provisioner"
24+
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/sampledriver"
25+
26+
"k8s.io/klog/v2"
27+
)
28+
29+
const provisionerName = "minio.objectstorage.k8s.io"
30+
31+
var (
32+
driverAddress = "unix:///var/lib/cosi/cosi.sock"
33+
)
34+
35+
var cmd = &cobra.Command{
36+
Use: "minio-cosi-driver",
37+
Short: "K8s COSI driver for MinIO object storage",
38+
SilenceErrors: true,
39+
SilenceUsage: true,
40+
RunE: func(cmd *cobra.Command, args []string) error {
41+
return run(cmd.Context(), args)
42+
},
43+
DisableFlagsInUseLine: true,
44+
}
45+
46+
func init() {
47+
viper.AutomaticEnv()
48+
49+
flag.Set("alsologtostderr", "true")
50+
kflags := flag.NewFlagSet("klog", flag.ExitOnError)
51+
klog.InitFlags(kflags)
52+
53+
persistentFlags := cmd.PersistentFlags()
54+
persistentFlags.AddGoFlagSet(kflags)
55+
56+
stringFlag := persistentFlags.StringVarP
57+
stringFlag(&driverAddress,
58+
"driver-addr",
59+
"d",
60+
driverAddress,
61+
"path to unix domain socket where driver should listen")
62+
63+
viper.BindPFlags(cmd.PersistentFlags())
64+
}
65+
66+
func run(ctx context.Context, args []string) error {
67+
identityServer, bucketProvisioner := sampledriver.NewDriver(provisionerName)
68+
server, err := provisioner.NewDefaultCOSIProvisionerServer(driverAddress, identityServer, bucketProvisioner)
69+
if err != nil {
70+
return err
71+
}
72+
return server.Run(ctx)
73+
}

Diff for: cmd/minio-cosi-driver/main.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2021 The Kubernetes Authors.
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// You may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package main
15+
16+
import (
17+
"context"
18+
"os"
19+
"os/signal"
20+
"syscall"
21+
"time"
22+
23+
"k8s.io/klog/v2"
24+
)
25+
26+
func main() {
27+
ctx, cancel := context.WithCancel(context.Background())
28+
defer cancel()
29+
30+
sigs := make(chan os.Signal, 1)
31+
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
32+
33+
go func() {
34+
sig := <-sigs
35+
klog.InfoS("Signal received", "type", sig)
36+
cancel()
37+
<-time.After(30 * time.Second)
38+
os.Exit(1)
39+
}()
40+
41+
if err := cmd.ExecuteContext(ctx); err != nil {
42+
klog.ErrorS(err, "Exiting on error")
43+
}
44+
}

Diff for: cmd/objectstorage-sidecar/app/objectstorage-sidecar.go

-109
This file was deleted.

Diff for: cmd/objectstorage-sidecar/cmd.go

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/* Copyright 2021 The Kubernetes Authors.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package main
17+
18+
import (
19+
"context"
20+
"flag"
21+
22+
"sigs.k8s.io/container-object-storage-interface-api/controller"
23+
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/bucket"
24+
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/bucketaccess"
25+
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/provisioner"
26+
27+
"github.com/spf13/cobra"
28+
"github.com/spf13/viper"
29+
30+
"k8s.io/klog/v2"
31+
)
32+
33+
const DefaultProvisionerName = "provisioner.objectstorage.k8s.io"
34+
35+
var (
36+
driverAddress = "unix:///var/lib/cosi/cosi.sock"
37+
provisionerName = ""
38+
kubeconfig = ""
39+
debug = false
40+
)
41+
42+
var cmd = &cobra.Command{
43+
Use: "objectstorage-sidecar",
44+
Short: "provisioner that interacts with cosi drivers to manage buckets and bucketAccesses",
45+
SilenceErrors: true,
46+
SilenceUsage: true,
47+
RunE: func(cmd *cobra.Command, args []string) error {
48+
return run(cmd.Context(), args)
49+
},
50+
DisableFlagsInUseLine: true,
51+
}
52+
53+
func init() {
54+
viper.AutomaticEnv()
55+
56+
flag.Set("alsologtostderr", "true")
57+
kflags := flag.NewFlagSet("klog", flag.ExitOnError)
58+
klog.InitFlags(kflags)
59+
60+
persistentFlags := cmd.PersistentFlags()
61+
persistentFlags.AddGoFlagSet(kflags)
62+
63+
stringFlag := persistentFlags.StringVarP
64+
boolFlag := persistentFlags.BoolVarP
65+
66+
stringFlag(&kubeconfig, "kubeconfig", "", kubeconfig, "path to kubeconfig file")
67+
stringFlag(&driverAddress, "driver-addr", "d", driverAddress, "path to unix domain socket where driver is listening")
68+
stringFlag(&provisionerName, "provisioner", "p", DefaultProvisionerName, "The name of the provisioner")
69+
70+
boolFlag(&debug, "debug", "g", debug, "Logs all grpc requests and responses")
71+
72+
viper.BindPFlags(cmd.PersistentFlags())
73+
}
74+
75+
func run(ctx context.Context, args []string) error {
76+
if provisionerName == "" {
77+
provisionerName = DefaultProvisionerName
78+
}
79+
80+
ctrl, err := controller.NewDefaultObjectStorageController("cosi", provisionerName, 40)
81+
if err != nil {
82+
return err
83+
}
84+
85+
klog.V(3).InfoS("Attempting connection to driver", "address", driverAddress)
86+
cosiClient, err := provisioner.NewDefaultCOSIProvisionerClient(ctx, driverAddress, debug)
87+
if err != nil {
88+
return err
89+
}
90+
klog.V(3).InfoS("Successfully connected to driver")
91+
92+
ctrl.AddBucketListener(bucket.NewBucketListener(provisionerName, cosiClient))
93+
94+
bal, err := bucketaccess.NewBucketAccessListener(provisionerName, cosiClient)
95+
if err != nil {
96+
return err
97+
}
98+
ctrl.AddBucketAccessListener(bal)
99+
100+
return ctrl.Run(ctx)
101+
}

0 commit comments

Comments
 (0)