Skip to content

CORS-4062: Migrate endpoints in pkg/types/aws/platform.go to sdk v2 #9759

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

barbacbd
Copy link
Contributor

pkg/types/aws:

** Remove the endpoints package from aws sdk v1.
** Remove the function to check for secret regions

pkg/asset/installconfig/aws:

** Add a function to check for secret regions.
** The function was moved here (and changed) because the types package should not make api calls. As we migrated to aws sdk v2 the partitions are no longer publicly available BUT we can access them through endpoints. To get the partition we go through the ec2 api (make a proxy call) and get the endpoint from that call then the endpoint will provide us with the partition.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label May 29, 2025
@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented May 29, 2025

@barbacbd: This pull request references CORS-4062 which is a valid jira issue.

In response to this:

pkg/types/aws:

** Remove the endpoints package from aws sdk v1.
** Remove the function to check for secret regions

pkg/asset/installconfig/aws:

** Add a function to check for secret regions.
** The function was moved here (and changed) because the types package should not make api calls. As we migrated to aws sdk v2 the partitions are no longer publicly available BUT we can access them through endpoints. To get the partition we go through the ec2 api (make a proxy call) and get the endpoint from that call then the endpoint will provide us with the partition.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@barbacbd
Copy link
Contributor Author

/cc @patrickdillon
/cc @sadasu
/cc @tthvo

@openshift-ci openshift-ci bot requested review from patrickdillon, sadasu and tthvo May 29, 2025 16:37
Copy link
Contributor

openshift-ci bot commented May 29, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign andfasano for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot requested review from jhixson74 and mtulio May 29, 2025 16:37
@barbacbd barbacbd force-pushed the CORS-4062 branch 2 times, most recently from 3abaee7 to 38bbd03 Compare May 29, 2025 17:38
Copy link
Member

@tthvo tthvo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

I agree with the idea here! There is also an "unanswered" question aws/aws-sdk-go-v2#2351. But more importantly, there is a V2 version of EndpointResolver (which does not help) that I am unsure if it will replace V1 one day.

if trustBundle != "" && awstypes.IsSecretRegion(installConfig.Config.AWS.Region) {
isSecretRegion, err := awsic.IsSecretRegion(ctx, installConfig.Config.AWS.Region)
if err != nil {
return fmt.Errorf("failed to determine is aws region is secret: %w", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("failed to determine is aws region is secret: %w", err)
return fmt.Errorf("failed to determine if AWS region is secret: %w", err)

nit: typo ^-^

Comment on lines 94 to 59
ctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()
// Need to make a call with the client to activate the endpoint resolver.
_, err = client.DescribeRegions(ctx, &ec2.DescribeRegionsInput{AllRegions: aws.Bool(false)})
if err != nil {
if !errors.Is(err, context.DeadlineExceeded) {
return false, err
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can resolve the endpoint directly without initiating a probe API call, maybe? I did the following (basically just this part from your code only) 🤔

// IsSecretRegion determines if the region is part of a secret partition.
func IsSecretRegion(region string) (bool, error) {
	endpoint, err := ec2.NewDefaultEndpointResolver().ResolveEndpoint(region, ec2.EndpointResolverOptions{})
	if err != nil {
		return false, fmt.Errorf("failed to resolve aws ec2 endpoint: %w", err)
	}
    // TODO: Remove this
	logrus.Infof("Endpoint Partition: %s", endpoint.PartitionID)

	switch endpoint.PartitionID {
	case isoPartition, isobPartition:
		return true, nil
	}

	return false, nil
}

And I tested it with command openshift-install create permissions-policy --log-level=debug --dir=. (also need setting amiID for contrplane and compute in install-config.yaml)

us-iso-east-1: INFO Endpoint Partition: aws-iso
us-isob-east-1: INFO Endpoint Partition: aws-iso-b
us-east-1: INFO Endpoint Partition: aws

@barbacbd barbacbd force-pushed the CORS-4062 branch 2 times, most recently from 679d3eb to d1fc77a Compare May 30, 2025 11:23
if trustBundle != "" && awstypes.IsSecretRegion(installConfig.Config.AWS.Region) {
isSecretRegion, err := awsic.IsSecretRegion(installConfig.Config.AWS.Region)
if err != nil {
return fmt.Errorf("failed to determine is AWS region is secret: %w", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("failed to determine is AWS region is secret: %w", err)
return fmt.Errorf("failed to determine if AWS region is secret: %w", err)

typo?

pkg/types/aws:

** Remove the endpoints package from aws sdk v1.
** Remove the function to check for secret regions

pkg/asset/installconfig/aws:

** Add a function to check for secret regions.
** The function was moved here (and changed) because the types package
should not make api calls. As we migrated to aws sdk v2 the partitions are no
longer publicly available BUT we can access them through endpoints. To get the
partition we go through the ec2 api (make a proxy call) and get the endpoint
from that call then the endpoint will provide us with the partition.
@barbacbd
Copy link
Contributor Author

barbacbd commented Jun 2, 2025

/label platform/aws

Copy link
Member

@tthvo tthvo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 2, 2025
Copy link
Contributor

openshift-ci bot commented Jun 3, 2025

@barbacbd: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-vsphere-static-ovn 1d2b0cd link false /test e2e-vsphere-static-ovn
ci/prow/e2e-aws-ovn-shared-vpc-custom-security-groups 1d2b0cd link false /test e2e-aws-ovn-shared-vpc-custom-security-groups
ci/prow/e2e-aws-ovn-single-node 1d2b0cd link false /test e2e-aws-ovn-single-node
ci/prow/e2e-vsphere-externallb-ovn 1d2b0cd link false /test e2e-vsphere-externallb-ovn
ci/prow/e2e-vsphere-ovn-multi-network 1d2b0cd link false /test e2e-vsphere-ovn-multi-network
ci/prow/okd-scos-e2e-aws-ovn 1d2b0cd link false /test okd-scos-e2e-aws-ovn
ci/prow/e2e-azure-ovn-resourcegroup 1d2b0cd link false /test e2e-azure-ovn-resourcegroup
ci/prow/e2e-aws-private 1d2b0cd link false /test e2e-aws-private

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. platform/aws
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants