1
1
package cmd
2
2
3
3
import (
4
+ "context"
4
5
"encoding/json"
5
6
"fmt"
6
7
"os"
@@ -280,13 +281,23 @@ coder envs edit back-end-env --disk 20`,
280
281
return err
281
282
}
282
283
283
- req , err := buildUpdateReq (updateConf {
284
- command : cmd ,
284
+ cpuCores , _ = cmd .Flags ().GetFloat32 ("cpu" )
285
+ memGB , _ = cmd .Flags ().GetFloat32 ("memory" )
286
+ diskGB , _ = cmd .Flags ().GetInt ("disk" )
287
+ gpus , _ = cmd .Flags ().GetInt ("gpus" )
288
+
289
+ req , err := buildUpdateReq (cmd .Context (),
290
+ updateConf {
291
+ cpu : cpuCores ,
292
+ memGB : memGB ,
293
+ diskGB : diskGB ,
294
+ gpus : gpus ,
285
295
client : client ,
286
296
environment : env ,
287
297
user : user ,
288
298
image : img ,
289
299
imageTag : tag ,
300
+ orgName : org ,
290
301
},
291
302
)
292
303
if err != nil {
@@ -394,15 +405,19 @@ func rmEnvsCommand(user *string) *cobra.Command {
394
405
}
395
406
396
407
type updateConf struct {
397
- command * cobra.Command
408
+ cpu float32
409
+ memGB float32
410
+ diskGB int
411
+ gpus int
398
412
client * coder.Client
399
413
environment * coder.Environment
400
414
user * string
401
415
image string
402
416
imageTag string
417
+ orgName string
403
418
}
404
419
405
- func buildUpdateReq (conf updateConf ) (* coder.UpdateEnvironmentReq , error ) {
420
+ func buildUpdateReq (ctx context. Context , conf updateConf ) (* coder.UpdateEnvironmentReq , error ) {
406
421
var (
407
422
updateReq coder.UpdateEnvironmentReq
408
423
defaultCPUCores float32
@@ -412,10 +427,11 @@ func buildUpdateReq(conf updateConf) (*coder.UpdateEnvironmentReq, error) {
412
427
413
428
// If this is not empty it means the user is requesting to change the environment image.
414
429
if conf .image != "" {
415
- importedImg , err := findImg (conf . command . Context () ,
430
+ importedImg , err := findImg (ctx ,
416
431
conf .client ,
417
432
* conf .user ,
418
433
conf .image ,
434
+ conf .orgName ,
419
435
)
420
436
if err != nil {
421
437
return nil , err
@@ -449,25 +465,22 @@ func buildUpdateReq(conf updateConf) (*coder.UpdateEnvironmentReq, error) {
449
465
// If they did not, then we will get the zero value back
450
466
// and should set the resource amount to the default.
451
467
452
- cpuCores , _ := conf .command .Flags ().GetFloat32 ("cpu" )
453
- if cpuCores == 0 {
468
+ if conf .cpu == 0 {
454
469
updateReq .CPUCores = & defaultCPUCores
455
470
} else {
456
- updateReq .CPUCores = & cpuCores
471
+ updateReq .CPUCores = & conf . cpu
457
472
}
458
473
459
- memGB , _ := conf .command .Flags ().GetFloat32 ("memory" )
460
- if memGB == 0 {
474
+ if conf .memGB == 0 {
461
475
updateReq .MemoryGB = & defaultMemGB
462
476
} else {
463
- updateReq .MemoryGB = & memGB
477
+ updateReq .MemoryGB = & conf . memGB
464
478
}
465
479
466
- diskGB , _ := conf .command .Flags ().GetInt ("disk" )
467
- if diskGB == 0 {
480
+ if conf .diskGB == 0 {
468
481
updateReq .DiskGB = & defaultDiskGB
469
482
} else {
470
- updateReq .DiskGB = & diskGB
483
+ updateReq .DiskGB = & conf . diskGB
471
484
}
472
485
473
486
// Environment disks can not be shrink so we have to overwrite this
@@ -477,9 +490,8 @@ func buildUpdateReq(conf updateConf) (*coder.UpdateEnvironmentReq, error) {
477
490
updateReq .DiskGB = & conf .environment .DiskGB
478
491
}
479
492
480
- gpus , _ := conf .command .Flags ().GetInt ("gpus" )
481
- if gpus != 0 {
482
- updateReq .GPUs = & gpus
493
+ if conf .gpus != 0 {
494
+ updateReq .GPUs = & conf .gpus
483
495
}
484
496
485
497
if conf .imageTag == "" {
0 commit comments