Skip to content

Commit df82d14

Browse files
Merge pull request #539 from AlexVulaj/cpd-no-isolated-backplane
Add error message if running against cluster using isolated backplane flow
2 parents 981cb82 + 558be4e commit df82d14

File tree

1 file changed

+56
-23
lines changed

1 file changed

+56
-23
lines changed

cmd/cluster/cpd.go

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ package cluster
33
import (
44
"context"
55
"fmt"
6+
"github.com/aws/aws-sdk-go-v2/aws/arn"
7+
sdk "github.com/openshift-online/ocm-sdk-go"
8+
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
9+
"github.com/openshift/backplane-cli/pkg/ocm"
610

711
awsSdk "github.com/aws/aws-sdk-go-v2/aws"
812
"github.com/aws/aws-sdk-go-v2/service/ec2"
@@ -34,6 +38,7 @@ Helps investigate OSD/ROSA cluster provisioning delays (CPD) or failures
3438
# Investigate a CPD for a cluster using an AWS profile named "rhcontrol"
3539
osdctl cluster cpd --cluster-id 1kfmyclusteristhebesteverp8m --profile rhcontrol
3640
`
41+
OldFlowSupportRole = "role/RH-Technical-Support-Access"
3742
)
3843

3944
func newCmdCpd() *cobra.Command {
@@ -89,32 +94,38 @@ func (o *cpdOptions) run() error {
8994
return fmt.Errorf("this command doesn't support GCP yet. Needs manual investigation:\nocm backplane cloud console -b %s", o.clusterID)
9095
}
9196

92-
fmt.Println("Generating AWS credentials for cluster")
93-
// Get AWS credentials for the cluster
94-
awsClient, err := osdCloud.GenerateAWSClientForCluster(o.awsProfile, o.clusterID)
95-
if err != nil {
96-
fmt.Println("PLEASE CONFIRM YOUR CREDENTIALS ARE CORRECT. If you're absolutely sure they are, send this Service Log https://github.com/openshift/managed-notifications/blob/master/osd/aws/ROSA_AWS_invalid_permissions.json")
97-
fmt.Println(err)
98-
return err
99-
}
97+
if isolated, err := isIsolatedBackplaneAccess(cluster, ocmClient); err != nil {
98+
return fmt.Errorf("unable to determine which backplane flow this cluster is using: %w.\nNeeds manual investigation:\nocm backplane cloud console -b %s", err, o.clusterID)
99+
} else if isolated {
100+
return fmt.Errorf("this command doesn't support the isolated backplane flow yet. Needs manual investigation:\nocm backplane cloud console -b %s", o.clusterID)
101+
} else {
102+
fmt.Println("Generating AWS credentials for cluster")
103+
// Get AWS credentials for the cluster
104+
awsClient, err := osdCloud.GenerateAWSClientForCluster(o.awsProfile, o.clusterID)
105+
if err != nil {
106+
fmt.Println("PLEASE CONFIRM YOUR CREDENTIALS ARE CORRECT. If you're absolutely sure they are, send this Service Log https://github.com/openshift/managed-notifications/blob/master/osd/aws/ROSA_AWS_invalid_permissions.json")
107+
fmt.Println(err)
108+
return err
109+
}
100110

101-
// If the cluster is BYOVPC, check the route tables
102-
// This check is copied from ocm-cli
103-
if cluster.AWS().SubnetIDs() != nil && len(cluster.AWS().SubnetIDs()) > 0 {
104-
fmt.Println("Checking BYOVPC to ensure subnets have valid routing")
105-
for _, subnet := range cluster.AWS().SubnetIDs() {
106-
isValid, err := isSubnetRouteValid(awsClient, subnet)
107-
if err != nil {
108-
return err
109-
}
110-
if !isValid {
111-
return fmt.Errorf("subnet %s does not have a default route to 0.0.0.0/0\n Run the following to send a SerivceLog:\n osdctl servicelog post %s -t https://raw.githubusercontent.com/openshift/managed-notifications/master/osd/aws/InstallFailed_NoRouteToInternet.json", subnet, o.clusterID)
111+
// If the cluster is BYOVPC, check the route tables
112+
// This check is copied from ocm-cli
113+
if cluster.AWS().SubnetIDs() != nil && len(cluster.AWS().SubnetIDs()) > 0 {
114+
fmt.Println("Checking BYOVPC to ensure subnets have valid routing")
115+
for _, subnet := range cluster.AWS().SubnetIDs() {
116+
isValid, err := isSubnetRouteValid(awsClient, subnet)
117+
if err != nil {
118+
return err
119+
}
120+
if !isValid {
121+
return fmt.Errorf("subnet %s does not have a default route to 0.0.0.0/0\n Run the following to send a SerivceLog:\n osdctl servicelog post %s -t https://raw.githubusercontent.com/openshift/managed-notifications/master/osd/aws/InstallFailed_NoRouteToInternet.json", subnet, o.clusterID)
122+
}
112123
}
124+
fmt.Printf("Attempting to run: osdctl network verify-egress --cluster-id %s\n", o.clusterID)
125+
ev := &network.EgressVerification{ClusterId: o.clusterID}
126+
ev.Run(context.TODO())
127+
return nil
113128
}
114-
fmt.Printf("Attempting to run: osdctl network verify-egress --cluster-id %s\n", o.clusterID)
115-
ev := &network.EgressVerification{ClusterId: o.clusterID}
116-
ev.Run(context.TODO())
117-
return nil
118129
}
119130

120131
fmt.Println("Next step: check the AWS resources manually, run ocm backplane cloud console")
@@ -211,3 +222,25 @@ func findDefaultRouteTableForVPC(awsClient aws.Client, vpcID string) (string, er
211222

212223
return "", fmt.Errorf("no default route table found for vpc: %s", vpcID)
213224
}
225+
226+
func isIsolatedBackplaneAccess(cluster *cmv1.Cluster, ocmConnection *sdk.Connection) (bool, error) {
227+
if cluster.Hypershift().Enabled() {
228+
return true, nil
229+
}
230+
231+
if cluster.AWS().STS().Enabled() {
232+
stsSupportJumpRole, err := ocm.DefaultOCMInterface.GetStsSupportJumpRoleARN(ocmConnection, cluster.ID())
233+
if err != nil {
234+
return false, fmt.Errorf("failed to get sts support jump role ARN for cluster %v: %w", cluster.ID(), err)
235+
}
236+
supportRoleArn, err := arn.Parse(stsSupportJumpRole)
237+
if err != nil {
238+
return false, fmt.Errorf("failed to parse ARN for jump role %v: %w", stsSupportJumpRole, err)
239+
}
240+
if supportRoleArn.Resource != OldFlowSupportRole {
241+
return true, nil
242+
}
243+
}
244+
245+
return false, nil
246+
}

0 commit comments

Comments
 (0)