Skip to content

Commit 8cf8f3b

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 8cf8f3b

17 files changed

+890
-832
lines changed

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

-109
This file was deleted.

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

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
ctrl.AddBucketAccessListener(bucketaccess.NewBucketAccessListener(provisionerName, cosiClient))
94+
95+
return ctrl.Run(ctx)
96+
}

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

+34-18
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
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-
*/
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+
*/
1615

1716
package main
1817

1918
import (
19+
"context"
2020
"os"
21+
"os/signal"
22+
"syscall"
23+
"time"
2124

22-
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/cmd/objectstorage-sidecar/app"
25+
"k8s.io/klog/v2"
2326
)
2427

2528
func main() {
26-
command := app.NewControllerManagerCommand()
27-
if err := command.Execute(); err != nil {
29+
ctx, cancel := context.WithCancel(context.Background())
30+
defer cancel()
31+
32+
sigs := make(chan os.Signal, 1)
33+
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
34+
35+
go func() {
36+
sig := <-sigs
37+
klog.InfoS("Signal received", "type", sig)
38+
cancel()
39+
<-time.After(30 * time.Second)
2840
os.Exit(1)
41+
}()
42+
43+
if err := cmd.ExecuteContext(ctx); err != nil {
44+
klog.ErrorS(err, "Exiting on error")
2945
}
3046
}

Diff for: go.mod

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ require (
88
github.com/minio/minio v0.0.0-20210112204746-e09196d62633
99
github.com/minio/minio-go v6.0.14+incompatible
1010
github.com/pkg/errors v0.9.1
11-
github.com/spf13/cobra v0.0.5
12-
github.com/spf13/viper v1.3.2
11+
github.com/spf13/cobra v1.1.3
12+
github.com/spf13/viper v1.7.0
1313
golang.org/x/net v0.0.0-20201216054612-986b41b23924
1414
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
1515
google.golang.org/grpc v1.35.0
@@ -20,3 +20,8 @@ require (
2020
sigs.k8s.io/container-object-storage-interface-api v0.0.0-20210308183412-eb167f7cca3c
2121
sigs.k8s.io/container-object-storage-interface-spec v0.0.0-20210224211525-dfa3af562c18
2222
)
23+
24+
replace (
25+
sigs.k8s.io/container-object-storage-interface-api => ../container-object-storage-interface-api
26+
sigs.k8s.io/container-object-storage-interface-spec => ../container-object-storage-interface-spec
27+
)

0 commit comments

Comments
 (0)