From fc35cd4dddc3254b5894bf0a3c47c7d08bb528a2 Mon Sep 17 00:00:00 2001 From: Maggie Chen Date: Fri, 19 Apr 2024 13:43:40 -0400 Subject: [PATCH] OCM-1308 | fix: filter empty subnet id Signed-off-by: Maggie Chen add test Signed-off-by: Maggie Chen --- cmd/create/cluster/cmd.go | 16 +++++++++++++--- cmd/create/cluster/cmd_test.go | 8 ++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cmd/create/cluster/cmd.go b/cmd/create/cluster/cmd.go index accd7b25c0..9f7e77637c 100644 --- a/cmd/create/cluster/cmd.go +++ b/cmd/create/cluster/cmd.go @@ -2058,9 +2058,9 @@ func run(cmd *cobra.Command, _ []string) { } // Subnet IDs - subnetIDs := args.subnetIDs + subnetIDs := delete_empty(args.subnetIDs) subnetsProvided := len(subnetIDs) > 0 - r.Reporter.Debugf("Received the following subnetIDs: %v", args.subnetIDs) + r.Reporter.Debugf("Received the following subnetIDs: %v", subnetIDs) // If the user has set the availability zones (allowed for non-BYOVPC clusters), don't prompt the BYOVPC message if !useExistingVPC && !subnetsProvided && !isAvailabilityZonesSet && interactive.Enabled() { existingVPCHelp := "To install into an existing VPC you need to ensure that your VPC is configured " + @@ -2092,7 +2092,7 @@ func run(cmd *cobra.Command, _ []string) { var subnets []ec2types.Subnet mapSubnetIDToSubnet := make(map[string]aws.Subnet) if useExistingVPC || subnetsProvided { - initialSubnets, err := getInitialValidSubnets(awsClient, args.subnetIDs, r.Reporter) + initialSubnets, err := getInitialValidSubnets(awsClient, subnetIDs, r.Reporter) if err != nil { r.Reporter.Errorf("Failed to get the list of subnets: %s", err) os.Exit(1) @@ -4134,3 +4134,13 @@ func getMachinePoolRootDisk(r *rosa.Runtime, cmd *cobra.Command, version string, func clusterHasLongNameWithoutDomainPrefix(clusterName, domainPrefix string) bool { return domainPrefix == "" && len(clusterName) > ocm.MaxClusterDomainPrefixLength } + +func delete_empty(s []string) []string { + var r []string + for _, str := range s { + if str != "" { + r = append(r, str) + } + } + return r +} diff --git a/cmd/create/cluster/cmd_test.go b/cmd/create/cluster/cmd_test.go index ecca2f3321..9d44e7e9ad 100644 --- a/cmd/create/cluster/cmd_test.go +++ b/cmd/create/cluster/cmd_test.go @@ -498,6 +498,14 @@ var _ = Describe("clusterHasLongNameWithoutDomainPrefix()", func() { ) }) +var _ = Describe("delete_empty()", func() { + It("OK: get filters subnets", func() { + subnets := []string{"test1", "test2", ""} + filteredSubnets := delete_empty(subnets) + Expect(filteredSubnets).To(Equal([]string{"test1", "test2"})) + }) +}) + func mustParseCIDR(s string) *net.IPNet { _, ipnet, err := net.ParseCIDR(s) Expect(err).To(BeNil())