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

Set default values in API rather than in webhooks #5111

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

bryan-cox
Copy link
Contributor

What type of PR is this?
/kind cleanup

What this PR does / why we need it:
This commit removes default values previously set in webhooks and adds the default values directly in the API through the kubebuilder annotation, kubebuilder:default.

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 #4204

Special notes for your reviewer:

  • cherry-pick candidate

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests

Release note:

Removes default values previously set in webhooks and adds the default values directly in the API through the kubebuilder annotation, `kubebuilder:default`.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Sep 5, 2024
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 5, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @bryan-cox. 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.

Copy link

codecov bot commented Sep 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 52.34%. Comparing base (fa94869) to head (a0b707d).
Report is 150 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5111      +/-   ##
==========================================
+ Coverage   51.35%   52.34%   +0.98%     
==========================================
  Files         273      272       -1     
  Lines       24670    29343    +4673     
==========================================
+ Hits        12670    15360    +2690     
- Misses      11211    13178    +1967     
- Partials      789      805      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bryan-cox
Copy link
Contributor Author

@nojnhuh @jackfrancis - do we want to continue with this PR? If so, could I get an ok to test this please?

@mboersma
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 Sep 26, 2024
@bryan-cox
Copy link
Contributor Author

/retest

@bryan-cox
Copy link
Contributor Author

For pull-cluster-api-provider-azure-e2e-aks

Expected success, but got an error:
    <errors.aggregate | len:1, cap:1>: 
    admission webhook "validation.azuremanagedcontrolplanes.infrastructure.cluster.x-k8s.io" denied the request: [spec.virtualNetwork.CIDRBlock: Invalid value: "": pre-existing virtual networks CIDR block is invalid, spec.virtualNetwork.Subnet.CIDRBlock: Invalid value: "": pre-existing subnets CIDR block is invalid]
    [

Not sure how these would be empty when they are defaulted here and here.

Does the e2e use any API changes from the PR?

@bryan-cox bryan-cox force-pushed the 4204 branch 3 times, most recently from 317973f to b659359 Compare October 23, 2024 11:37
Copy link
Contributor

@nojnhuh nojnhuh left a comment

Choose a reason for hiding this comment

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

Loving all the red in this diff so far!

Comment on lines -176 to -177
// Default is the same as the ScanInterval so default to that same value if it isn't set
result.ScaleDownDelayAfterDelete = result.ScanInterval
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this can be expressed in the kubebuilder annotations, so maybe best to keep just this field 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.

Isn't setting this to the same default value in the kubebuilder annotations accomplishing the same purpose here though? It's just a default value if the value isn't set, which what was happening here before.

Name string `json:"name"`
Name string `json:"name"`

// +kubebuilder:default:="10.240.0.0/16"
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic we had for this already seems necessary, so I don't think it buys us anything to include this kubebuilder annotation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to remove it but does it hurt anything to include the default here?

@@ -419,6 +422,7 @@ type AzureManagedMachinePoolClassSpec struct {

// ManagedControlPlaneVirtualNetworkClassSpec defines the ManagedControlPlaneVirtualNetwork properties that may be shared across several managed control plane vnets.
type ManagedControlPlaneVirtualNetworkClassSpec struct {
// +kubebuilder:default:="10.0.0.0/8"
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as the other CIDR block comment above.

@bryan-cox
Copy link
Contributor Author

/retest

@nojnhuh
Copy link
Contributor

nojnhuh commented Nov 7, 2024

I'll get back to this as soon as I can.

/assign

@bryan-cox
Copy link
Contributor Author

/test pull-cluster-api-provider-azure-e2e-aks

@nawazkh nawazkh added this to the v1.18 milestone Nov 7, 2024
@dtzar dtzar modified the milestones: v1.18, next Nov 19, 2024
@bryan-cox
Copy link
Contributor Author

/test pull-cluster-api-provider-azure-e2e-aks

@bryan-cox bryan-cox force-pushed the 4204 branch 3 times, most recently from 475fc5d to d06d8fb Compare December 5, 2024 20:00
@mboersma
Copy link
Contributor

@nojnhuh could you take another look at this when time permits?

@nojnhuh
Copy link
Contributor

nojnhuh commented Dec 12, 2024

Sorry, I'm not optimistic I'll be able to get back to this before I take off for the holidays. I'll let someone else take on reviewing this if I can't get back to it.

/unassign

@willie-yao
Copy link
Contributor

No problem, I got it!
/assign

Copy link
Contributor

@willie-yao willie-yao 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 pending one minor nit!

@willie-yao
Copy link
Contributor

@mboersma Can you take a look as well so we have two reviewers?

This commit removes default values previously set in webhooks and adds
the default values directly in the API through the kubebuilder
annotation, `kubebuilder:default`.

Signed-off-by: Bryan Cox <[email protected]>
Copy link
Contributor

@mboersma mboersma left a comment

Choose a reason for hiding this comment

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

/lgtm
/test pull-cluster-api-provider-azure-e2e-optional
/test pull-cluster-api-provider-azure-apiversion-upgrade

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

LGTM label has been added.

Git tree hash: a95acb3b51f6d1cb17d036ba57bcba509f55d3c6

@k8s-ci-robot
Copy link
Contributor

@bryan-cox: 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
pull-cluster-api-provider-azure-apidiff a0b707d link false /test pull-cluster-api-provider-azure-apidiff
pull-cluster-api-provider-azure-e2e-optional a0b707d link false /test pull-cluster-api-provider-azure-e2e-optional

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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.

Copy link
Contributor

@willie-yao willie-yao 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

Thank you for your work and patience on this! @bryan-cox

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: willie-yao

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 Dec 13, 2024
@willie-yao
Copy link
Contributor

/retest

@k8s-ci-robot k8s-ci-robot merged commit f35cdf1 into kubernetes-sigs:main Dec 13, 2024
21 of 23 checks passed
@k8s-ci-robot k8s-ci-robot modified the milestones: next, v1.18 Dec 13, 2024
@bryan-cox bryan-cox deleted the 4204 branch December 13, 2024 19:27
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. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", 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. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Use // +kubebuilder:default annotations where possible
8 participants