diff --git a/coder-sdk/client.go b/coder-sdk/client.go index 8f512e05..3f859bde 100644 --- a/coder-sdk/client.go +++ b/coder-sdk/client.go @@ -17,14 +17,16 @@ type Client struct { // newHTTPClient creates a default underlying http client and sets the auth cookie. // -// NOTE: As we do not specify a custom transport, the default one from the stdlib will be used, -// resulting in a persistent connection pool. -// We do not set a timeout here as it could cause issue with the websocket. -// The caller is expected to set it when needed. +// NOTE: +// As we do not specify a custom transport, the default one from the stdlib will be used, +// resulting in a persistent connection pool. +// We do not set a timeout here as it could cause issue with the websocket. +// The caller is expected to set it when needed. // -// WARNING: If the caller sets a custom transport to set TLS settings or a custom CA, the default -// pool will not be used and it might result in a new dns lookup/tls session/socket begin -// established each time. +// WARNING: +// If the caller sets a custom transport to set TLS settings or a custom CA the default +// pool will not be used and it might result in a new dns lookup/tls session/socket begin +// established each time. func (c Client) newHTTPClient() (*http.Client, error) { jar, err := cookiejar.New(nil) if err != nil { diff --git a/coder-sdk/env.go b/coder-sdk/env.go index 62cf0812..e8962971 100644 --- a/coder-sdk/env.go +++ b/coder-sdk/env.go @@ -33,6 +33,7 @@ type Environment struct { LastConnectionAt time.Time `json:"last_connection_at" table:"-"` AutoOffThreshold Duration `json:"auto_off_threshold" table:"-"` SSHAvailable bool `json:"ssh_available" table:"-"` + UseContainerVM bool `json:"use_container_vm" table:"CVM"` } // RebuildMessage defines the message shown when an Environment requires a rebuild for it can be accessed. @@ -71,14 +72,15 @@ const ( // CreateEnvironmentRequest is used to configure a new environment. type CreateEnvironmentRequest struct { - Name string `json:"name"` - ImageID string `json:"image_id"` - ImageTag string `json:"image_tag"` - CPUCores float32 `json:"cpu_cores"` - MemoryGB float32 `json:"memory_gb"` - DiskGB int `json:"disk_gb"` - GPUs int `json:"gpus"` - Services []string `json:"services"` + Name string `json:"name"` + ImageID string `json:"image_id"` + ImageTag string `json:"image_tag"` + CPUCores float32 `json:"cpu_cores"` + MemoryGB float32 `json:"memory_gb"` + DiskGB int `json:"disk_gb"` + GPUs int `json:"gpus"` + Services []string `json:"services"` + UseContainerVM bool `json:"use_container_vm"` } // CreateEnvironment sends a request to create an environment. @@ -130,6 +132,7 @@ type UpdateEnvironmentReq struct { GPUs *int `json:"gpus"` Services *[]string `json:"services"` CodeServerReleaseURL *string `json:"code_server_release_url"` + UseContainerVM *bool `json:"use_container_vm"` } // RebuildEnvironment requests that the given envID is rebuilt with no changes to its specification. diff --git a/docs/coder_envs_create.md b/docs/coder_envs_create.md index 96b6048b..91daaf07 100644 --- a/docs/coder_envs_create.md +++ b/docs/coder_envs_create.md @@ -21,6 +21,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub ### Options ``` + --container-vm deploy the environment as a Container-based VM -c, --cpu float32 number of cpu cores the environment should be provisioned with. -d, --disk int GB of disk storage an environment should be provisioned with. --follow follow buildlog after initiating rebuild diff --git a/docs/coder_envs_edit.md b/docs/coder_envs_edit.md index 72416b2c..da94adcc 100644 --- a/docs/coder_envs_edit.md +++ b/docs/coder_envs_edit.md @@ -21,15 +21,17 @@ coder envs edit back-end-env --disk 20 ### Options ``` - -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. - -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") + --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 + -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 diff --git a/internal/cmd/envs.go b/internal/cmd/envs.go index e12e9d35..8ba33fb8 100644 --- a/internal/cmd/envs.go +++ b/internal/cmd/envs.go @@ -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, + 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{ @@ -296,6 +301,8 @@ coder envs edit back-end-env --disk 20`, image: img, imageTag: tag, orgName: org, + useCVM: useCVM, + notCVM: notCVM, }) if err != nil { return err @@ -328,6 +335,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") return cmd } @@ -391,8 +400,12 @@ type updateConf struct { image string imageTag string orgName string + useCVM bool + notCVM 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 +414,16 @@ func buildUpdateReq(ctx context.Context, client *coder.Client, conf updateConf) defaultDiskGB int ) + if conf.useCVM && conf.notCVM { + return nil, xerrors.New("--container-vm and --not-container-vm flags conflict") + } + if conf.useCVM { + updateReq.UseContainerVM = boolP(true) + } + if conf.notCVM { + updateReq.UseContainerVM = boolP(false) + } + // 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{