Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated backport of #1230: Add custom vpc support in AWS cloud prepare #1233

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.0
github.com/spf13/pflag v1.0.5
github.com/submariner-io/admiral v0.18.0
github.com/submariner-io/cloud-prepare v0.18.0
github.com/submariner-io/cloud-prepare v0.18.1-0.20240926141430-b73b84732e47
github.com/submariner-io/lighthouse v0.18.0
github.com/submariner-io/shipyard v0.18.0
github.com/submariner-io/submariner v0.18.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@ github.com/submariner-io/admiral v0.18.0 h1:f8+owedukeKjwNazwmQScJjP3wXkEB+FqEJQ
github.com/submariner-io/admiral v0.18.0/go.mod h1:Xy24HCHRsq+LUSyuQh0pLgKFpAFyPhuzcPRUyUlL30s=
github.com/submariner-io/cloud-prepare v0.18.0 h1:o9w6xKwzU0mhZrVGoaw0GXsvr/5f6P6c14DnNVLspJI=
github.com/submariner-io/cloud-prepare v0.18.0/go.mod h1:zxzSHoJpLH5C0rZV8tqxAIyJ27iS21VMJvc06RBzzVw=
github.com/submariner-io/cloud-prepare v0.18.1-0.20240926141430-b73b84732e47 h1:H+zFPcfvihetBc00wWCsNSi9MAXDfZxCZJ0ajUnnCF0=
github.com/submariner-io/cloud-prepare v0.18.1-0.20240926141430-b73b84732e47/go.mod h1:zxzSHoJpLH5C0rZV8tqxAIyJ27iS21VMJvc06RBzzVw=
github.com/submariner-io/lighthouse v0.18.0 h1:5hWXQBDduJqY+reheP24Ue7HPedVoWaIJjVn5OMEXkU=
github.com/submariner-io/lighthouse v0.18.0/go.mod h1:xkvjJT46XvR77HMw2srnytWJEMGyfP4lDPC5oNtuqho=
github.com/submariner-io/shipyard v0.18.0 h1:bBvqho5UtEplMhyxX2YhEC4DzjrfWTqF8KOGblaDJJw=
Expand Down
46 changes: 37 additions & 9 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,9 +61,33 @@ 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)
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...,
)
if err != nil {
return status.Error(err, "error loading default config")
return status.Error(err, "error creating cloud object from settings")
}

status.End()
Expand Down
Loading