This repository was archived by the owner on Aug 30, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork18
Add cvm flag to CLI and fields to coder-sdk#201
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from3 commits
Commits
Show all changes
4 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
16 changes: 9 additions & 7 deletionscoder-sdk/client.go
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
19 changes: 11 additions & 8 deletionscoder-sdk/env.go
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
1 change: 1 addition & 0 deletionsdocs/coder_envs_create.md
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
20 changes: 11 additions & 9 deletionsdocs/coder_envs_edit.md
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 |
---|---|---|
@@ -21,15 +21,17 @@ coder envs edit back-end-env --disk 20 | ||
### Options | ||
``` | ||
--container-vm deploy the environment as a Container-based VM | ||
-c, --cpu float32 The number of cpu cores the environment should be provisioned with. | ||
-d, --disk int The amount of disk storage an environment should be provisioned with. | ||
--follow follow buildlog after initiating rebuild | ||
-g, --gpu int The amount of disk storage to provision the environment with. | ||
-h, --help help for edit | ||
-i, --image string name of the image you want the environment to be based off of. | ||
-m, --memory float32 The amount of RAM an environment should be provisioned with. | ||
--not-container-vm do not deploy the environment as a Container-based VM | ||
cmoog marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
-o, --org string name of the organization the environment should be created under. | ||
-t, --tag string image tag of the image you want to base the environment off of. (default "latest") | ||
``` | ||
### Options inherited from parent commands | ||
35 changes: 28 additions & 7 deletionsinternal/cmd/envs.go
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 |
---|---|---|
@@ -148,6 +148,7 @@ func createEnvCmd(user *string) *cobra.Command { | ||
img string | ||
tag string | ||
follow bool | ||
useCVM bool | ||
) | ||
cmd := &cobra.Command{ | ||
@@ -189,13 +190,14 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub | ||
// ExactArgs(1) ensures our name value can't panic on an out of bounds. | ||
createReq := &coder.CreateEnvironmentRequest{ | ||
Name: args[0], | ||
ImageID: importedImg.ID, | ||
ImageTag: tag, | ||
CPUCores: cpu, | ||
MemoryGB: memory, | ||
DiskGB: disk, | ||
GPUs: gpus, | ||
UseContainerVM: useCVM, | ||
} | ||
// if any of these defaulted to their zero value we provision | ||
@@ -238,6 +240,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub | ||
cmd.Flags().IntVarP(&gpus, "gpus", "g", 0, "number GPUs an environment should be provisioned with.") | ||
cmd.Flags().StringVarP(&img, "image", "i", "", "name of the image to base the environment off of.") | ||
cmd.Flags().BoolVar(&follow, "follow", false, "follow buildlog after initiating rebuild") | ||
cmd.Flags().BoolVar(&useCVM, "container-vm", false, "deploy the environment as a Container-based VM") | ||
_ = cmd.MarkFlagRequired("image") | ||
return cmd | ||
} | ||
@@ -252,6 +255,8 @@ func editEnvCmd(user *string) *cobra.Command { | ||
disk int | ||
gpus int | ||
follow bool | ||
useCVM bool | ||
notCVM bool | ||
) | ||
cmd := &cobra.Command{ | ||
@@ -328,6 +333,8 @@ coder envs edit back-end-env --disk 20`, | ||
cmd.Flags().IntVarP(&disk, "disk", "d", 0, "The amount of disk storage an environment should be provisioned with.") | ||
cmd.Flags().IntVarP(&gpus, "gpu", "g", 0, "The amount of disk storage to provision the environment with.") | ||
cmd.Flags().BoolVar(&follow, "follow", false, "follow buildlog after initiating rebuild") | ||
cmd.Flags().BoolVar(&useCVM, "container-vm", false, "deploy the environment as a Container-based VM") | ||
cmd.Flags().BoolVar(¬CVM, "not-container-vm", false, "do not deploy the environment as a Container-based VM") | ||
cmoog marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
return cmd | ||
} | ||
@@ -391,8 +398,12 @@ type updateConf struct { | ||
image string | ||
imageTag string | ||
orgName string | ||
useCVM bool | ||
noCVM bool | ||
} | ||
func boolP(a bool) *bool { return &a } | ||
func buildUpdateReq(ctx context.Context, client *coder.Client, conf updateConf) (*coder.UpdateEnvironmentReq, error) { | ||
var ( | ||
updateReq coder.UpdateEnvironmentReq | ||
@@ -401,6 +412,16 @@ func buildUpdateReq(ctx context.Context, client *coder.Client, conf updateConf) | ||
defaultDiskGB int | ||
) | ||
if conf.useCVM && conf.noCVM { | ||
return nil, xerrors.New("--container-vm and --not-container-vm flags conflict") | ||
} | ||
if conf.useCVM { | ||
updateReq.UseContainerVM = boolP(true) | ||
} | ||
if conf.noCVM { | ||
updateReq.UseContainerVM = boolP(false) | ||
} | ||
cmoog marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
// If this is not empty it means the user is requesting to change the environment image. | ||
if conf.image != "" { | ||
importedImg, err := findImg(ctx, client, findImgConf{ | ||
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.