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 bucketLookup support #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM golang:1.16-alpine as gobuild
ARG ALPINE_VERSION="3.17"
ARG GOLANG_VERSION="1.20"
FROM docker.io/library/golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} as gobuild

WORKDIR /build
ADD go.mod go.sum /build/
Expand All @@ -8,7 +10,7 @@ ADD pkg /build/pkg
RUN go get -d -v ./...
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o ./s3driver ./cmd/s3driver

FROM alpine:3.16
FROM docker.io/library/alpine:${ALPINE_VERSION}
LABEL maintainers="Vitaliy Filippov <[email protected]>"
LABEL description="csi-s3 slim image"

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ stringData:
endpoint: https://storage.yandexcloud.net
# For AWS set it to AWS region
#region: ""
# For S3-compatible set it to bucket lookup style (choices: Auto [default], DNS, Path)
#bucketLookup: ""
```

The region can be empty if you are using some other S3 compatible storage.
Expand Down
2 changes: 2 additions & 0 deletions deploy/helm/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ stringData:
accessKeyID: {{ .Values.secret.accessKey }}
secretAccessKey: {{ .Values.secret.secretKey }}
endpoint: {{ .Values.secret.endpoint }}
region: {{ .Values.secret.region }}
bucketLookup: {{ .Values.secret.bucketLookup }}
{{- end -}}
4 changes: 4 additions & 0 deletions deploy/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ secret:
secretKey: ""
# Endpoint
endpoint: https://storage.yandexcloud.net
# For AWS set it to AWS region
region: ""
# For S3-compatible set it to bucket lookup style (choices: Auto [default], DNS, Path)
bucketLookup: Auto

tolerations:
all: false
Expand Down
2 changes: 2 additions & 0 deletions deploy/kubernetes/examples/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ stringData:
endpoint: https://storage.yandexcloud.net
# For AWS set it to AWS region
#region: ""
# For S3-compatible set it to bucket lookup style (choices: Auto [default], DNS, Path)
#bucketLookup: ""
12 changes: 5 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@ go 1.15

require (
github.com/container-storage-interface/spec v1.1.0
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/godbus/dbus/v5 v5.0.4 // indirect
github.com/coreos/go-systemd/v22 v22.5.0
github.com/godbus/dbus/v5 v5.0.4
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/protobuf v1.1.0 // indirect
github.com/kubernetes-csi/csi-lib-utils v0.6.1 // indirect
github.com/kubernetes-csi/csi-test v2.0.0+incompatible
github.com/kubernetes-csi/drivers v1.0.2
github.com/minio/minio-go/v7 v7.0.5
github.com/minio/minio-go/v7 v7.0.49
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936
github.com/onsi/ginkgo v1.5.0
github.com/onsi/gomega v1.4.0
github.com/spf13/afero v1.2.1 // indirect
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
golang.org/x/net v0.0.0-20200707034311-ab3426394381
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 // indirect
golang.org/x/sys v0.0.0-20200922070232-aee5d888a860 // indirect
golang.org/x/net v0.7.0
google.golang.org/genproto v0.0.0-20180716172848-2731d4fa720b // indirect
google.golang.org/grpc v1.13.0
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apimachinery v0.0.0-20180714051327-705cfa51a97f // indirect
k8s.io/klog v0.2.0 // indirect
k8s.io/kubernetes v1.13.4
Expand Down
125 changes: 63 additions & 62 deletions go.sum

Large diffs are not rendered by default.

28 changes: 25 additions & 3 deletions pkg/s3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Config struct {
Region string
Endpoint string
Mounter string
BucketLookup string
}

type FSMeta struct {
Expand All @@ -41,6 +42,11 @@ type FSMeta struct {
func NewClient(cfg *Config) (*s3Client, error) {
var client = &s3Client{}

bucketLookup, err := ParseBucketLookup(cfg.BucketLookup)
if err != nil {
return nil, err
}

client.Config = cfg
u, err := url.Parse(client.Config.Endpoint)
if err != nil {
Expand All @@ -52,8 +58,10 @@ func NewClient(cfg *Config) (*s3Client, error) {
endpoint = u.Hostname() + ":" + u.Port()
}
minioClient, err := minio.New(endpoint, &minio.Options{
Creds: credentials.NewStaticV4(client.Config.AccessKeyID, client.Config.SecretAccessKey, client.Config.Region),
Secure: ssl,
Creds: credentials.NewStaticV4(client.Config.AccessKeyID, client.Config.SecretAccessKey, ""),
Secure: ssl,
Region: client.Config.Region,
BucketLookup: bucketLookup,
})
if err != nil {
return nil, err
Expand All @@ -70,7 +78,8 @@ func NewClientFromSecret(secret map[string]string) (*s3Client, error) {
Region: secret["region"],
Endpoint: secret["endpoint"],
// Mounter is set in the volume preferences, not secrets
Mounter: "",
Mounter: "",
BucketLookup: secret["bucketLookup"],
})
}

Expand Down Expand Up @@ -220,3 +229,16 @@ func (client *s3Client) removeObjectsOneByOne(bucketName, prefix string) error {

return nil
}

func ParseBucketLookup(bucketLookup string) (minio.BucketLookupType, error) {
switch bucketLookup {
case "", "Auto":
return minio.BucketLookupAuto, nil
case "DNS":
return minio.BucketLookupDNS, nil
case "Path":
return minio.BucketLookupPath, nil
default:
return -1, fmt.Errorf("failed to parse BucketLookup: %s", bucketLookup)
}
}