-
Notifications
You must be signed in to change notification settings - Fork 98
fix: reconsider behavior when providing a value lower than 500 for bu… #438
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
Open
harsh082ip
wants to merge
3
commits into
civo:master
Choose a base branch
from
harsh082ip:issue-394
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+52
−12
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -13,16 +13,19 @@ import ( | |
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var allowedBucketSizes = []int64{500, 1000} | ||
|
|
||
| var bucketSize int64 | ||
| var owner string | ||
| var waitOS bool | ||
| var yesFlag bool | ||
|
|
||
| var objectStoreCreateCmd = &cobra.Command{ | ||
| Use: "create", | ||
| Aliases: []string{"new", "add"}, | ||
| Example: "civo objectstore create OBJECTSTORE_NAME --size SIZE", | ||
| Short: "Create a new Object Store", | ||
| Long: "Bucket size should be in Gigabytes (GB) and must be a multiple of 500, starting from 500.\n", | ||
| Long: "Bucket size should be in Gigabytes (GB) and must be either 500 or 1000.\n", | ||
|
Contributor
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. couldn't we use the constants of before, declared in a common package? |
||
| Args: cobra.MinimumNArgs(0), | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| utility.EnsureCurrentRegion() | ||
|
|
@@ -34,7 +37,6 @@ var objectStoreCreateCmd = &cobra.Command{ | |
| os.Exit(1) | ||
| } | ||
| objectStoreName = args[0] | ||
|
|
||
| } else { | ||
| objectStoreName = utility.RandomName() | ||
| } | ||
|
|
@@ -60,17 +62,29 @@ var objectStoreCreateCmd = &cobra.Command{ | |
| client.Region = common.RegionSet | ||
| } | ||
|
|
||
| if bucketSize < 500 { | ||
| utility.Error("The minimum size to create an object store is 500 GB. Please provide a valid size.") | ||
| if bucketSize < minBucketSizeGB { | ||
| utility.Error("The minimum size to create an object store is %d GB. Please provide a valid size.", minBucketSizeGB) | ||
| os.Exit(1) | ||
| } else if bucketSize%500 != 0 { | ||
| utility.YellowConfirm("The size to create an object store must be a multiple of 500. Would you like to create an %s of %d GB instead? (y/n) ? ", utility.Green("object store"), bucketSize+(500-bucketSize%500)) | ||
| _, err := utility.UserAccepts(os.Stdin) | ||
| if err != nil { | ||
| utility.Error("Unable to parse the input: %s", err) | ||
| } | ||
|
|
||
| if !isAllowedSize(bucketSize) { | ||
| newSize := adjustedBucketSize(bucketSize) | ||
| if !isAllowedSize(newSize) { | ||
| utility.Error("Only 500 GB and 1000 GB sizes are allowed for Object Store.") | ||
| os.Exit(1) | ||
| } | ||
| bucketSize = bucketSize + (500 - bucketSize%500) | ||
| if !yesFlag { | ||
| utility.YellowConfirm("Only 500 GB and 1000 GB sizes are allowed. Would you like to create an object store of %d GB instead? (y/n)", newSize) | ||
| accept, err := utility.UserAccepts(os.Stdin) | ||
| if err != nil { | ||
| utility.Error("Unable to parse the input: %s", err) | ||
| os.Exit(1) | ||
| } | ||
| if !accept { | ||
| os.Exit(1) | ||
| } | ||
| } | ||
| bucketSize = newSize | ||
| } | ||
|
|
||
| var credential *civogo.ObjectStoreCredential | ||
|
|
@@ -135,7 +149,11 @@ var objectStoreCreateCmd = &cobra.Command{ | |
| os.Exit(1) | ||
| } | ||
|
|
||
| ow := utility.NewOutputWriterWithMap(map[string]string{"name": objectStore.Name, "id": objectStore.ID, "access_key": objectStore.OwnerInfo.AccessKeyID}) | ||
| ow := utility.NewOutputWriterWithMap(map[string]string{ | ||
| "name": objectStore.Name, | ||
| "id": objectStore.ID, | ||
| "access_key": objectStore.OwnerInfo.AccessKeyID, | ||
| }) | ||
|
|
||
| switch common.OutputFormat { | ||
| case "json": | ||
|
|
@@ -154,3 +172,19 @@ var objectStoreCreateCmd = &cobra.Command{ | |
| } | ||
| }, | ||
| } | ||
|
|
||
| func adjustedBucketSize(size int64) int64 { | ||
| if size < minBucketSizeGB { | ||
| return minBucketSizeGB | ||
| } | ||
| return minBucketSizeGB * ((size + minBucketSizeGB - 1) / minBucketSizeGB) | ||
| } | ||
|
|
||
| func isAllowedSize(size int64) bool { | ||
| for _, allowed := range allowedBucketSizes { | ||
| if size == allowed { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
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.
why the 500 is set as constant while the 1000 isn't?