Do not create fs prefix for existing bucket
This commit is contained in:
parent
7e1842c274
commit
fae1210aaf
2 changed files with 23 additions and 18 deletions
|
@ -70,36 +70,40 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to check if bucket %s exists: %v", volumeID, err)
|
return nil, fmt.Errorf("failed to check if bucket %s exists: %v", volumeID, err)
|
||||||
}
|
}
|
||||||
if exists {
|
|
||||||
var b *bucket
|
var b *bucket
|
||||||
|
if exists {
|
||||||
b, err = s3.getBucket(volumeID)
|
b, err = s3.getBucket(volumeID)
|
||||||
// TODO 如果 bucket 已经存在了,为什么要去检查它是否有 metadata 和 capacity 呢?
|
|
||||||
// 或者说 metadata 的作用是什么?
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Warningf("failed to get bucket metadata of bucket %s: %v", volumeID, err)
|
glog.Warningf("Bucket %s exists, but failed to get its metadata: %v", volumeID, err)
|
||||||
// return nil, fmt.Errorf("failed to get bucket metadata of bucket %s: %v", volumeID, err)
|
b = &bucket{
|
||||||
if err = s3.createPrefix(volumeID, fsPrefix); err != nil {
|
Name: volumeID,
|
||||||
return nil, fmt.Errorf("failed to create prefix %s: %v", fsPrefix, err)
|
Mounter: mounter,
|
||||||
|
CapacityBytes: capacityBytes,
|
||||||
|
FSPath: "",
|
||||||
|
CreatedByCsi: false,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Check if volume capacity requested is bigger than the already existing capacity
|
// Check if volume capacity requested is bigger than the already existing capacity
|
||||||
if capacityBytes > b.CapacityBytes {
|
if capacityBytes > b.CapacityBytes {
|
||||||
return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("Volume with the same name: %s but with smaller size already exist", volumeID))
|
return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("Volume with the same name: %s but with smaller size already exist", volumeID))
|
||||||
}
|
}
|
||||||
|
b.Mounter = mounter
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = s3.createBucket(volumeID); err != nil {
|
if err = s3.createBucket(volumeID); err != nil {
|
||||||
return nil, fmt.Errorf("failed to create volume %s: %v", volumeID, err)
|
return nil, fmt.Errorf("failed to create volume %s: %v", volumeID, err)
|
||||||
}
|
}
|
||||||
if err = s3.createPrefix(volumeID, fsPrefix); err != nil {
|
if err = s3.createPrefix(volumeID, defaultFsPrefix); err != nil {
|
||||||
return nil, fmt.Errorf("failed to create prefix %s: %v", fsPrefix, err)
|
return nil, fmt.Errorf("failed to create prefix %s: %v", defaultFsPrefix, err)
|
||||||
}
|
}
|
||||||
}
|
b = &bucket{
|
||||||
b := &bucket{
|
|
||||||
Name: volumeID,
|
Name: volumeID,
|
||||||
Mounter: mounter,
|
Mounter: mounter,
|
||||||
CapacityBytes: capacityBytes,
|
CapacityBytes: capacityBytes,
|
||||||
FSPath: fsPrefix,
|
FSPath: defaultFsPrefix,
|
||||||
|
CreatedByCsi: !exists,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err := s3.setBucket(b); err != nil {
|
if err := s3.setBucket(b); err != nil {
|
||||||
return nil, fmt.Errorf("Error setting bucket metadata: %v", err)
|
return nil, fmt.Errorf("Error setting bucket metadata: %v", err)
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
metadataName = ".metadata.json"
|
metadataName = ".metadata.json"
|
||||||
fsPrefix = "csi-fs"
|
defaultFsPrefix = "csi-fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type s3Client struct {
|
type s3Client struct {
|
||||||
|
@ -29,6 +29,7 @@ type bucket struct {
|
||||||
Mounter string
|
Mounter string
|
||||||
FSPath string
|
FSPath string
|
||||||
CapacityBytes int64
|
CapacityBytes int64
|
||||||
|
CreatedByCsi bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newS3Client(cfg *Config) (*s3Client, error) {
|
func newS3Client(cfg *Config) (*s3Client, error) {
|
||||||
|
@ -133,7 +134,7 @@ func (client *s3Client) emptyBucket(bucketName string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure our prefix is also removed
|
// ensure our prefix is also removed
|
||||||
return client.minio.RemoveObject(client.ctx, bucketName, fsPrefix, minio.RemoveObjectOptions{})
|
return client.minio.RemoveObject(client.ctx, bucketName, defaultFsPrefix, minio.RemoveObjectOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *s3Client) setBucket(bucket *bucket) error {
|
func (client *s3Client) setBucket(bucket *bucket) error {
|
||||||
|
|
Loading…
Reference in a new issue