Skip to content

Commit 4064438

Browse files
authored
Merge branch 'master' into OSD-28396
2 parents 0e5d1bb + 57a742d commit 4064438

File tree

10 files changed

+710
-86
lines changed

10 files changed

+710
-86
lines changed

cmd/cluster/context.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/openshift/osdctl/pkg/utils"
3030
"github.com/spf13/cobra"
3131
"github.com/spf13/viper"
32-
cmdutil "k8s.io/kubectl/pkg/cmd/util"
3332
)
3433

3534
const (
@@ -166,14 +165,17 @@ func newCmdContext() *cobra.Command {
166165
Short: "Shows the context of a specified cluster",
167166
Args: cobra.ExactArgs(1),
168167
DisableAutoGenTag: true,
169-
Run: func(cmd *cobra.Command, args []string) {
170-
cmdutil.CheckErr(ops.complete(cmd, args))
171-
cmdutil.CheckErr(ops.run())
168+
RunE: func(cmd *cobra.Command, args []string) error {
169+
err := ops.setup(args)
170+
if err != nil {
171+
return err
172+
}
173+
174+
return ops.run()
172175
},
173176
}
174177

175178
contextCmd.Flags().StringVarP(&ops.output, "output", "o", "long", "Valid formats are ['long', 'short', 'json']. Output is set to 'long' by default")
176-
contextCmd.Flags().StringVarP(&ops.clusterID, "cluster-id", "C", "", "Cluster ID")
177179
contextCmd.Flags().StringVarP(&ops.awsProfile, "profile", "p", "", "AWS Profile")
178180
contextCmd.Flags().BoolVarP(&ops.verbose, "verbose", "", false, "Verbose output")
179181
contextCmd.Flags().BoolVar(&ops.full, "full", false, "Run full suite of checks.")
@@ -195,11 +197,8 @@ func newContextOptions() *ContextOptions {
195197
}
196198
}
197199

198-
func (o *ContextOptions) complete(cmd *cobra.Command, args []string) error {
199-
if len(args) != 1 {
200-
return cmdutil.UsageErrorf(cmd, "Provide exactly one cluster ID")
201-
}
202200

201+
func (o *ContextOptions) setup(args []string) error {
203202
if o.days < 1 {
204203
return fmt.Errorf("cannot have a days value lower than 1")
205204
}

cmd/cluster/cpd.go

Lines changed: 38 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import (
99
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
1010
"github.com/openshift/backplane-cli/pkg/ocm"
1111

12-
awsSdk "github.com/aws/aws-sdk-go-v2/aws"
1312
"github.com/aws/aws-sdk-go-v2/service/ec2"
14-
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
1513
"github.com/openshift/osdctl/cmd/network"
1614
"github.com/openshift/osdctl/pkg/osdCloud"
1715
"github.com/openshift/osdctl/pkg/provider/aws"
@@ -95,38 +93,44 @@ func (o *cpdOptions) run() error {
9593
return fmt.Errorf("this command doesn't support GCP yet. Needs manual investigation:\nocm backplane cloud console -b %s", o.clusterID)
9694
}
9795

98-
if isolated, err := isIsolatedBackplaneAccess(cluster, ocmClient); err != nil {
99-
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)
100-
} else if isolated {
101-
return fmt.Errorf("this command doesn't support the isolated backplane flow yet. Needs manual investigation:\nocm backplane cloud console -b %s", o.clusterID)
102-
} else {
103-
fmt.Println("Generating AWS credentials for cluster")
104-
// Get AWS credentials for the cluster
105-
awsClient, err := osdCloud.GenerateAWSClientForCluster(o.awsProfile, o.clusterID)
106-
if err != nil {
107-
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")
108-
fmt.Println(err)
109-
return err
110-
}
96+
awsv2cfg, err := osdCloud.CreateAWSV2Config(ocmClient, cluster)
97+
if err != nil {
98+
return fmt.Errorf("failed to build aws client config: %w\nManual investigation required", err)
99+
}
100+
creds, err := awsv2cfg.Credentials.Retrieve(context.Background())
101+
if err != nil {
102+
return fmt.Errorf("failed to retrieve aws credentials: %w\nManual investigation required", err)
103+
}
104+
awsClient, err := aws.NewAwsClientWithInput(&aws.ClientInput{
105+
AccessKeyID: creds.AccessKeyID,
106+
SecretAccessKey: creds.SecretAccessKey,
107+
SessionToken: creds.SessionToken,
108+
Region: cluster.Region().ID(),
109+
})
110+
if err != nil {
111+
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")
112+
fmt.Println(err)
113+
return err
114+
}
111115

112-
// If the cluster is BYOVPC, check the route tables
113-
// This check is copied from ocm-cli
114-
if cluster.AWS().SubnetIDs() != nil && len(cluster.AWS().SubnetIDs()) > 0 {
115-
fmt.Println("Checking BYOVPC to ensure subnets have valid routing")
116-
for _, subnet := range cluster.AWS().SubnetIDs() {
117-
isValid, err := isSubnetRouteValid(awsClient, subnet)
118-
if err != nil {
119-
return err
120-
}
121-
if !isValid {
122-
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)
123-
}
116+
// If the cluster is BYOVPC, check the route tables
117+
// This check is copied from ocm-cli
118+
if cluster.AWS().SubnetIDs() != nil && len(cluster.AWS().SubnetIDs()) > 0 {
119+
fmt.Println("Checking BYOVPC to ensure subnets have valid routing")
120+
for _, subnet := range cluster.AWS().SubnetIDs() {
121+
fmt.Printf("subnet: %v\n", subnet)
122+
isValid, err := isSubnetRouteValid(awsClient, subnet)
123+
if err != nil {
124+
return err
125+
}
126+
if !isValid {
127+
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)
124128
}
125-
fmt.Printf("Attempting to run: osdctl network verify-egress --cluster-id %s\n", o.clusterID)
126-
ev := &network.EgressVerification{ClusterId: o.clusterID}
127-
ev.Run(context.TODO())
128-
return nil
129129
}
130+
fmt.Printf("Attempting to run: osdctl network verify-egress --cluster-id %s\n", o.clusterID)
131+
ev := &network.EgressVerification{ClusterId: o.clusterID}
132+
ev.Run(context.Background())
133+
return nil
130134
}
131135

132136
fmt.Println("Next step: check the AWS resources manually, run ocm backplane cloud console")
@@ -135,45 +139,13 @@ func (o *cpdOptions) run() error {
135139
}
136140

137141
func isSubnetRouteValid(awsClient aws.Client, subnetID string) (bool, error) {
138-
var routeTable string
139-
140-
// Try and find a Route Table associated with the given subnet
141-
describeRouteTablesOutput, err := awsClient.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
142-
Filters: []types.Filter{
143-
{
144-
Name: awsSdk.String("association.subnet-id"),
145-
Values: []string{subnetID},
146-
},
147-
},
148-
})
142+
routeTable, err := utils.FindRouteTableForSubnet(awsClient, subnetID)
149143
if err != nil {
150-
return false, fmt.Errorf("failed to describe route tables associated to subnet %s: %w", subnetID, err)
151-
}
152-
153-
// If there are no associated RouteTables, then the subnet uses the default RoutTable for the VPC
154-
if len(describeRouteTablesOutput.RouteTables) == 0 {
155-
// Get the VPC ID for the subnet
156-
describeSubnetOutput, err := awsClient.DescribeSubnets(&ec2.DescribeSubnetsInput{
157-
SubnetIds: []string{subnetID},
158-
})
159-
if err != nil {
160-
return false, err
161-
}
162-
if len(describeSubnetOutput.Subnets) == 0 {
163-
return false, fmt.Errorf("no subnets returned for subnet id %v", subnetID)
164-
}
165-
166-
vpcID := *describeSubnetOutput.Subnets[0].VpcId
167-
168-
// Set the route table to the default for the VPC
169-
routeTable, err = utils.FindRouteTableForSubnet(awsClient, vpcID)
170-
if err != nil {
171-
return false, err
172-
}
144+
return false, fmt.Errorf("failed to find routetable for subnet: %w", err)
173145
}
174146

175147
// Check that the RouteTable for the subnet has a default route to 0.0.0.0/0
176-
describeRouteTablesOutput, err = awsClient.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
148+
describeRouteTablesOutput, err := awsClient.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
177149
RouteTableIds: []string{routeTable},
178150
})
179151
if err != nil {

cmd/promote/cmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package promote
33
import (
44
"fmt"
55

6+
"github.com/openshift/osdctl/cmd/promote/dynatrace"
67
"github.com/openshift/osdctl/cmd/promote/pko"
78
"github.com/openshift/osdctl/cmd/promote/saas"
89
"github.com/spf13/cobra"
@@ -19,6 +20,7 @@ func NewCmdPromote() *cobra.Command {
1920

2021
promoteCmd.AddCommand(saas.NewCmdSaas())
2122
promoteCmd.AddCommand(pko.NewCmdPKO())
23+
promoteCmd.AddCommand(dynatrace.NewCmdDynatrace())
2224

2325
return promoteCmd
2426
}

0 commit comments

Comments
 (0)