Skip to content

Commit

Permalink
Add custom vpc support in AWS cloud prepare
Browse files Browse the repository at this point in the history
Signed-off-by: Aswin Suryanarayanan <asuryana@redhat.com>
  • Loading branch information
aswinsuryan committed Sep 24, 2024
1 parent bf332e0 commit 2e112e9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
9 changes: 9 additions & 0 deletions cmd/subctl/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ func init() {
"OCP metadata.json file (or directory containing it) to read AWS infra ID and region from (Takes precedence over the flags)")
command.Flags().StringVar(&awsConfig.Profile, "profile", cpaws.DefaultProfile(), "AWS profile to use for credentials")
command.Flags().StringVar(&awsConfig.CredentialsFile, "credentials", cpaws.DefaultCredentialsFile(), "AWS credentials configuration file")

command.Flags().StringVar(&awsConfig.ControlPlaneSecurityGroup, "control-plane-security-group", "",
"Custom AWS control plane security group name if the default is not used while provisioning")
command.Flags().StringVar(&awsConfig.WorkerSecurityGroup, "worker-security-group", "",
"Custom AWS worker security group name if the default is not used while provisioning")
command.Flags().StringVar(&awsConfig.VpcName, "vpc-name", "",
"Custom AWS VPC name if the default is not used while provisioning")
command.Flags().StringSliceVar(&awsConfig.SubnetNames, "subnet-names", nil,
"Custom AWS subnet names if the default is not used while provisioning (comma-separated list)")
}

addGeneralAWSFlags(awsPrepareCmd)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/submariner-io/admiral v0.19.0-m3
github.com/submariner-io/cloud-prepare v0.19.0-m3
github.com/submariner-io/cloud-prepare v0.19.0-m3.0.20240924020030-81ebc17f5877
github.com/submariner-io/lighthouse v0.19.0-m3
github.com/submariner-io/shipyard v0.19.0-m3
github.com/submariner-io/submariner v0.19.0-m3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/submariner-io/admiral v0.19.0-m3 h1:LTkYxCvB8S1210P2FZtCb6dzjaPpIgBrRQxZkH/snDo=
github.com/submariner-io/admiral v0.19.0-m3/go.mod h1:xRpP1rDOblEdPHr0qrC+plcTNfShYJAOH2fexqOmI1A=
github.com/submariner-io/cloud-prepare v0.19.0-m3 h1:f2PR4fFSJnwI5Ta9gTSmH0+Y2ZgES+hmBvAF29j45vM=
github.com/submariner-io/cloud-prepare v0.19.0-m3/go.mod h1:LEyZLtFxBytG73MPS2kvmF/ASoNmVPIKrEjroWJFSOQ=
github.com/submariner-io/cloud-prepare v0.19.0-m3.0.20240924020030-81ebc17f5877 h1:56O6Vhdv7pGyLqLXwTUKNjxLavqgiXqH0D1Li/A7gsY=
github.com/submariner-io/cloud-prepare v0.19.0-m3.0.20240924020030-81ebc17f5877/go.mod h1:LEyZLtFxBytG73MPS2kvmF/ASoNmVPIKrEjroWJFSOQ=
github.com/submariner-io/lighthouse v0.19.0-m3 h1:CDv7V6lM/ixurJKvM9H9D2ckVXD9bJpY4F2IHPHcp/8=
github.com/submariner-io/lighthouse v0.19.0-m3/go.mod h1:SA5PyBm+pM2Dx2MgWFNz/eJPN3Wde4BrnNWysWQzBRQ=
github.com/submariner-io/shipyard v0.19.0-m3 h1:NliwAktRPF4OsLj1TDgpaOJD/bmmZW/FH9+mJmWgxbk=
Expand Down
45 changes: 35 additions & 10 deletions pkg/cloud/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ import (
)

type Config struct {
Gateways int
InfraID string
Region string
Profile string
CredentialsFile string
OcpMetadataFile string
GWInstanceType string
Gateways int
InfraID string
Region string
Profile string
CredentialsFile string
OcpMetadataFile string
GWInstanceType string
ControlPlaneSecurityGroup string
WorkerSecurityGroup string
VpcName string
SubnetNames []string
}

// RunOn runs the given function on AWS, supplying it with a cloud instance connected to AWS and a reporter that writes to CLI.
Expand All @@ -57,11 +61,32 @@ func RunOn(clusterInfo *cluster.Info, config *Config, status reporter.Interface,

status.Start("Initializing AWS connectivity")

awsCloud, err := aws.NewCloudFromSettings(config.CredentialsFile, config.Profile, config.InfraID, config.Region)
if err != nil {
return status.Error(err, "error loading default config")
var cloudOptions []aws.CloudOption

if config.ControlPlaneSecurityGroup != "" {
cloudOptions = append(cloudOptions, aws.WithControlPlaneSecurityGroup(config.ControlPlaneSecurityGroup))
}

if config.WorkerSecurityGroup != "" {
cloudOptions = append(cloudOptions, aws.WithWorkerSecurityGroup(config.WorkerSecurityGroup))
}

if config.VpcName != "" {
cloudOptions = append(cloudOptions, aws.WithVPCName(config.VpcName))
}

if len(config.SubnetNames) > 0 {
cloudOptions = append(cloudOptions, aws.WithPublicSubnetList(config.SubnetNames))
}

awsCloud, err := aws.NewCloudFromSettings(
config.CredentialsFile,
config.Profile,
config.InfraID,
config.Region,
cloudOptions...,
)

status.End()

restMapper, err := util.BuildRestMapper(clusterInfo.RestConfig)
Expand Down

0 comments on commit 2e112e9

Please sign in to comment.