Skip to content

Commit

Permalink
allow set instace-type and disk-size when creating the crc-cloud inst…
Browse files Browse the repository at this point in the history
…ance 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
  • Loading branch information
adrianriobo committed Jul 19, 2023
1 parent 357dd22 commit 24d0b35
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
```
Expand Down
4 changes: 3 additions & 1 deletion pkg/provider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/provider/aws/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 19 additions & 2 deletions pkg/provider/aws/create-instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"strconv"

"github.com/crc/crc-cloud/pkg/bundle"
"github.com/crc/crc-cloud/pkg/bundle/setup"
Expand All @@ -17,6 +18,8 @@ import (
type createRequest struct {
projectName string
amiID string
instanceType string
diskSize int
bootingPrivateKeyFilePath string
ocpPullSecretFilePath string
}
Expand All @@ -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
}
Expand All @@ -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(),
}
Expand Down

0 comments on commit 24d0b35

Please sign in to comment.