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

Commit 166514d

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 166514d

26 files changed

+1511
-2573
lines changed

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

cmd/objectstorage-sidecar/app/objectstorage-sidecar.go

-109
This file was deleted.

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+
}

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
}

go.mod

+17-10
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,27 @@ module sigs.k8s.io/container-object-storage-interface-provisioner-sidecar
33
go 1.15
44

55
require (
6-
github.com/go-ini/ini v1.62.0 // indirect
7-
github.com/kubernetes-csi/csi-lib-utils v0.9.0
8-
github.com/minio/minio v0.0.0-20210112204746-e09196d62633
9-
github.com/minio/minio-go v6.0.14+incompatible
6+
github.com/google/go-cmp v0.5.2 // indirect
7+
github.com/kr/text v0.2.0 // indirect
8+
github.com/mailru/easyjson v0.7.6 // indirect
9+
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
1010
github.com/pkg/errors v0.9.1
11-
github.com/spf13/cobra v0.0.5
12-
github.com/spf13/viper v1.3.2
13-
golang.org/x/net v0.0.0-20201216054612-986b41b23924
14-
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
11+
github.com/smartystreets/assertions v1.1.1 // indirect
12+
github.com/spf13/cobra v1.1.3
13+
github.com/spf13/viper v1.7.0
14+
github.com/stretchr/testify v1.6.1 // indirect
15+
golang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392 // indirect
16+
golang.org/x/net v0.0.0-20201216054612-986b41b23924 // indirect
17+
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
18+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
1519
google.golang.org/grpc v1.35.0
20+
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
21+
gopkg.in/ini.v1 v1.57.0 // indirect
22+
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
1623
k8s.io/api v0.19.4
1724
k8s.io/apimachinery v0.19.4
1825
k8s.io/client-go v0.19.4
1926
k8s.io/klog/v2 v2.2.0
20-
sigs.k8s.io/container-object-storage-interface-api v0.0.0-20210308183412-eb167f7cca3c
21-
sigs.k8s.io/container-object-storage-interface-spec v0.0.0-20210224211525-dfa3af562c18
27+
sigs.k8s.io/container-object-storage-interface-api v0.0.0-20210330175159-2cdabb1a5dc7
28+
sigs.k8s.io/container-object-storage-interface-spec v0.0.0-20210330184956-b0de747ccee4
2229
)

0 commit comments

Comments
 (0)