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 1, 2024
1 parent 8e2a339 commit 1afdb8f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 58 deletions.
12 changes: 6 additions & 6 deletions cmd/rosa-support/create/proxy/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var Cmd = &cobra.Command{
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> --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",
"",
"",
"Creates a proxy in the indicated zone",
"Creates a proxy in the indicated zone (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 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
81 changes: 31 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
zones 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>`,

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.zones,
"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",
"Zones to create subnets in",
)
err = Cmd.MarkFlagRequired("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,14 @@ 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)
zones := strings.Split(args.zones, ",")
for _, zone := range zones {
subnetMap, err := vpc.PreparePairSubnetByZone(zone)
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("ZONE %s %s SUBNET: %s", zone, 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 1afdb8f

Please sign in to comment.