Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCM-1308 | fix: filter empty subnet id #1950

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"}))
})
})
})
})