Skip to content

Commit

Permalink
fix: align the startup check condition with storage conf fields. (#161)
Browse files Browse the repository at this point in the history
Signed-off-by: weston-shih <[email protected]>
  • Loading branch information
weston-shih authored Aug 15, 2024
1 parent 6fabd8a commit 42d2415
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
18 changes: 10 additions & 8 deletions pkg/controllers/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type StorageConditionInfo struct {
IAMEndpoint string
// StorageAccount of azure
StorageAccount string
UseVirtualHost bool
}

type checkMinIOFunc = func(args external.CheckMinIOArgs) error
Expand Down Expand Up @@ -148,14 +149,15 @@ func GetMinioCondition(ctx context.Context, logger logr.Logger, cli client.Clien
ak = info.StorageAccount
}
err := checkMinIO(external.CheckMinIOArgs{
Type: info.Storage.Type,
AK: ak,
SK: string(secretkey),
Endpoint: info.Storage.Endpoint,
Bucket: info.Bucket,
UseSSL: info.UseSSL,
UseIAM: info.UseIAM,
IAMEndpoint: info.IAMEndpoint,
Type: info.Storage.Type,
AK: ak,
SK: string(secretkey),
Endpoint: info.Storage.Endpoint,
Bucket: info.Bucket,
UseSSL: info.UseSSL,
UseIAM: info.UseIAM,
IAMEndpoint: info.IAMEndpoint,
UseVirtualHost: info.UseVirtualHost,
})
if err != nil {
return newErrStorageCondResult(v1beta1.ReasonClientErr, err.Error())
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/status_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ func (r *MilvusStatusSyncer) GetMinioCondition(
UseIAM: GetMinioUseIAM(mc.Spec.Conf.Data),
IAMEndpoint: GetMinioIAMEndpoint(mc.Spec.Conf.Data),
StorageAccount: GetAzureStorageAccount(mc.Spec.Conf.Data),
UseVirtualHost: GetVirtualHostCondition(mc.Spec.Conf.Data),
}
getter := wrapMinioConditionGetter(ctx, r.logger, r.Client, info)
return GetCondition(getter, []string{mc.Spec.Dep.Storage.Endpoint}), nil
Expand Down
10 changes: 10 additions & 0 deletions pkg/controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,16 @@ func GetMinioSecure(conf map[string]interface{}) bool {
return false
}

func GetVirtualHostCondition(conf map[string]interface{}) bool {
fields := []string{"minio", "useVirtualHost"}
useVirtualHost, exist := util.GetBoolValue(conf, fields...)
if exist {
return useVirtualHost
}

return false
}

func GetMinioBucket(conf map[string]interface{}) string {
return GetStringValueWithDefault(conf, defaultBucketName, "minio", "bucketName")
}
Expand Down
23 changes: 14 additions & 9 deletions pkg/external/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import (
// CheckMinIOArgs is info for acquiring storage condition
type CheckMinIOArgs struct {
// S3 / MinIO
Type string
AK string
SK string
Bucket string
Endpoint string
UseSSL bool
UseIAM bool
IAMEndpoint string
Type string
AK string
SK string
Bucket string
Endpoint string
UseSSL bool
UseIAM bool
IAMEndpoint string
UseVirtualHost bool
}

var DependencyCheckTimeout = 5 * time.Second
Expand All @@ -40,11 +41,15 @@ func CheckMinIO(args CheckMinIOArgs) error {
// minio client cannot recognize aws endpoints with :443
endpoint = strings.TrimSuffix(endpoint, ":443")
}
bucketLookup := minio.BucketLookupPath
if args.UseVirtualHost {
bucketLookup = minio.BucketLookupDNS
}
cli, err := minio.New(endpoint, &minio.Options{
// GetBucketLocation will succeed as long as the bucket exists
Creds: credentials.NewStaticV4(args.AK, args.SK, ""),
Secure: args.UseSSL,
BucketLookup: minio.BucketLookupDNS,
BucketLookup: bucketLookup,
})
if err != nil {
return err
Expand Down

0 comments on commit 42d2415

Please sign in to comment.