-
Notifications
You must be signed in to change notification settings - Fork 11
Added versioning configuration for COS buckets in CSI driver #172
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
base: main
Are you sure you want to change the base?
Changes from 8 commits
32915d0
7af7fda
0b6da41
164beb7
74059a3
2a1ee43
842b4de
2f00c67
28c3cd7
dffc1c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ func (cs *controllerServer) CreateVolume(_ context.Context, req *csi.CreateVolum | |
kpRootKeyCrn string | ||
pvcName string | ||
pvcNamespace string | ||
BucketVersioning string | ||
) | ||
secretMapCustom := make(map[string]string) | ||
|
||
|
@@ -164,6 +165,24 @@ func (cs *controllerServer) CreateVolume(_ context.Context, req *csi.CreateVolum | |
bucketName = secretMapCustom["bucketName"] | ||
} | ||
|
||
// Check for BucketVersioning parameter | ||
if val, ok := secretMap["BucketVersioning"]; ok && val != "" { | ||
enable := strings.ToLower(strings.TrimSpace(val)) | ||
if enable != "true" && enable != "false" { | ||
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("Invalid BucketVersioning value in secret: %s. Must be 'true' or 'false'", val)) | ||
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. Please log secret name as well her. |
||
} | ||
BucketVersioning = enable | ||
klog.Infof("BucketVersioning set via secret: %s", BucketVersioning) | ||
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. klog.Infof("BucketVersioning value that will be set via secret: %s", BucketVersioning) |
||
} else if val, ok := params["BucketVersioning"]; ok && val != "" { | ||
enable := strings.ToLower(strings.TrimSpace(val)) | ||
if enable != "true" && enable != "false" { | ||
return nil, status.Error(codes.InvalidArgument, | ||
fmt.Sprintf("Invalid BucketVersioning value in storage class: %s. Must be 'true' or 'false'", val)) | ||
} | ||
BucketVersioning = enable | ||
klog.Infof("BucketVersioning set via storage class: %s", BucketVersioning) | ||
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. klog.Infof("BucketVersioning value that will be set via storage class params: %s", BucketVersioning) |
||
} | ||
|
||
creds, err := getCredentials(secretMap) | ||
if err != nil { | ||
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("Error in getting credentials %v", err)) | ||
|
@@ -184,6 +203,16 @@ func (cs *controllerServer) CreateVolume(_ context.Context, req *csi.CreateVolum | |
params["userProvidedBucket"] = "false" | ||
klog.Infof("Created bucket: %s", bucketName) | ||
} | ||
|
||
if BucketVersioning != "" { | ||
enable := BucketVersioning == "true" | ||
if err := sess.SetBucketVersioning(bucketName, enable); err != nil { | ||
klog.Errorf("Failed to set versioning for bucket: %s, error: %v", bucketName, err) | ||
return nil, status.Error(codes.Internal, fmt.Sprintf("Failed to set versioning for bucket %s: %v", bucketName, err)) | ||
} | ||
klog.Infof("Bucket versioning set to %t for bucket %s", enable, bucketName) | ||
} | ||
|
||
params["bucketName"] = bucketName | ||
} else { | ||
// Generate random temp bucket name based on volume id | ||
|
@@ -197,6 +226,15 @@ func (cs *controllerServer) CreateVolume(_ context.Context, req *csi.CreateVolum | |
if err != nil { | ||
return nil, status.Error(codes.PermissionDenied, fmt.Sprintf("%v: %v", err, tempBucketName)) | ||
} | ||
// Enable versioning for new temp bucket | ||
if BucketVersioning != "" { | ||
enable := BucketVersioning == "true" | ||
if err := sess.SetBucketVersioning(tempBucketName, enable); err != nil { | ||
klog.Errorf("Failed to set versioning for temp bucket: %s, error: %v", tempBucketName, err) | ||
return nil, status.Error(codes.Internal, fmt.Sprintf("Failed to set versioning for bucket %s: %v", tempBucketName, err)) | ||
} | ||
klog.Infof("Bucket versioning set to %t for temp bucket %s", enable, tempBucketName) | ||
} | ||
klog.Infof("Created temp bucket: %s", tempBucketName) | ||
params["userProvidedBucket"] = "false" | ||
params["bucketName"] = tempBucketName | ||
|
@@ -441,6 +479,7 @@ func parseCustomSecret(secret *v1.Secret) map[string]string { | |
iamEndpoint string | ||
cosEndpoint string | ||
locationConstraint string | ||
BucketVersioning string | ||
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. bucketVersioning |
||
) | ||
|
||
if bytesVal, ok := secret.Data["accessKey"]; ok { | ||
|
@@ -479,6 +518,10 @@ func parseCustomSecret(secret *v1.Secret) map[string]string { | |
locationConstraint = string(bytesVal) | ||
} | ||
|
||
if bytesVal, ok := secret.Data["BucketVersioning"]; ok { | ||
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.
|
||
BucketVersioning = string(bytesVal) | ||
} | ||
|
||
secretMapCustom["accessKey"] = accessKey | ||
secretMapCustom["secretKey"] = secretKey | ||
secretMapCustom["apiKey"] = apiKey | ||
|
@@ -488,6 +531,7 @@ func parseCustomSecret(secret *v1.Secret) map[string]string { | |
secretMapCustom["iamEndpoint"] = iamEndpoint | ||
secretMapCustom["cosEndpoint"] = cosEndpoint | ||
secretMapCustom["locationConstraint"] = locationConstraint | ||
secretMapCustom["BucketVersioning"] = BucketVersioning | ||
|
||
return secretMapCustom | ||
} | ||
|
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.
bucketVersioning