Skip to content

Commit

Permalink
Merge pull request #1950 from chenz4027/OCM-1308
Browse files Browse the repository at this point in the history
OCM-1308 | fix: filter empty subnet id
  • Loading branch information
openshift-merge-bot[bot] authored Apr 24, 2024
2 parents 8d577cb + 23192dc commit 9dea294
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cmd/create/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2058,9 +2058,9 @@ func run(cmd *cobra.Command, _ []string) {
}

// Subnet IDs
subnetIDs := args.subnetIDs
subnetIDs := helper.FilterEmptyStrings(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 " +
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -2205,7 +2205,7 @@ func run(cmd *cobra.Command, _ []string) {
}
}

// Validate subnets in the case the user has provided them using the `args.subnets`
// Validate subnets in the case the user has provided them using the `args.subnetIDs`
if useExistingVPC || subnetsProvided {
if !isHostedCP {
err = ocm.ValidateSubnetsCount(multiAZ, privateLink, len(subnetIDs))
Expand Down
10 changes: 10 additions & 0 deletions pkg/helper/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,13 @@ func ChunkSlice[T any](slice []T, chunkSize int) [][]T {
func IsBYOVPC(cluster *cmv1.Cluster) bool {
return len(cluster.AWS().SubnetIDs()) > 0
}

func FilterEmptyStrings(strings []string) []string {
var filteredResult []string
for _, str := range strings {
if str != "" {
filteredResult = append(filteredResult, str)
}
}
return filteredResult
}
8 changes: 8 additions & 0 deletions pkg/helper/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,13 @@ var _ = Describe("Helper", func() {
Entry("Uses the first 27 characters of the cluster name when the cluster name is > 27 chars",
strings.Repeat("a", 54), strings.Repeat("a", 27)))
})

var _ = Context("FilterEmptyStrings()", func() {
It("OK: get filters subnets", func() {
subnets := []string{"test1", "test2", ""}
filteredSubnets := FilterEmptyStrings(subnets)
Expect(filteredSubnets).To(Equal([]string{"test1", "test2"}))
})
})
})
})

0 comments on commit 9dea294

Please sign in to comment.