From d256695915208b162c6422d62741912d4551d8f5 Mon Sep 17 00:00:00 2001 From: Cezar Craciunoiu Date: Wed, 21 Aug 2024 10:49:21 +0300 Subject: [PATCH] feat(cloud): Introduce 'vcpus' flag for instance creation Signed-off-by: Cezar Craciunoiu --- internal/cli/kraft/cloud/deploy/deploy.go | 1 + internal/cli/kraft/cloud/deploy/deployer_image_name.go | 1 + internal/cli/kraft/cloud/deploy/deployer_kraftfile_runtime.go | 1 + internal/cli/kraft/cloud/instance/create/create.go | 4 ++++ 4 files changed, 7 insertions(+) diff --git a/internal/cli/kraft/cloud/deploy/deploy.go b/internal/cli/kraft/cloud/deploy/deploy.go index 52cd74094..4d5237621 100644 --- a/internal/cli/kraft/cloud/deploy/deploy.go +++ b/internal/cli/kraft/cloud/deploy/deploy.go @@ -76,6 +76,7 @@ type DeployOptions struct { SubDomain []string `local:"true" long:"subdomain" short:"s" usage:"Set the names to use when provisioning subdomains"` Timeout time.Duration `local:"true" long:"timeout" usage:"Set the timeout for remote procedure calls (ms/s/m/h)" default:"60s"` Token string `noattribute:"true"` + Vcpus uint `local:"true" long:"vcpus" short:"V" usage:"Specify the number of vCPUs to allocate"` Volumes []string `long:"volume" short:"v" usage:"Specify the volume mapping(s) in the form NAME:DEST or NAME:DEST:OPTIONS"` Workdir string `local:"true" long:"workdir" short:"w" usage:"Set an alternative working directory (default is cwd)"` } diff --git a/internal/cli/kraft/cloud/deploy/deployer_image_name.go b/internal/cli/kraft/cloud/deploy/deployer_image_name.go index 805f6c5c8..29a8d54d1 100644 --- a/internal/cli/kraft/cloud/deploy/deployer_image_name.go +++ b/internal/cli/kraft/cloud/deploy/deployer_image_name.go @@ -114,6 +114,7 @@ func (deployer *deployerImageName) Deploy(ctx context.Context, opts *DeployOptio Start: !opts.NoStart, SubDomain: opts.SubDomain, Token: opts.Token, + Vcpus: opts.Vcpus, }, deployer.args...) if err != nil { return fmt.Errorf("could not create instance: %w", err) diff --git a/internal/cli/kraft/cloud/deploy/deployer_kraftfile_runtime.go b/internal/cli/kraft/cloud/deploy/deployer_kraftfile_runtime.go index 085a7a6c2..9ac9f07e8 100644 --- a/internal/cli/kraft/cloud/deploy/deployer_kraftfile_runtime.go +++ b/internal/cli/kraft/cloud/deploy/deployer_kraftfile_runtime.go @@ -142,6 +142,7 @@ func (deployer *deployerKraftfileRuntime) Deploy(ctx context.Context, opts *Depl Start: !opts.NoStart, SubDomain: opts.SubDomain, Token: opts.Token, + Vcpus: opts.Vcpus, Volumes: opts.Volumes, WaitForImage: true, WaitForImageTimeout: opts.Timeout, diff --git a/internal/cli/kraft/cloud/instance/create/create.go b/internal/cli/kraft/cloud/instance/create/create.go index 24bd14f58..61b11faa2 100644 --- a/internal/cli/kraft/cloud/instance/create/create.go +++ b/internal/cli/kraft/cloud/instance/create/create.go @@ -60,6 +60,7 @@ type CreateOptions struct { ScaleToZeroCooldown time.Duration `local:"true" long:"scale-to-zero-cooldown" usage:"Cooldown period before scaling to zero (ms/s/m/h)"` SubDomain []string `local:"true" long:"subdomain" short:"s" usage:"Set the subdomains to use when creating the service"` Token string `noattribute:"true"` + Vcpus uint `local:"true" long:"vcpus" short:"V" usage:"Specify the number of vCPUs to allocate"` Volumes []string `local:"true" long:"volume" short:"v" usage:"List of volumes to attach instance to"` WaitForImage bool `local:"true" long:"wait-for-image" short:"w" usage:"Wait for the image to be available before creating the instance"` WaitForImageTimeout time.Duration `local:"true" long:"wait-for-image-timeout" usage:"Time to wait before timing out when waiting for image (ms/s/m/h)" default:"60s"` @@ -199,6 +200,9 @@ func Create(ctx context.Context, opts *CreateOptions, args ...string) (*kcclient Image: opts.Image, RestartPolicy: opts.RestartPolicy, } + if opts.Vcpus > 0 { + req.Vcpus = ptr(int(opts.Vcpus)) + } if opts.Name != "" { req.Name = &opts.Name }