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

✨ Added the CapacityReservation support #5047

Merged

Conversation

athiruma
Copy link
Contributor

@athiruma athiruma commented Jul 11, 2024

What type of PR is this?

What this PR does / why we need it:
Add a new field to API - capacityReservationId, then use it to create capacity reserved instances by initializing a CapacityReservationSpecification and passing it to RunInstances().

  • Capacity Reservations only support a single availability zone

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

#5045

Special notes for your reviewer:

Checklist:

  • squashed commits
  • includes documentation
  • includes emojis
  • adds unit tests
  • adds or updates e2e tests

Release note:

Adding a new API field `capacityReservationId` to create capacity reserved instances

@k8s-ci-robot k8s-ci-robot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Jul 11, 2024
Copy link

linux-foundation-easycla bot commented Jul 11, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-priority labels Jul 11, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @athiruma!

It looks like this is your first PR to kubernetes-sigs/cluster-api-provider-aws 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/cluster-api-provider-aws has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 11, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @athiruma. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 11, 2024
@k8s-ci-robot k8s-ci-robot requested review from AndiDog and nrb July 11, 2024 04:37
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 11, 2024
@nrb
Copy link
Contributor

nrb commented Jul 11, 2024

/ok-to-test

@k8s-ci-robot k8s-ci-robot 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 Jul 11, 2024
@athiruma athiruma force-pushed the support_capacity_reservation branch from aa8cee7 to 7ed3c02 Compare July 11, 2024 16:37
@@ -157,6 +157,10 @@ type AWSMachineSpec struct {
// +optional
// +kubebuilder:validation:Enum:=default;dedicated;host
Tenancy string `json:"tenancy,omitempty"`

// CapacityReservationID specifies the capacity reservation resource id that should be
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you are missing the rest of the sentence :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@athiruma athiruma force-pushed the support_capacity_reservation branch 2 times, most recently from a934b6d to 1af019d Compare July 14, 2024 08:58
// CapacityReservationID specifies the instance that should be launched in the
// reserved compute capacity.
// +optional
CapacityReservationID string `json:"capacityReservationId,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the motivation to add this field to v1beta1? In general, new fields should probably only go into v1beta2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the same based on the spot market options PR. I will remove that.

@athiruma athiruma force-pushed the support_capacity_reservation branch from 1af019d to 11045bb Compare July 15, 2024 19:21
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 15, 2024
Fixed the lint

Fixed the description

Removed the API in v1
@athiruma athiruma force-pushed the support_capacity_reservation branch from 11045bb to dc07755 Compare July 15, 2024 19:37
@athiruma
Copy link
Contributor Author

/test pull-cluster-api-provider-aws-test

Comment on lines 197 to 198
// CapacityReservationID specifies the instance that should be launched in the
// reserved compute capacity.
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not specify an instance.

Suggested change
// CapacityReservationID specifies the instance that should be launched in the
// reserved compute capacity.
// CapacityReservationID specifies the target Capacity Reservation into which the instance should be launched.

pkg/cloud/services/ec2/instances.go Show resolved Hide resolved
@@ -1119,6 +1122,22 @@ func filterGroups(list []string, strToFilter string) (newList []string) {
return
}

func getCapacityReservationSpecification(capacityReservationID string) *ec2.CapacityReservationSpecification {
if capacityReservationID == "" {
// Instance is not a CapacityReservation instance
Copy link
Contributor

Choose a reason for hiding this comment

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

See above. There's "[EC2] instance" and "Capacity Reservation" as two separate terms. Let's not mix those.

Suggested change
// Instance is not a CapacityReservation instance
// Not targetting any specific Capacity Reservation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment on lines 1131 to 1138
// Set required values for CapacityReservation
capacityReservationTargetOptions := &ec2.CapacityReservationTarget{}
capacityReservationTargetOptions.SetCapacityReservationId(capacityReservationID)

capacityReservationSpecification := &ec2.CapacityReservationSpecification{}
capacityReservationSpecification.SetCapacityReservationTarget(capacityReservationTargetOptions)

return capacityReservationSpecification
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
// Set required values for CapacityReservation
capacityReservationTargetOptions := &ec2.CapacityReservationTarget{}
capacityReservationTargetOptions.SetCapacityReservationId(capacityReservationID)
capacityReservationSpecification := &ec2.CapacityReservationSpecification{}
capacityReservationSpecification.SetCapacityReservationTarget(capacityReservationTargetOptions)
return capacityReservationSpecification
return &ec2.CapacityReservationSpecification{
CapacityReservationTarget: &ec2.CapacityReservationTarget{
CapacityReservationId: ptr.To[string](capacityReservationID),
}
}

},
{
name: "with an valid CapacityReservationID specified",
capacityReservationID: *aws.String(mockCapacityReservationID),
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
capacityReservationID: *aws.String(mockCapacityReservationID),
capacityReservationID: mockCapacityReservationID,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

capacityReservationID accepts only the *string. So it will be aws.String(mockCapacityReservationID)

expectedRequest: nil,
},
{
name: "with an 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.

Suggested change
name: "with an valid CapacityReservationID specified",
name: "with a valid CapacityReservationID specified",

@athiruma athiruma force-pushed the support_capacity_reservation branch 3 times, most recently from 11012a7 to 35cf423 Compare July 16, 2024 10:33
Removed the tests by verify-gen
@athiruma athiruma force-pushed the support_capacity_reservation branch from 35cf423 to 5e44fa5 Compare July 16, 2024 22:44
@nrb
Copy link
Contributor

nrb commented Jul 23, 2024

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 23, 2024
@athiruma
Copy link
Contributor Author

/cc @AndiDog @muraee

@muraee
Copy link
Contributor

muraee commented Jul 26, 2024

/lgtm

Copy link
Contributor

@AndiDog AndiDog left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AndiDog

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 29, 2024
@k8s-ci-robot k8s-ci-robot merged commit 6ad02ef into kubernetes-sigs:main Jul 29, 2024
19 checks passed
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants