Skip to content

Capacity reservations feature implementation #235

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

Merged

Conversation

fizashaikh
Copy link
Contributor

Issue: aws-controllers-k8s/community#2234

Description of changes:
This change implements capacity reservations feature in ec2 operator.
It adds e2e tests for the capacity reservations CRUD functionality.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link

ack-prow bot commented Jan 29, 2025

Hi @fizashaikh. Thanks for your PR.

I'm waiting for a aws-controllers-k8s 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/test-infra repository.

@ack-prow ack-prow bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jan 29, 2025
@ack-prow ack-prow bot requested review from a-hilaly and jlbutler January 29, 2025 01:26
@fizashaikh fizashaikh changed the title Capacity reservations feature Capacity reservations feature implementation Jan 29, 2025
@a-hilaly
Copy link
Member

a-hilaly commented Feb 4, 2025

/ok-to-test

@ack-prow ack-prow 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 Feb 4, 2025
@a-hilaly
Copy link
Member

a-hilaly commented Feb 4, 2025

at first glance, this LGTM, @michaelhtm can you PTAL

@fizashaikh
Copy link
Contributor Author

/test ec2-verify-attribution

Copy link
Member

@michaelhtm michaelhtm left a comment

Choose a reason for hiding this comment

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

Hey @fizashaikh, thanks for contributing!
Everything lgtm, can you please resolve the conflict?
Thanks

@fizashaikh
Copy link
Contributor Author

Hey @fizashaikh, thanks for contributing! Everything lgtm, can you please resolve the conflict? Thanks

Thanks for reviewing @michaelhtm ! All conflicts are resolved now 👍
Thanks!

Copy link
Member

@michaelhtm michaelhtm left a comment

Choose a reason for hiding this comment

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

Hi @fizashaikh. apologies for the back and forth. I have a couple more comments about this PR. Thanks!

Comment on lines +84 to +94
EndDate *metav1.Time `json:"endDate,omitempty"`
// Indicates the way in which the Capacity Reservation ends. A Capacity Reservation
// can have one of the following end types:
//
// - unlimited - The Capacity Reservation remains active until you explicitly
// cancel it. Do not provide an EndDate if the EndDateType is unlimited.
//
// - limited - The Capacity Reservation expires automatically at a specified
// date and time. You must provide an EndDate value if the EndDateType value
// is limited.
EndDateType *string `json:"endDateType,omitempty"`
Copy link
Member

@michaelhtm michaelhtm Feb 7, 2025

Choose a reason for hiding this comment

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

nit: not sure if this should be required, but can we have custom code validating the assignment of these fields?

//
// You can request a future-dated Capacity Reservation between 5 and 120 days
// in advance.
StartDate *metav1.Time `json:"startDate,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

î same for this one? with end-date

@michaelhtm
Copy link
Member

Nice 🚀 🚀
/lgtm
can you also make a release PR? thanks!

@ack-prow ack-prow bot added the lgtm Indicates that a PR is ready to be merged. label Feb 10, 2025
Copy link

ack-prow bot commented Feb 10, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fizashaikh, michaelhtm

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

@ack-prow ack-prow bot added the approved label Feb 10, 2025
@michaelhtm
Copy link
Member

/hold

@ack-prow ack-prow bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 10, 2025
Copy link
Member

@michaelhtm michaelhtm left a comment

Choose a reason for hiding this comment

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

Hey @fizashaikh I have one more comment..

Comment on lines +3 to +10
latestCopy, err := rm.sdkFind(ctx, desired)
if err != nil {
return nil, err
}

ko.Status.AvailableInstanceCount = latestCopy.ko.Status.AvailableInstanceCount
ko.Status.TotalInstanceCount = latestCopy.ko.Status.TotalInstanceCount
ko.Status.State = latestCopy.ko.Status.State
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reviewing the PR @michaelhtm !
Looks like late initialization code generator looks for these fields in Spec, however I am trying to update the fields within Status to reflect the correct values of these fields after a capacity reservation is modified/updated.
Therefore, I see errors when I remove the custom hook and update generator.yaml to include these fields with late_initialization,

  CapacityReservation:
    fields:
      State:
        print:
          name: STATE
        late_initialize: {}
      AvailableInstanceCount:
        late_initialize: {}
      TotalInstanceCount:
        late_initialize: {}

The code generated with above change looks like this,

// incompleteLateInitialization return true if there are fields which were supposed to be
// late initialized but are not. If all the fields are late initialized, false is returned
func (rm *resourceManager) incompleteLateInitialization(
	res acktypes.AWSResource,
) bool {
	ko := rm.concreteResource(res).ko.DeepCopy()
	if ko.Spec.AvailableInstanceCount == nil {
		return true
	}
	if ko.Spec.State == nil {
		return true
	}
	if ko.Spec.TotalInstanceCount == nil {
		return true
	}
	return false
}

Error,

ko.Spec.AvailableInstanceCount undefined 
(type "github.com/aws-controllers-k8s/ec2-controller/apis/v1alpha1".CapacityReservationSpec 
has no field or method AvailableInstanceCount)

Am I missing something? Is there a way to tell code generator to look for these fields in Status?
Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

You are right..just looked into the implementation of late_initialize and it looks like it only supports Spec fields..it should be an easy fix if you want to tackle that as well, maybe even by allowing user to specify whether late_initialize is in spec or status...
https://github.com/aws-controllers-k8s/code-generator/blob/8762917215d9902b2011a2b0b1b0c776855a683e/pkg/generate/code/late_initialize.go#L302-L306

Copy link
Member

@michaelhtm michaelhtm left a comment

Choose a reason for hiding this comment

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

This is great, Thank you!
/unhold

Copy link
Member

Choose a reason for hiding this comment

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

🚀🚀🚀🚀

@ack-prow ack-prow bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 11, 2025
@ack-prow ack-prow bot merged commit e0af7b2 into aws-controllers-k8s:main Feb 11, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved 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.

3 participants