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

OCPCLOUD-2693: Support Capacity Reservations by adding 'CapacityReservationId' #110

Merged

Conversation

athiruma
Copy link
Contributor

This PR supports the Capacity Reservation by passing the CapaCityReservationId to the ec2. RunInstancesInput.
CapacityReservationId specifies the target Capacity Reservation into which the instance should be launched

@athiruma athiruma force-pushed the support_capacity_reservation branch from 42a0fa1 to 06d6c8a Compare August 13, 2024 09:20
@openshift-ci openshift-ci bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 13, 2024
Copy link
Contributor

openshift-ci bot commented Aug 13, 2024

Hi @athiruma. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@athiruma
Copy link
Contributor Author

/cc @JoelSpeed

@theobarberbany
Copy link
Contributor

/ok-to-test

@openshift-ci openshift-ci bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 13, 2024
@@ -1544,3 +1544,35 @@ func TestGetAvalabilityZoneTypeFromZoneName(t *testing.T) {
})
}
}

func TestGetCapacityReservationSpecification(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, all new tests would use ginkgo + gomega :)

expectedRequest: nil,
},
{
name: "with a valid CapacityReservationID specified",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any scenario where we may pass an invalid CapacityReservationID? Do we want some verification or testing around that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the AWS resources start with their short resource name for example cr-***, so I thought no need for verification.

Copy link
Contributor

Choose a reason for hiding this comment

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

You still need to verify the user input, what if they change the value to something that isn't the correct format?

Copy link
Contributor Author

@athiruma athiruma Aug 16, 2024

Choose a reason for hiding this comment

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

Done, verified that the id starts with the prefix cr-.

@theobarberbany
Copy link
Contributor

Hey @athiruma, overall I think this looks good. Just a couple of comments/questions and I think it's good to go!

@athiruma athiruma force-pushed the support_capacity_reservation branch 3 times, most recently from 1016add to ce5508f Compare August 16, 2024 09:30
return nil, nil
}

if !strings.HasPrefix(capacityReservationID, "cr-") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any other validations we can apply, maximum length? Valid characters? Is there a regex we could use to validate the user input here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right resource-id will be 17char long excluding cr- and we check regex with a mix of lower alpha and digits.

@athiruma athiruma force-pushed the support_capacity_reservation branch from ce5508f to 8d1723a Compare August 16, 2024 16:14

if !re.MatchString(capacityReservationID) {
// It must starts with cr-xxxxxxxxxxxxxxxxx with length of 17 characters excluding cr-
return nil, mapierrors.InvalidMachineConfiguration("Invalid value for capacityReservationId: %q, it must starts with cr-", capacityReservationID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, mapierrors.InvalidMachineConfiguration("Invalid value for capacityReservationId: %q, it must starts with cr-", capacityReservationID)
return nil, mapierrors.InvalidMachineConfiguration("Invalid value for capacityReservationId: %q, it must starts with cr- followed by 17 lowercase hexadecimal characters", capacityReservationID)


func TestGetCapacityReservationSpecification(t *testing.T) {
mockCapacityReservationID := "cr-1234a6789d234f6f4"
invalidMockCapacityReservationID := "cr-1234"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you try a few variations, different lengths, ones with capitals, ones with non hex digits

@athiruma athiruma force-pushed the support_capacity_reservation branch from 8d1723a to fd9bca8 Compare August 19, 2024 10:29
@athiruma
Copy link
Contributor Author

/test golint

@athiruma athiruma force-pushed the support_capacity_reservation branch from fd9bca8 to 9b7869d Compare August 20, 2024 05:06
@athiruma
Copy link
Contributor Author

/test e2e-aws-operator

name: "with invalid CapacityReservationID options specified, shorter length",
capacityReservationID: capacityReservationIDShorterLength,
expectedRequest: nil,
expectedError: mapierrors.InvalidMachineConfiguration("Invalid value for capacityReservationId: %q, it must starts with cr-", capacityReservationIDShorterLength),
Copy link
Contributor

Choose a reason for hiding this comment

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

The error message here should also contain the details about the 17 characters and hexadecimal, thought I suggested that already sorry

@athiruma athiruma force-pushed the support_capacity_reservation branch from 9b7869d to 06095c5 Compare August 21, 2024 12:55
@JoelSpeed
Copy link
Contributor

/approve

Can you please add the relevant Jira card to the PR title please

@theobarberbany can you LGTM if you're ok with this as it is now?

Copy link
Contributor

openshift-ci bot commented Aug 21, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JoelSpeed

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

The pull request process is described 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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 21, 2024
@athiruma
Copy link
Contributor Author

/approve

Can you please add the relevant Jira card to the PR title please

@theobarberbany can you LGTM if you're ok with this as it is now?

I don't have any cards.

@JoelSpeed
Copy link
Contributor

@athiruma You don't have any cards? What's tracking this work? There must be an epic or something so that we can co-ordinate between QE/Docs/PX about the feature. If you don't have anything, please go and make it. Who's the PM on this feature?

@athiruma athiruma changed the title Support Capacity Reservations by adding 'CapacityReservationId' OCPCLOUD-2693: Support Capacity Reservations by adding 'CapacityReservationId' Aug 27, 2024
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Aug 27, 2024
@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Aug 27, 2024

@athiruma: This pull request references OCPCLOUD-2693 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the epic to target the "4.18.0" version, but no target version was set.

In response to this:

This PR supports the Capacity Reservation by passing the CapaCityReservationId to the ec2. RunInstancesInput.
CapacityReservationId specifies the target Capacity Reservation into which the instance should be launched

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.

@athiruma
Copy link
Contributor Author

@athiruma You don't have any cards? What's tracking this work? There must be an epic or something so that we can co-ordinate between QE/Docs/PX about the feature. If you don't have anything, please go and make it. Who's the PM on this feature?

yup added to the title.
Thanks @subin for creating a Jira card.

@theobarberbany
Copy link
Contributor

/lgtm

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 27, 2024
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 27, 2024
@athiruma athiruma force-pushed the support_capacity_reservation branch from 06095c5 to 96e5708 Compare August 28, 2024 04:40
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 28, 2024
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 28, 2024
@athiruma
Copy link
Contributor Author

athiruma commented Sep 1, 2024

/test e2e-aws-serial
/test e2e-aws-upgrade

@athiruma
Copy link
Contributor Author

athiruma commented Sep 1, 2024

/cc @JoelSpeed @theobarberbany

@JoelSpeed
Copy link
Contributor

/lgtm

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

/retest-required

Remaining retests: 0 against base HEAD eb7feab and 2 for PR HEAD 96e5708 in total

Copy link
Contributor

openshift-ci bot commented Sep 2, 2024

@athiruma: all tests passed!

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.

@openshift-merge-bot openshift-merge-bot bot merged commit 7d11346 into openshift:main Sep 2, 2024
10 checks passed
@openshift-bot
Copy link
Contributor

[ART PR BUILD NOTIFIER]

Distgit: ose-machine-api-provider-aws
This PR has been included in build ose-machine-api-provider-aws-container-v4.18.0-202409021542.p0.g7d11346.assembly.stream.el9.
All builds following this will include this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. 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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants