Skip to content

Commit

Permalink
add support for multiple cosi drivers in k8s cluster
Browse files Browse the repository at this point in the history
Fixes: #27

Signed-off-by: Jiffin Tony Thottan <[email protected]>
  • Loading branch information
thotz committed Feb 21, 2024
1 parent e1f4ab2 commit bc1b7fc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
12 changes: 8 additions & 4 deletions cmd/ceph-cosi-driver/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"context"
"flag"
"os"
"strings"

"github.com/ceph/cosi-driver-ceph/pkg/driver"
Expand All @@ -34,9 +35,7 @@ const provisionerName = "ceph.objectstorage.k8s.io"

var (
driverAddress = "unix:///var/lib/cosi/cosi.sock"
AccessKey = ""
SecretKey = ""
Endpoint = ""
driverPrefix = ""
)

var cmd = &cobra.Command{
Expand Down Expand Up @@ -78,7 +77,12 @@ func init() {
}

func run(ctx context.Context, args []string) error {
identityServer, bucketProvisioner, err := driver.NewDriver(ctx, provisionerName)
driverPrefix := os.Getenv("DRIVER_PREFIX")
if driverPrefix == "" {
driverPrefix = os.Getenv("POD_NAMESPACE")
}
driverName := driverPrefix + "." + provisionerName
identityServer, bucketProvisioner, err := driver.NewDriver(ctx, driverName)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
cosispec "sigs.k8s.io/container-object-storage-interface-spec"
)

func NewDriver(ctx context.Context, provisionerName string) (cosispec.IdentityServer, cosispec.ProvisionerServer, error) {
provisionerServer, err := NewProvisionerServer(provisionerName)
func NewDriver(ctx context.Context, driverName string) (cosispec.IdentityServer, cosispec.ProvisionerServer, error) {
provisionerServer, err := NewProvisionerServer(driverName)
if err != nil {
klog.Fatal(err, "failed to create provisioner server")
return nil, nil, err
}
identityServer, err := NewIdentityServer(provisionerName)
identityServer, err := NewIdentityServer(driverName)
if err != nil {
klog.Fatal(err, "failed to create provisioner server")
return nil, nil, err
Expand Down
6 changes: 6 additions & 0 deletions resources/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ spec:
- name: ceph-cosi-driver
image: $(CEPH_IMAGE_ORG)/ceph-cosi-driver:$(CEPH_IMAGE_VERSION)
imagePullPolicy: IfNotPresent
envFrom:
- secretRef:
name: objectstorage-provisioner
volumeMounts:
- mountPath: /var/lib/cosi
name: socket
Expand All @@ -47,6 +50,9 @@ spec:
imagePullPolicy: IfNotPresent
args:
- "--v=5"
envFrom:
- secretRef:
name: objectstorage-provisioner
env:
- name: POD_NAMESPACE
valueFrom:
Expand Down
12 changes: 12 additions & 0 deletions resources/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Secret
metadata:
name: objectstorage-provisioner
labels:
app.kubernetes.io/part-of: container-object-storage-interface
app.kubernetes.io/component: driver-ceph
app.kubernetes.io/version: main
app.kubernetes.io/name: cosi-driver-ceph
type: Opaque
#stringData:
# DRIVER_PREFIX: ""

0 comments on commit bc1b7fc

Please sign in to comment.