Skip to content

Commit

Permalink
Refactored cpd.go
Browse files Browse the repository at this point in the history
  • Loading branch information
aliceh committed May 15, 2024
1 parent c0786da commit 7b068e4
Showing 1 changed file with 2 additions and 26 deletions.
28 changes: 2 additions & 26 deletions cmd/cluster/cpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cluster
import (
"context"
"fmt"

"github.com/aws/aws-sdk-go-v2/aws/arn"
sdk "github.com/openshift-online/ocm-sdk-go"
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
Expand Down Expand Up @@ -165,7 +166,7 @@ func isSubnetRouteValid(awsClient aws.Client, subnetID string) (bool, error) {
vpcID := *describeSubnetOutput.Subnets[0].VpcId

// Set the route table to the default for the VPC
routeTable, err = findDefaultRouteTableForVPC(awsClient, vpcID)
routeTable, err = utils.FindRouteTableForSubnet(awsClient, vpcID)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -198,31 +199,6 @@ func isSubnetRouteValid(awsClient aws.Client, subnetID string) (bool, error) {
return false, nil
}

// findDefaultRouteTableForVPC returns the AWS Route Table ID of the VPC's default Route Table
func findDefaultRouteTableForVPC(awsClient aws.Client, vpcID string) (string, error) {
describeRouteTablesOutput, err := awsClient.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
Filters: []types.Filter{
{
Name: awsSdk.String("vpc-id"),
Values: []string{vpcID},
},
},
})
if err != nil {
return "", fmt.Errorf("failed to describe route tables associated with vpc %s: %w", vpcID, err)
}

for _, rt := range describeRouteTablesOutput.RouteTables {
for _, assoc := range rt.Associations {
if *assoc.Main {
return *rt.RouteTableId, nil
}
}
}

return "", fmt.Errorf("no default route table found for vpc: %s", vpcID)
}

func isIsolatedBackplaneAccess(cluster *cmv1.Cluster, ocmConnection *sdk.Connection) (bool, error) {
if cluster.Hypershift().Enabled() {
return true, nil
Expand Down

0 comments on commit 7b068e4

Please sign in to comment.