Skip to content

Commit

Permalink
OCM-7805 | fix: Replace subnets command with correct command; improve…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
hunterkepley committed May 2, 2024
1 parent 5ce12b3 commit 6eed883
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 69 deletions.
34 changes: 17 additions & 17 deletions cmd/rosa-support/create/proxy/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ import (
)

var args struct {
region string
vpcID string
zone string
imageID string
privateKeyPath string
keyPairName string
caFilePath string
region string
vpcID string
availabilityZone string
imageID string
privateKeyPath string
keyPairName string
caFilePath string
}

var Cmd = &cobra.Command{
Use: "proxy",
Short: "Create proxy",
Long: "Create proxy.",
Example: ` # Create a proxy
rosa-helper create proxy --region us-east-2 --vpc-id <vpc id>`,
rosa-support create proxy --region us-east-2 --vpc-id <vpc id> --availability-zone <AZ> --ca-file <filepath> --keypair-name <name>`,
Run: run,
}

Expand All @@ -37,21 +37,21 @@ func init() {
"region",
"",
"",
"Vpc region",
"Vpc region (required)",
)
flags.StringVarP(
&args.vpcID,
"vpc-id",
"",
"",
"Creates a pair of subnets",
"Creates a pair of subnets (required)",
)
flags.StringVarP(
&args.zone,
"zone",
&args.availabilityZone,
"availability-zone",
"",
"",
"Creates a proxy in the indicated zone",
"Creates a proxy in the indicated AZ (required)",
)
flags.StringVarP(
&args.imageID,
Expand All @@ -66,15 +66,15 @@ func init() {
"ca-file",
"",
"",
"Creates a proxy and stores the ca file",
"Creates a proxy and stores the ca file (required)",
)

flags.StringVarP(
&args.keyPairName,
"keypair-name",
"",
"",
"Stores key pair in the given path",
"Stores key pair in the given path (required)",
)

err := Cmd.MarkFlagRequired("vpc-id")
Expand All @@ -87,7 +87,7 @@ func init() {
logger.LogError(err.Error())
os.Exit(1)
}
err = Cmd.MarkFlagRequired("zone")
err = Cmd.MarkFlagRequired("availability-zone")
if err != nil {
logger.LogError(err.Error())
os.Exit(1)
Expand All @@ -109,7 +109,7 @@ func run(cmd *cobra.Command, _ []string) {
if err != nil {
panic(err)
}
_, ip, ca, err := vpc.LaunchProxyInstance(args.imageID, args.zone, args.keyPairName)
_, ip, ca, err := vpc.LaunchProxyInstance(args.imageID, args.availabilityZone, args.keyPairName)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/rosa-support/create/sg/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var Cmd = &cobra.Command{
Short: "Create security-groups",
Long: "Create security-groups.",
Example: `# Create a number of security groups"
rosa-helper create security-groups --name-prefix=mysg --region us-east-2 --vpc-id <vpc id>`,
rosa-support create security-groups --name-prefix=mysg --region us-east-2 --vpc-id <vpc id>`,

Run: run,
}
Expand Down
82 changes: 32 additions & 50 deletions cmd/rosa-support/create/subnets/cmd.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sg
package subnets

import (
"fmt"
"os"
"strings"

Expand All @@ -12,19 +11,18 @@ import (
)

var args struct {
region string
count int
vpcID string
tags string
namePrefix string
region string
availabilityZones string
vpcID string
tags string
}

var Cmd = &cobra.Command{
Use: "security-groups",
Short: "Create security-groups",
Long: "Create security-groups.",
Example: `# Create a number of security groups"
rosa-helper create security-groups --name-prefix=mysg --region us-east-2 --vpc-id <vpc id>`,
Use: "subnets",
Short: "Create subnets",
Long: "Create subnets.",
Example: ` # Create a pair of subnets with prefix 'mysubnet-' in region 'us-east-2'
rosa-support create subnets --name-prefix=mysubnet --region us-east-2 --vpc-id <vpc id> --availability-zones <AZs>`,

Run: run,
}
Expand All @@ -37,36 +35,33 @@ func init() {
"region",
"",
"",
"Region of the security groups",
"Vpc region",
)
err := Cmd.MarkFlagRequired("region")
if err != nil {
logger.LogError(err.Error())
os.Exit(1)
}
flags.StringVarP(
&args.namePrefix,
"name-prefix",
&args.availabilityZones,
"availability-zones",
"",
"",
"Name prefix of the security groups, they will be named with <prefix>-0,<prefix>-1",
)

flags.IntVarP(
&args.count,
"count",
"",
0,
"Additional number of security groups to be created for the vpc",
"Availability zones to create subnets in",
)
err = Cmd.MarkFlagRequired("availability-zones")
if err != nil {
logger.LogError(err.Error())
os.Exit(1)
}
flags.StringVarP(
&args.vpcID,
"vpc-id",
"",
"",
"Vpc ID for the VPC created for the additional security groups",
"ID of vpc to be created",
)
err := Cmd.MarkFlagRequired("vpc-id")
if err != nil {
logger.LogError(err.Error())
os.Exit(1)
}
err = Cmd.MarkFlagRequired("region")
err = Cmd.MarkFlagRequired("vpc-id")
if err != nil {
logger.LogError(err.Error())
os.Exit(1)
Expand All @@ -77,28 +72,15 @@ func run(cmd *cobra.Command, _ []string) {
if err != nil {
panic(err)
}
preparedSGs := []string{}
sgDescription := "This security group is created for OCM testing"
protocol := "tcp"
for i := 0; i < args.count; i++ {
sgName := fmt.Sprintf("%s-%d", args.namePrefix, i)
sg, err := vpc.AWSClient.CreateSecurityGroup(vpc.VpcID, sgName, sgDescription)
availabilityZones := strings.Split(args.availabilityZones, ",")
for _, availabilityZone := range availabilityZones {
subnetMap, err := vpc.PreparePairSubnetByZone(availabilityZone)
if err != nil {
panic(err)
}
groupID := *sg.GroupId
cidrPortsMap := map[string]int32{
vpc.CIDRValue: 8080,
"0.0.0.0/0": 22,
for subnetType, subnet := range subnetMap {
logger.LogInfo("AVAILABILITY ZONE %s %s SUBNET: %s", availabilityZone, strings.ToUpper(subnetType),
subnet.ID)
}
for cidr, port := range cidrPortsMap {
_, err = vpc.AWSClient.AuthorizeSecurityGroupIngress(groupID, cidr, protocol, port, port)
if err != nil {
panic(err)
}
}

preparedSGs = append(preparedSGs, groupID)
}
logger.LogInfo("ADDITIONAL SECURITY GROUPS: %s", strings.Join(preparedSGs, ","))
}
2 changes: 1 addition & 1 deletion cmd/rosa-support/create/vpc/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var Cmd = &cobra.Command{
Short: "Create vpc",
Long: "Create vpc.",
Example: ` # Create a vpc named "myvpc"
rosa-helper create vpc --name=myvpc --region us-east-2`,
rosa-support create vpc --name=myvpc --region us-east-2`,

Run: run,
}
Expand Down

0 comments on commit 6eed883

Please sign in to comment.