Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for multiple cosi drivers in k8s cluster #32

Merged
merged 1 commit into from
Mar 11, 2024
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ An example for awscli pods can be found at `examples/awscliapppod.yaml`. Credent

1. Handle access policies for Bucket Access Request

## Configuration Options

| Option | Default value | Description |
| ------------------------- | -------------------------------------- | -------------------------------------------------------------------|
| `--driver-address` | `unix:///var/lib/cosi/cosi.sock` | COSI driver address, must be a UNIX socket |
| `--driver-prefix` | _empty_ | prefix added before name, e.g, `<prefix>.ceph.objectstorage.k8s.io`|

## Integration with Rook

The ceph cosi driver integrates with [Rook](https://rook.io/) from v1.12 onwards to provide object storage for Kubernetes applications. More details can be found [here](https://rook.io/docs/rook/v1.12/Storage-Configuration/Object-Storage-RGW/cosi/).
Expand Down
61 changes: 15 additions & 46 deletions cmd/ceph-cosi-driver/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ package main

import (
"context"
"errors"
"flag"
"strings"

"github.com/ceph/cosi-driver-ceph/pkg/driver"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"k8s.io/klog/v2"

"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/provisioner"
Expand All @@ -33,57 +30,29 @@ import (
const provisionerName = "ceph.objectstorage.k8s.io"

var (
driverAddress = "unix:///var/lib/cosi/cosi.sock"
AccessKey = ""
SecretKey = ""
Endpoint = ""
driverAddress = flag.String("driver-address", "unix:///var/lib/cosi/cosi.sock", "driver address for socket")
driverPrefix = flag.String("driver-prefix", "", "prefix for cosi driver, e.g. <prefix>.ceph.objectstorage.k8s.io")
)

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

func init() {
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))

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())
cmd.PersistentFlags().VisitAll(func(f *pflag.Flag) {
if viper.IsSet(f.Name) && viper.GetString(f.Name) != "" {
cmd.PersistentFlags().Set(f.Name, viper.GetString(f.Name))
}
})
klog.InitFlags(nil)
if err := flag.Set("logtostderr", "true"); err != nil {
klog.Exitf("failed to set logtostderr flag: %v", err)
}
flag.Parse()
}

func run(ctx context.Context, args []string) error {
identityServer, bucketProvisioner, err := driver.NewDriver(ctx, provisionerName)
func run(ctx context.Context) error {
if *driverPrefix == "" {
return errors.New("driver prefix is missing for ceph cosi driver deployment")
}
driverName := *driverPrefix + "." + provisionerName
identityServer, bucketProvisioner, err := driver.NewDriver(ctx, driverName)
if err != nil {
return err
}

server, err := provisioner.NewDefaultCOSIProvisionerServer(driverAddress,
server, err := provisioner.NewDefaultCOSIProvisionerServer(*driverAddress,
identityServer,
bucketProvisioner)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/ceph-cosi-driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func main() {
os.Exit(1)
}()

if err := cmd.ExecuteContext(ctx); err != nil {
if err := run(ctx); err != nil {
klog.ErrorS(err, "Exiting on error")
}
}
4 changes: 2 additions & 2 deletions examples/bucketaccessclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ kind: BucketAccessClass
apiVersion: objectstorage.k8s.io/v1alpha1
metadata:
name: sample-bac
driverName: ceph.objectstorage.k8s.io
driverName: cosi.ceph.objectstorage.k8s.io
authenticationType: KEY
parameters:
objectStoreUserSecretName: rook-ceph-object-user-my-store-my-user
objectStoreUserSecretName: rook-ceph-object-user-my-store-cosi
objectStoreUserSecretNamespace: rook-ceph
4 changes: 2 additions & 2 deletions examples/bucketclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ kind: BucketClass
apiVersion: objectstorage.k8s.io/v1alpha1
metadata:
name: sample-bcc
driverName: ceph.objectstorage.k8s.io
driverName: cosi.ceph.objectstorage.k8s.io
deletionPolicy: Delete
parameters:
objectStoreUserSecretName: rook-ceph-object-user-my-store-my-user
objectStoreUserSecretName: rook-ceph-object-user-my-store-cosi
objectStoreUserSecretNamespace: rook-ceph
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
12 changes: 7 additions & 5 deletions resources/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,21 @@ spec:
- name: ceph-cosi-driver
image: $(CEPH_IMAGE_ORG)/ceph-cosi-driver:$(CEPH_IMAGE_VERSION)
imagePullPolicy: IfNotPresent
args:
- "--driver-prefix=cosi"
volumeMounts:
- mountPath: /var/lib/cosi
name: socket
- name: objectstorage-provisioner-sidecar
image: gcr.io/k8s-staging-sig-storage/objectstorage-sidecar/objectstorage-sidecar:v20221117-v0.1.0-22-g0e67387
imagePullPolicy: IfNotPresent
args:
- "--v=5"
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: objectstorage-provisioner-sidecar
image: gcr.io/k8s-staging-sig-storage/objectstorage-sidecar/objectstorage-sidecar:v20221117-v0.1.0-22-g0e67387
imagePullPolicy: IfNotPresent
args:
- "--v=5"
volumeMounts:
- mountPath: /var/lib/cosi
name: socket
Loading