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 <[email protected]>
  • Loading branch information
aswinsuryan authored and tpantelis committed Oct 8, 2024
1 parent e9c2229 commit 9a26adb
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 27 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
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ require (
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/submariner-io/admiral v0.17.2
github.com/submariner-io/cloud-prepare v0.17.2
github.com/submariner-io/cloud-prepare v0.17.3-0.20241008120503-cf65423281fa
github.com/submariner-io/lighthouse v0.17.2
github.com/submariner-io/shipyard v0.17.2
github.com/submariner-io/submariner v0.17.2
github.com/submariner-io/submariner-operator v0.17.3-0.20240709140014-b957cc9ca3c3
github.com/submariner-io/submariner-operator v0.17.3-0.20241001091116-ab7ece93bee9
github.com/uw-labs/lichen v0.1.7
golang.org/x/net v0.23.0
golang.org/x/oauth2 v0.16.0
google.golang.org/api v0.154.0
k8s.io/api v0.29.6
k8s.io/apiextensions-apiserver v0.29.6
k8s.io/apimachinery v0.29.6
k8s.io/client-go v0.29.6
k8s.io/api v0.29.9
k8s.io/apiextensions-apiserver v0.29.9
k8s.io/apimachinery v0.29.9
k8s.io/client-go v0.29.9
k8s.io/utils v0.0.0-20231127182322-b307cd553661
sigs.k8s.io/controller-runtime v0.17.0
sigs.k8s.io/mcs-api v0.1.0
Expand Down
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -528,16 +528,16 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/submariner-io/admiral v0.17.2 h1:GjhVcJXC+fZ0igkSRihJKRypNQ3joI91pZIcOpiQmGU=
github.com/submariner-io/admiral v0.17.2/go.mod h1:WZbjUAVf+tlQnLuvTIzHiF5gNkrD52rIhvuSxm2P2wM=
github.com/submariner-io/cloud-prepare v0.17.2 h1:bZAlgiQRnqn2fHydvspaIV+eOkugvhrkB/yKkDOtUy0=
github.com/submariner-io/cloud-prepare v0.17.2/go.mod h1:SXLXDIBfz7nOyCssOxvWZUKko6/FcfJb/r6nOsDrMwM=
github.com/submariner-io/cloud-prepare v0.17.3-0.20241008120503-cf65423281fa h1:EQ6ukgn/1UuWF1vgX6upery7T4eL8ufC/ZvsKlEEtvQ=
github.com/submariner-io/cloud-prepare v0.17.3-0.20241008120503-cf65423281fa/go.mod h1:SXLXDIBfz7nOyCssOxvWZUKko6/FcfJb/r6nOsDrMwM=
github.com/submariner-io/lighthouse v0.17.2 h1:YfQkzzB5pakXWGIUaGR7V5/baizpQCJC4onD8620A8o=
github.com/submariner-io/lighthouse v0.17.2/go.mod h1:1wcWMnG3UO2RKxYrCxSfK7YSSKjEsqL4EAnrQvRV7QU=
github.com/submariner-io/shipyard v0.17.2 h1:+ev89enbv98uP6BgrIRyVoyXYqOD/+9o49ELjtPugio=
github.com/submariner-io/shipyard v0.17.2/go.mod h1:Mrp0LPXBXYpbjMwhqq89G86Xgjz+U4vZM9Qg+F1ZBQw=
github.com/submariner-io/submariner v0.17.2 h1:6kyT5cJk+4+PzBxcsCbd5sFtkdxE34j/uHMaQCKqUtA=
github.com/submariner-io/submariner v0.17.2/go.mod h1:zbM5q83U7gkuty+fTJm7Dj1/lzfR4bBgKwQIPn0bY88=
github.com/submariner-io/submariner-operator v0.17.3-0.20240709140014-b957cc9ca3c3 h1:zeC3KgkAEst9vR6ng+VlEiHoqxq9fzMoKaKwL/ApNrE=
github.com/submariner-io/submariner-operator v0.17.3-0.20240709140014-b957cc9ca3c3/go.mod h1:PoSGGrq810UdJwNmQC5LswOZ82zR7nMvoTOF5ZzZZqg=
github.com/submariner-io/submariner-operator v0.17.3-0.20241001091116-ab7ece93bee9 h1:RW6N43qMoXe1+lQ8hQz5NBtwnwg+PBghkcZKlZvUvQM=
github.com/submariner-io/submariner-operator v0.17.3-0.20241001091116-ab7ece93bee9/go.mod h1:PSkOkRNgG6CaR8aFSHb0emF+S7ktyszfd0USU5+MdYE=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down Expand Up @@ -804,22 +804,22 @@ honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/api v0.18.2/go.mod h1:SJCWI7OLzhZSvbY7U8zwNl9UA4o1fizoug34OV/2r78=
k8s.io/api v0.18.4/go.mod h1:lOIQAKYgai1+vz9J7YcDZwC26Z0zQewYOGWdyIPUUQ4=
k8s.io/api v0.29.6 h1:eDxIl8+PeEpwbe2YyS5RXJ9vdn4hnKWMBf4WUJP9DQM=
k8s.io/api v0.29.6/go.mod h1:ZuUPMhJV74DJXapldbg6upaHfiOjrBb+0ffUbBi1jaw=
k8s.io/api v0.29.9 h1:FwdflpNsfMUYUOblMZNWJ4K/q0OSL5A4jGa0iOgcJco=
k8s.io/api v0.29.9/go.mod h1:fNhmzRfKaSEHCmczA/jRx6CiDKhYOnFLJBERMJAXEk8=
k8s.io/apiextensions-apiserver v0.18.2/go.mod h1:q3faSnRGmYimiocj6cHQ1I3WpLqmDgJFlKL37fC4ZvY=
k8s.io/apiextensions-apiserver v0.18.4/go.mod h1:NYeyeYq4SIpFlPxSAB6jHPIdvu3hL0pc36wuRChybio=
k8s.io/apiextensions-apiserver v0.29.6 h1:tUu1N6Zt9GT8KVcPF5aGDqfISz1mveM4yFh7eL5bxmE=
k8s.io/apiextensions-apiserver v0.29.6/go.mod h1:iw1EbwZat08I219qrQKoFMHGo7J9KxPqMpVKxCbNbCs=
k8s.io/apiextensions-apiserver v0.29.9 h1:EB6RK06kFJjbzBwU1YiVznxrcgBE0hhDWt6EQQIcOy4=
k8s.io/apiextensions-apiserver v0.29.9/go.mod h1:jcaHG6R/bB1iU6XzC1DMhB1x2ktTJLt2KKpg6B65Z2c=
k8s.io/apimachinery v0.18.2/go.mod h1:9SnR/e11v5IbyPCGbvJViimtJ0SwHG4nfZFjU77ftcA=
k8s.io/apimachinery v0.18.4/go.mod h1:OaXp26zu/5J7p0f92ASynJa1pZo06YlV9fG7BoWbCko=
k8s.io/apimachinery v0.29.6 h1:CLjJ5b0hWW7531n/njRE3rnusw3rhVGCFftPfnG54CI=
k8s.io/apimachinery v0.29.6/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y=
k8s.io/apimachinery v0.29.9 h1:YZ8HUid1TzQVz94cnNlsQjLdH0VoAhWSqz7t0q6B12A=
k8s.io/apimachinery v0.29.9/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y=
k8s.io/apiserver v0.18.2/go.mod h1:Xbh066NqrZO8cbsoenCwyDJ1OSi8Ag8I2lezeHxzwzw=
k8s.io/apiserver v0.18.4/go.mod h1:q+zoFct5ABNnYkGIaGQ3bcbUNdmPyOCoEBcg51LChY8=
k8s.io/client-go v0.18.2/go.mod h1:Xcm5wVGXX9HAA2JJ2sSBUn3tCJ+4SVlCbl2MNNv+CIU=
k8s.io/client-go v0.18.4/go.mod h1:f5sXwL4yAZRkAtzOxRWUhA/N8XzGCb+nPZI8PfobZ9g=
k8s.io/client-go v0.29.6 h1:5E2ebuB/p0F0THuQatyvhDvPL2SIeqwTPrtnrwKob/8=
k8s.io/client-go v0.29.6/go.mod h1:jHZcrQqDplyv20v7eu+iFM4gTpglZSZoMVcKrh8sRGg=
k8s.io/client-go v0.29.9 h1:4f/Wz6li3rEyIPFj32XAQMtOGMM1tg7KQi1oeS6ibPg=
k8s.io/client-go v0.29.9/go.mod h1:2N1drQEZ5yiYrWVaE2Un8JiISUhl47D8pyZlYLszke4=
k8s.io/code-generator v0.18.2/go.mod h1:+UHX5rSbxmR8kzS+FAv7um6dtYrZokQvjHpDSYRVkTc=
k8s.io/code-generator v0.18.4/go.mod h1:TgNEVx9hCyPGpdtCWA34olQYLkh3ok9ar7XfSsr8b6c=
k8s.io/component-base v0.18.2/go.mod h1:kqLlMuhJNHQ9lz8Z7V5bxUUtjFZnrypArGl58gmDfUM=
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

0 comments on commit 9a26adb

Please sign in to comment.