From 24d0b35bd5e8e4239c5a5faee15a2d0ba4db8bfe Mon Sep 17 00:00:00 2001 From: Adrian Riobo Lorenzo Date: Wed, 19 Jul 2023 14:57:48 +0200 Subject: [PATCH] allow set instace-type and disk-size when creating the crc-cloud instance on aws provider previously crc-cloud instance was created on a fixed type of machine and with a fixed size of disk, now those values can be set when create the machine, allowing to create cluster with more resources or even with different archs --- README.md | 8 ++++++-- pkg/provider/aws/aws.go | 4 +++- pkg/provider/aws/constants.go | 8 ++++++-- pkg/provider/aws/create-instance.go | 21 +++++++++++++++++++-- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4bbbe5d0..d931c74b 100644 --- a/README.md +++ b/README.md @@ -107,8 +107,10 @@ Usage: crc-cloud create aws [flags] Flags: - --aws-ami-id string AMI identifier - -h, --help help for aws + --aws-ami-id string AMI identifier + --aws-disk-size string Disk size in GB for the machine running the cluster. Default is 100. + --aws-instance-type string Instance type for the machine running the cluster. Default is c6a.2xlarge. + -h, --help help for aws Global Flags: --backed-url string backed for stack state. Can be a local path with format file:///path/subpath or s3 s3://existing-bucket @@ -140,6 +142,8 @@ podman run -d --rm \ --output "/workspace" \ --tags account=qe-pt,profile=builder \ --aws-ami-id "ami-xxxx" \ + --aws-instance-type "c6i.4xlarge" \ + --aws-disk-size "200" \ --pullsecret-filepath "/workspace/pullsecret" \ --key-filepath "/workspace/id_ecdsa" ``` diff --git a/pkg/provider/aws/aws.go b/pkg/provider/aws/aws.go index 53118d1a..40ca1938 100644 --- a/pkg/provider/aws/aws.go +++ b/pkg/provider/aws/aws.go @@ -27,7 +27,9 @@ func (a *Provider) ImportImageRunFunc(projectName, bundleDownloadURL, shasumfile func (a *Provider) CreateParams() map[string]string { return map[string]string{ - amiID: amiIDDesc, + amiID: amiIDDesc, + instanceType: instanceTypeDesc, + diskSize: diskSizeDesc, } } diff --git a/pkg/provider/aws/constants.go b/pkg/provider/aws/constants.go index a652a54f..78ff9106 100644 --- a/pkg/provider/aws/constants.go +++ b/pkg/provider/aws/constants.go @@ -3,8 +3,12 @@ package aws const ( // Create params - amiID string = "aws-ami-id" - amiIDDesc string = "AMI identifier" + amiID string = "aws-ami-id" + amiIDDesc string = "AMI identifier" + instanceType string = "aws-instance-type" + instanceTypeDesc string = "Instance type for the machine running the cluster. Default is c6a.2xlarge." + diskSize string = "aws-disk-size" + diskSizeDesc string = "Disk size in GB for the machine running the cluster. Default is 100." // default values ocpInstanceType string = "c6a.2xlarge" diff --git a/pkg/provider/aws/create-instance.go b/pkg/provider/aws/create-instance.go index cf7d4f1e..2c32c3d8 100644 --- a/pkg/provider/aws/create-instance.go +++ b/pkg/provider/aws/create-instance.go @@ -2,6 +2,7 @@ package aws import ( "fmt" + "strconv" "github.com/crc/crc-cloud/pkg/bundle" "github.com/crc/crc-cloud/pkg/bundle/setup" @@ -17,6 +18,8 @@ import ( type createRequest struct { projectName string amiID string + instanceType string + diskSize int bootingPrivateKeyFilePath string ocpPullSecretFilePath string } @@ -27,9 +30,23 @@ func fillCreateRequest(projectName, bootingPrivateKeyFilePath, ocpPullSecretFile if !ok { return nil, fmt.Errorf("amiID not found") } + it := ocpInstanceType + if customInstanceType, ok := args[instanceType]; ok { + it = customInstanceType + } + ds := ocpDefaultRootBlockDeviceSize + if customDiskSizeAsString, ok := args[diskSize]; ok { + customDiskSize, err := strconv.Atoi(customDiskSizeAsString) + if err != nil { + return nil, fmt.Errorf("error creating request for cluster machine: %v", err) + } + ds = customDiskSize + } return &createRequest{ projectName: projectName, amiID: amiIDValue, + instanceType: it, + diskSize: ds, bootingPrivateKeyFilePath: bootingPrivateKeyFilePath, ocpPullSecretFilePath: ocpPullSecretFilePath}, nil } @@ -45,12 +62,12 @@ func (r createRequest) runFunc(ctx *pulumi.Context) error { } args := ec2.InstanceArgs{ Ami: pulumi.String(r.amiID), - InstanceType: pulumi.String(ocpInstanceType), + InstanceType: pulumi.String(r.instanceType), KeyName: awsKeyPair.KeyName, AssociatePublicIpAddress: pulumi.Bool(true), VpcSecurityGroupIds: securityGroupsIds, RootBlockDevice: ec2.InstanceRootBlockDeviceArgs{ - VolumeSize: pulumi.Int(ocpDefaultRootBlockDeviceSize), + VolumeSize: pulumi.Int(r.diskSize), }, Tags: context.GetTags(), }