Repository navigation
feat(db): introduce new seaweedfs object store usage for e2e #79
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
Merged
saswatamcode
merged 1 commit into
efficientgo:main
from
Saumya40-codes:introduce-seaweedfs-s3-storage
Sep 27, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,13 +6,16 @@ | |
| package e2edb | ||
|
|
||
| import ( | ||
| "context" | ||
| "crypto/rand" | ||
| "crypto/rsa" | ||
| "crypto/tls" | ||
| "crypto/x509" | ||
| "encoding/pem" | ||
| "fmt" | ||
| "math/big" | ||
| "net" | ||
| "net/http" | ||
| "os" | ||
| "path/filepath" | ||
| "strconv" | ||
|
|
@@ -23,11 +26,13 @@ import ( | |
| "github.com/efficientgo/e2e" | ||
| e2emon "github.com/efficientgo/e2e/monitoring" | ||
| e2eprof "github.com/efficientgo/e2e/profiling" | ||
| "github.com/minio/minio-go/v7" | ||
| "github.com/minio/minio-go/v7/pkg/credentials" | ||
| ) | ||
|
|
||
| const ( | ||
| MinioAccessKey = "Cheescake" | ||
| MinioSecretKey = "supersecret" | ||
| S3AccessKey = "Cheescake" | ||
| S3SecretKey = "supersecret" | ||
| ) | ||
|
|
||
| type Option func(*options) | ||
|
|
@@ -36,6 +41,7 @@ type options struct { | |
| image string | ||
| flagOverride map[string]string | ||
| minioOptions minioOptions | ||
| seaweedOptions seaweedFSOptions | ||
| azuriteOptions azuriteOptions | ||
| } | ||
|
|
||
|
|
@@ -50,6 +56,11 @@ type minioOptions struct { | |
| enableTLS bool | ||
| } | ||
|
|
||
| type seaweedFSOptions struct { | ||
| enableTLS bool | ||
| enableIceberg bool | ||
| } | ||
|
|
||
| func WithImage(image string) Option { | ||
| return func(o *options) { | ||
| o.image = image | ||
|
|
@@ -74,6 +85,18 @@ func WithMinioTLS() Option { | |
| } | ||
| } | ||
|
|
||
| func WithSeaweedFSTLS() Option { | ||
| return func(o *options) { | ||
| o.seaweedOptions.enableTLS = true | ||
| } | ||
| } | ||
|
|
||
| func WithSeaweedFSIceberg() Option { | ||
| return func(o *options) { | ||
| o.seaweedOptions.enableIceberg = true | ||
| } | ||
| } | ||
|
|
||
| func WithAzuriteStorageAccounts(acc string) Option { | ||
| return func(o *options) { | ||
| o.azuriteOptions.customStorageAccounts = acc | ||
|
|
@@ -116,8 +139,8 @@ func NewMinio(env e2e.Environment, name, bktName string, opts ...Option) *e2emon | |
| userID := strconv.Itoa(os.Getuid()) | ||
| ports := map[string]int{AccessPortName: 8090} | ||
| envVars := []string{ | ||
| "MINIO_ROOT_USER=" + MinioAccessKey, | ||
| "MINIO_ROOT_PASSWORD=" + MinioSecretKey, | ||
| "MINIO_ROOT_USER=" + S3AccessKey, | ||
| "MINIO_ROOT_PASSWORD=" + S3SecretKey, | ||
| "MINIO_BROWSER=" + "off", | ||
| } | ||
|
|
||
|
|
@@ -473,3 +496,135 @@ func NewETCD(env e2e.Environment, name string, opts ...Option) *e2emon.Instrumen | |
| }, | ||
| ), "metrics") | ||
| } | ||
|
|
||
| func NewSeaweedFS(env e2e.Environment, name, bucket string, opts ...Option) *e2emon.InstrumentedRunnable { | ||
| o := options{image: "chrislusf/seaweedfs:4.47"} | ||
| for _, opt := range opts { | ||
| opt(&o) | ||
| } | ||
|
|
||
| const ( | ||
| adminPortName = "admin" | ||
| icebergPortName = "iceberg" | ||
| seaweedFSIcebergPort = 8181 | ||
| ) | ||
| ports := map[string]int{ | ||
| AccessPortName: 8333, | ||
| adminPortName: 23646, | ||
| } | ||
| icebergPort := 0 | ||
| if o.seaweedOptions.enableIceberg { | ||
| icebergPort = seaweedFSIcebergPort | ||
| ports[icebergPortName] = seaweedFSIcebergPort | ||
| } | ||
| f := env.Runnable(name).WithPorts(ports).Future() | ||
| dataDir := filepath.Join(f.Dir(), "data") | ||
| if err := os.MkdirAll(dataDir, 0750); err != nil { | ||
| return &e2emon.InstrumentedRunnable{Runnable: e2e.NewFailedRunnable(name, errors.Wrap(err, "create SeaweedFS data directory"))} | ||
| } | ||
|
|
||
| args := []string{ | ||
| "mini", | ||
| "-dir=/data", | ||
| fmt.Sprintf("-s3.port=%d", ports[AccessPortName]), | ||
| "-master.telemetry=false", | ||
| "-webdav=false", | ||
| fmt.Sprintf("-s3.port.iceberg=%d", icebergPort), | ||
| "-s3.port.lance=0", | ||
| "-s3.autoCreateBucket=false", | ||
| } | ||
| readiness := e2e.ReadinessProbe(e2e.NewHTTPReadinessProbe(AccessPortName, "/readyz", http.StatusOK, http.StatusOK)) | ||
| instrumentedOpts := []e2emon.InstrumentedOption{} | ||
| caFile := "" | ||
|
|
||
| if o.seaweedOptions.enableTLS { | ||
| certDir := filepath.Join(f.Dir(), "certs") | ||
| caDir := filepath.Join(certDir, "CAs") | ||
| if err := os.MkdirAll(caDir, 0750); err != nil { | ||
| return &e2emon.InstrumentedRunnable{Runnable: e2e.NewFailedRunnable(name, errors.Wrap(err, "create SeaweedFS certificate directory"))} | ||
| } | ||
|
|
||
| certFile := filepath.Join(certDir, "public.crt") | ||
| keyFile := filepath.Join(certDir, "private.key") | ||
| caFile = filepath.Join(caDir, "ca.crt") | ||
| if err := genCerts(certFile, keyFile, caFile, fmt.Sprintf("%s-%s", env.Name(), name)); err != nil { | ||
| return &e2emon.InstrumentedRunnable{Runnable: e2e.NewFailedRunnable(name, errors.Wrap(err, "generate SeaweedFS certificates"))} | ||
| } | ||
|
|
||
| args = append(args, "-s3.cert.file="+certFile, "-s3.key.file="+keyFile) | ||
| readiness = e2e.NewHTTPSReadinessProbe(AccessPortName, "/readyz", http.StatusOK, http.StatusOK) | ||
| instrumentedOpts = append(instrumentedOpts, e2emon.WithInstrumentedScheme("https")) | ||
| } | ||
|
|
||
| envVars := map[string]string{ | ||
| "AWS_ACCESS_KEY_ID": S3AccessKey, | ||
| "AWS_SECRET_ACCESS_KEY": S3SecretKey, | ||
| } | ||
| if bucket != "" { | ||
| envVars["S3_BUCKET"] = bucket | ||
| readiness = &seaweedFSBucketReadinessProbe{ | ||
| readiness: readiness, | ||
| bucket: bucket, | ||
| enableTLS: o.seaweedOptions.enableTLS, | ||
| caFile: caFile, | ||
| } | ||
| } | ||
|
|
||
| r := f.Init(e2e.StartOptions{ | ||
| Image: o.image, | ||
| User: strconv.Itoa(os.Getuid()), | ||
| Command: e2e.NewCommand(args[0], args[1:]...), | ||
| EnvVars: envVars, | ||
| Readiness: readiness, | ||
| Volumes: []string{dataDir + ":/data:z"}, | ||
| }) | ||
| return e2emon.AsInstrumented(r, AccessPortName, instrumentedOpts...) | ||
| } | ||
|
|
||
| type seaweedFSBucketReadinessProbe struct { | ||
| readiness e2e.ReadinessProbe | ||
| bucket string | ||
| enableTLS bool | ||
| caFile string | ||
| } | ||
|
|
||
| // This explicitly checks if bucket exists or not (seaweedfs s3 gateway server might report healthy while bucket creation is still pending, which happens in later stage). | ||
| func (p *seaweedFSBucketReadinessProbe) Ready(runnable e2e.Runnable) error { | ||
| if err := p.readiness.Ready(runnable); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| transport := http.DefaultTransport.(*http.Transport).Clone() | ||
| defer transport.CloseIdleConnections() | ||
| if p.enableTLS { | ||
| caPEM, err := os.ReadFile(p.caFile) | ||
| if err != nil { | ||
| return errors.Wrap(err, "read SeaweedFS CA certificate") | ||
| } | ||
| rootCAs := x509.NewCertPool() | ||
| if !rootCAs.AppendCertsFromPEM(caPEM) { | ||
| return errors.New("parse SeaweedFS CA certificate") | ||
| } | ||
| transport.TLSClientConfig = &tls.Config{RootCAs: rootCAs} | ||
| } | ||
|
|
||
| client, err := minio.New(runnable.Endpoint(AccessPortName), &minio.Options{ | ||
| Creds: credentials.NewStaticV4(S3AccessKey, S3SecretKey, ""), | ||
| Secure: p.enableTLS, | ||
| Transport: transport, | ||
| }) | ||
| if err != nil { | ||
| return errors.Wrap(err, "create SeaweedFS readiness client") | ||
| } | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||
| defer cancel() | ||
| exists, err := client.BucketExists(ctx, p.bucket) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I think here another viable way could've been hitting |
||
| if err != nil { | ||
| return errors.Wrap(err, "check SeaweedFS bucket") | ||
| } | ||
| if !exists { | ||
| return errors.Newf("SeaweedFS bucket %q does not exist", p.bucket) | ||
| } | ||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the official image for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. https://github.com/seaweedfs/seaweedfs#docker