Skip to content

Commit

Permalink
Prevent setting the volume size when creating one from snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
torrefatto committed Oct 3, 2024
1 parent 41cb1f2 commit b598bc8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/koyeb/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func NewVolumeCmd() *cobra.Command {
}
req.SetRegion(region)

isFromSnapshot := false
snapshot, err := cmd.Flags().GetString("snapshot")
if err != nil {
return err
Expand All @@ -49,6 +50,7 @@ func NewVolumeCmd() *cobra.Command {
return err
}
req.SetSnapshotId(id)
isFromSnapshot = true
}

// TODO: use a flag for the volume type when/if we support more than one
Expand All @@ -58,6 +60,20 @@ func NewVolumeCmd() *cobra.Command {
if err != nil {
return err
}
if size < 0 {
return &errors.CLIError{
What: "Invalid flag",
Why: "Invalid --size flag",
Solution: "A size for the volume cannot be negative",
}
}
if size != 0 && isFromSnapshot {
return &errors.CLIError{
What: "Invalid flag",
Why: "Invalid --size flag",
Solution: "A size for the volume cannot be specified when creating a volume from a snapshot",
}
}
req.SetMaxSize(size)

readOnly, err := cmd.Flags().GetBool("read-only")
Expand Down

0 comments on commit b598bc8

Please sign in to comment.