Skip to content

Conversation

@athiruma
Copy link
Contributor

@athiruma athiruma commented Mar 6, 2025

What type of PR is this?

  • If only MarketType=Spot is specified but spotMarketType is not provided, then we must explicitly add spotMarketType to the API configuration.
  • Webhook validation for the marketType field value

What this PR does / why we need it:

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 #

Special notes for your reviewer:

Checklist:

  • squashed commits
  • includes documentation
  • includes emoji in title
  • adds unit tests
  • adds or updates e2e tests

Release note:

None

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 6, 2025
@k8s-ci-robot k8s-ci-robot requested review from faiq and fiunchinho March 6, 2025 10:49
@k8s-ci-robot k8s-ci-robot added needs-priority needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 6, 2025
@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/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 6, 2025
@alexander-demicev
Copy link
Contributor

/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 Mar 6, 2025
@athiruma
Copy link
Contributor Author

@JoelSpeed ptal 👋

@JoelSpeed
Copy link

Changes look ok, have we considered if we should use CEL validations rather than webhooks for this kind of validation moving forward?

@athiruma
Copy link
Contributor Author

Changes look ok, have we considered if we should use CEL validations rather than webhooks for this kind of validation moving forward?

Im not aware of CEL, may I'll look into it.

@JoelSpeed
Copy link

You can add a marker, something along the lines of

// +kubebuilder:validation:XValidation:rule="!has(self.capacityReservationID) || !has(self.marketType) || self.marketType != 'Spot'",message="capacityReservationID may not be set when marketType is Spot"

@damdo
Copy link
Member

damdo commented Mar 15, 2025

@athiruma are you able to switch to the CEL validation for this?

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 16, 2025
// If this value is selected, CapacityReservationID must be specified to identify the target reservation.
// If marketType is not specified and spotMarketOptions is provided, the marketType defaults to "Spot".
// +optional
// +kubebuilder:validation:XValidation:rule="!has(self.capacityReservationID) || !has(self.marketType) || self.marketType != 'Spot'",message="capacityReservationID may not be set when marketType is Spot"

Choose a reason for hiding this comment

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

This must be added to the parent struct, and not this field, as "self" in the rule will apply to the field if you apply it here, or the parent struct if you apply it to the parent struct

@athiruma
Copy link
Contributor Author

/retest-required

@damdo
Copy link
Member

damdo commented Mar 22, 2025

/retest

@damdo
Copy link
Member

damdo commented Mar 23, 2025

@athiruma we don't do vendoring here in upstream CAPA, could you drop the vendor folders please?

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Mar 23, 2025
@athiruma
Copy link
Contributor Author

/retest-required

@damdo
Copy link
Member

damdo commented Mar 26, 2025

You could try to rebase to see if apidiff gets fixed

@damdo
Copy link
Member

damdo commented Mar 29, 2025

@athiruma looks like units need updating after the error message changes.

=== RUN   TestGetInstanceMarketOptionsRequest/with_spotMarketOptions_and_capacityRerservationID_specified
    instances_test.go:5878: 
        Expected
            <string>: "unable..."
        to equal       |
            <string>: "can't ..."

@athiruma
Copy link
Contributor Author

athiruma commented Apr 3, 2025

@damdo ptal!

Copy link
Member

@damdo damdo 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, last little change to make it more consistent, then I am happy with it!
Thanks a lot

@damdo
Copy link
Member

damdo commented Apr 3, 2025

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Apr 3, 2025
Copy link
Member

@damdo damdo left a comment

Choose a reason for hiding this comment

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

/lgtm

/assign @nrb @richardcase @AndiDog @dlipovetsky @Ankitasw

for approval

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 3, 2025

// AWSMachineSpec defines the desired state of an Amazon EC2 instance.
// +kubebuilder:validation:XValidation:rule="!has(self.capacityReservationId) || !has(self.marketType) || self.marketType != 'Spot'",message="capacityReservationId may not be set when marketType is Spot"
// +kubebuilder:validation:XValidation:rule="!has(self.capacityReservationId) || !has(self.spotMarketOptions)",message="capacityReservationId cannot be set when spotMarketOptions is specified"
Copy link
Member

Choose a reason for hiding this comment

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

I'll need to check the docs (but maybe @JoelSpeed knows), if we are tightening the validation rules is this considered a breaking behavioural change? Guess it depends on if it breaks currently.

@athiruma - whats the current behaviour if i set capacityReservationId and specify spot? Does it currently error in this situation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it will raise an error.

Choose a reason for hiding this comment

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

If the capacity reservation ID field has already shipped within a release, then yes, this could cause an issue for users who have already started using the field

Given that EC2 will reject creating machines with this configuration already, we are bringing the validation earlier here realistically, and ratcheting should also help with invalid combinations if folks are updating the objects.

I'm inclined to say this is likely to be fairly safe depending on how long ago this shipped

Copy link
Member

Choose a reason for hiding this comment

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

It has shipped in CAPA v2.8.1 a couple of weeks ago.
I think if we backport it to v2.8.z and then release it in v2.9.0 we should be fine right?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds like we are all good then.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah considering this would already fail anyway at a later stage.
Happy to approve then @richardcase ?

@richardcase
Copy link
Member

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: richardcase

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 Apr 5, 2025
@k8s-ci-robot k8s-ci-robot merged commit e5b01de into kubernetes-sigs:main Apr 5, 2025
18 checks passed
athiruma added a commit to athiruma/cluster-api-provider-aws that referenced this pull request Apr 9, 2025
* Add spotMarketRequest on marketType spot

* Add CEL validation

* update vendor files

* added validation

* Updated the comments
@damdo
Copy link
Member

damdo commented Apr 9, 2025

/cherry-pick release-2.8

@k8s-infra-cherrypick-robot

@damdo: Failed to get PR patch from GitHub. This PR will need to be manually cherrypicked.

Error messagestatus code 422 not one of [200], body: {"message":"The patch is taking too long to generate.","documentation_url":"https://docs.github.com/rest/pulls/pulls#get-a-pull-request","status":"422"}

In response to this:

/cherry-pick release-2.8

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.

punkwalker pushed a commit to punkwalker/cluster-api-provider-aws that referenced this pull request May 1, 2025
* Add spotMarketRequest on marketType spot

* Add CEL validation

* update vendor files

* added validation

* Updated the comments
@damdo
Copy link
Member

damdo commented Jun 5, 2025

/cherry-pick release-2.8

@k8s-infra-cherrypick-robot

@damdo: Failed to get PR patch from GitHub. This PR will need to be manually cherrypicked.

Error messagestatus code 422 not one of [200], body: {"message":"The patch is taking too long to generate.","documentation_url":"https://docs.github.com/rest/pulls/pulls#get-a-pull-request","status":"422"}

In response to this:

/cherry-pick release-2.8

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.

alam0rt pushed a commit to alam0rt/cluster-api-provider-aws that referenced this pull request Sep 4, 2025
* Add spotMarketRequest on marketType spot

* Add CEL validation

* update vendor files

* added validation

* Updated the comments
AndiDog pushed a commit to giantswarm/cluster-api-provider-aws that referenced this pull request Nov 10, 2025
* Add spotMarketRequest on marketType spot

* Add CEL validation

* update vendor files

* added validation

* Updated the comments
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-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.