Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 9b94c77

Browse files
authored
Add cvm flag to CLI and fields to coder-sdk (#201)
1 parent 58320e4 commit 9b94c77

File tree

5 files changed

+62
-31
lines changed

5 files changed

+62
-31
lines changed

coder-sdk/client.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ type Client struct {
1717

1818
// newHTTPClient creates a default underlying http client and sets the auth cookie.
1919
//
20-
// NOTE: As we do not specify a custom transport, the default one from the stdlib will be used,
21-
// resulting in a persistent connection pool.
22-
// We do not set a timeout here as it could cause issue with the websocket.
23-
// The caller is expected to set it when needed.
20+
// NOTE:
21+
// As we do not specify a custom transport, the default one from the stdlib will be used,
22+
// resulting in a persistent connection pool.
23+
// We do not set a timeout here as it could cause issue with the websocket.
24+
// The caller is expected to set it when needed.
2425
//
25-
// WARNING: If the caller sets a custom transport to set TLS settings or a custom CA, the default
26-
// pool will not be used and it might result in a new dns lookup/tls session/socket begin
27-
// established each time.
26+
// WARNING:
27+
// If the caller sets a custom transport to set TLS settings or a custom CA the default
28+
// pool will not be used and it might result in a new dns lookup/tls session/socket begin
29+
// established each time.
2830
func (c Client) newHTTPClient() (*http.Client, error) {
2931
jar, err := cookiejar.New(nil)
3032
if err != nil {

coder-sdk/env.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Environment struct {
3333
LastConnectionAt time.Time `json:"last_connection_at" table:"-"`
3434
AutoOffThreshold Duration `json:"auto_off_threshold" table:"-"`
3535
SSHAvailable bool `json:"ssh_available" table:"-"`
36+
UseContainerVM bool `json:"use_container_vm" table:"CVM"`
3637
}
3738

3839
// RebuildMessage defines the message shown when an Environment requires a rebuild for it can be accessed.
@@ -71,14 +72,15 @@ const (
7172

7273
// CreateEnvironmentRequest is used to configure a new environment.
7374
type CreateEnvironmentRequest struct {
74-
Name string `json:"name"`
75-
ImageID string `json:"image_id"`
76-
ImageTag string `json:"image_tag"`
77-
CPUCores float32 `json:"cpu_cores"`
78-
MemoryGB float32 `json:"memory_gb"`
79-
DiskGB int `json:"disk_gb"`
80-
GPUs int `json:"gpus"`
81-
Services []string `json:"services"`
75+
Name string `json:"name"`
76+
ImageID string `json:"image_id"`
77+
ImageTag string `json:"image_tag"`
78+
CPUCores float32 `json:"cpu_cores"`
79+
MemoryGB float32 `json:"memory_gb"`
80+
DiskGB int `json:"disk_gb"`
81+
GPUs int `json:"gpus"`
82+
Services []string `json:"services"`
83+
UseContainerVM bool `json:"use_container_vm"`
8284
}
8385

8486
// CreateEnvironment sends a request to create an environment.
@@ -130,6 +132,7 @@ type UpdateEnvironmentReq struct {
130132
GPUs *int `json:"gpus"`
131133
Services *[]string `json:"services"`
132134
CodeServerReleaseURL *string `json:"code_server_release_url"`
135+
UseContainerVM *bool `json:"use_container_vm"`
133136
}
134137

135138
// RebuildEnvironment requests that the given envID is rebuilt with no changes to its specification.

docs/coder_envs_create.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
2121
### Options
2222

2323
```
24+
--container-vm deploy the environment as a Container-based VM
2425
-c, --cpu float32 number of cpu cores the environment should be provisioned with.
2526
-d, --disk int GB of disk storage an environment should be provisioned with.
2627
--follow follow buildlog after initiating rebuild

docs/coder_envs_edit.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ coder envs edit back-end-env --disk 20
2121
### Options
2222

2323
```
24-
-c, --cpu float32 The number of cpu cores the environment should be provisioned with.
25-
-d, --disk int The amount of disk storage an environment should be provisioned with.
26-
--follow follow buildlog after initiating rebuild
27-
-g, --gpu int The amount of disk storage to provision the environment with.
28-
-h, --help help for edit
29-
-i, --image string name of the image you want the environment to be based off of.
30-
-m, --memory float32 The amount of RAM an environment should be provisioned with.
31-
-o, --org string name of the organization the environment should be created under.
32-
-t, --tag string image tag of the image you want to base the environment off of. (default "latest")
24+
--container-vm deploy the environment as a Container-based VM
25+
-c, --cpu float32 The number of cpu cores the environment should be provisioned with.
26+
-d, --disk int The amount of disk storage an environment should be provisioned with.
27+
--follow follow buildlog after initiating rebuild
28+
-g, --gpu int The amount of disk storage to provision the environment with.
29+
-h, --help help for edit
30+
-i, --image string name of the image you want the environment to be based off of.
31+
-m, --memory float32 The amount of RAM an environment should be provisioned with.
32+
--not-container-vm do not deploy the environment as a Container-based VM
33+
-o, --org string name of the organization the environment should be created under.
34+
-t, --tag string image tag of the image you want to base the environment off of. (default "latest")
3335
```
3436

3537
### Options inherited from parent commands

internal/cmd/envs.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ func createEnvCmd(user *string) *cobra.Command {
148148
img string
149149
tag string
150150
follow bool
151+
useCVM bool
151152
)
152153

153154
cmd := &cobra.Command{
@@ -189,13 +190,14 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
189190

190191
// ExactArgs(1) ensures our name value can't panic on an out of bounds.
191192
createReq := &coder.CreateEnvironmentRequest{
192-
Name: args[0],
193-
ImageID: importedImg.ID,
194-
ImageTag: tag,
195-
CPUCores: cpu,
196-
MemoryGB: memory,
197-
DiskGB: disk,
198-
GPUs: gpus,
193+
Name: args[0],
194+
ImageID: importedImg.ID,
195+
ImageTag: tag,
196+
CPUCores: cpu,
197+
MemoryGB: memory,
198+
DiskGB: disk,
199+
GPUs: gpus,
200+
UseContainerVM: useCVM,
199201
}
200202

201203
// 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
238240
cmd.Flags().IntVarP(&gpus, "gpus", "g", 0, "number GPUs an environment should be provisioned with.")
239241
cmd.Flags().StringVarP(&img, "image", "i", "", "name of the image to base the environment off of.")
240242
cmd.Flags().BoolVar(&follow, "follow", false, "follow buildlog after initiating rebuild")
243+
cmd.Flags().BoolVar(&useCVM, "container-vm", false, "deploy the environment as a Container-based VM")
241244
_ = cmd.MarkFlagRequired("image")
242245
return cmd
243246
}
@@ -252,6 +255,8 @@ func editEnvCmd(user *string) *cobra.Command {
252255
disk int
253256
gpus int
254257
follow bool
258+
useCVM bool
259+
notCVM bool
255260
)
256261

257262
cmd := &cobra.Command{
@@ -296,6 +301,8 @@ coder envs edit back-end-env --disk 20`,
296301
image: img,
297302
imageTag: tag,
298303
orgName: org,
304+
useCVM: useCVM,
305+
notCVM: notCVM,
299306
})
300307
if err != nil {
301308
return err
@@ -328,6 +335,8 @@ coder envs edit back-end-env --disk 20`,
328335
cmd.Flags().IntVarP(&disk, "disk", "d", 0, "The amount of disk storage an environment should be provisioned with.")
329336
cmd.Flags().IntVarP(&gpus, "gpu", "g", 0, "The amount of disk storage to provision the environment with.")
330337
cmd.Flags().BoolVar(&follow, "follow", false, "follow buildlog after initiating rebuild")
338+
cmd.Flags().BoolVar(&useCVM, "container-vm", false, "deploy the environment as a Container-based VM")
339+
cmd.Flags().BoolVar(&notCVM, "not-container-vm", false, "do not deploy the environment as a Container-based VM")
331340
return cmd
332341
}
333342

@@ -391,8 +400,12 @@ type updateConf struct {
391400
image string
392401
imageTag string
393402
orgName string
403+
useCVM bool
404+
notCVM bool
394405
}
395406

407+
func boolP(a bool) *bool { return &a }
408+
396409
func buildUpdateReq(ctx context.Context, client *coder.Client, conf updateConf) (*coder.UpdateEnvironmentReq, error) {
397410
var (
398411
updateReq coder.UpdateEnvironmentReq
@@ -401,6 +414,16 @@ func buildUpdateReq(ctx context.Context, client *coder.Client, conf updateConf)
401414
defaultDiskGB int
402415
)
403416

417+
if conf.useCVM && conf.notCVM {
418+
return nil, xerrors.New("--container-vm and --not-container-vm flags conflict")
419+
}
420+
if conf.useCVM {
421+
updateReq.UseContainerVM = boolP(true)
422+
}
423+
if conf.notCVM {
424+
updateReq.UseContainerVM = boolP(false)
425+
}
426+
404427
// If this is not empty it means the user is requesting to change the environment image.
405428
if conf.image != "" {
406429
importedImg, err := findImg(ctx, client, findImgConf{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy