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

Add proper validation for nodepool name #3974

Merged
merged 1 commit into from
Oct 4, 2023

Conversation

tapojit047
Copy link
Contributor

@tapojit047 tapojit047 commented Sep 8, 2023

 
What type of PR is this?
/kind bug

What this PR does / why we need it:

  1. According to Azure Docs, these are the nodepool naming restrictions:
        - The name of a node pool may only contain lowercase alphanumeric characters and must begin with a lowercase letter.
        - For Linux node pools, the length must be between 1-12 characters.

But the nodepool name is not validated properly (according to these restrictions). Proper validation following these restrictions in the azuremanagedmachinepool_webhook.go is added.

  1. If the name of the nodepool i.e. spec.name field is not specified in the YAML of AzureManagedMachinePool, then the default name is set to the metadata.name. Take a look here. So metadata.name is validated when spec.name is not set.

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

Special notes for your reviewer:

  • cherry-pick candidate

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests

Release note:

Add proper validation for nodepool name

@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/bug Categorizes issue or PR as related to a bug. labels Sep 8, 2023
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Sep 8, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: tapojit047 / name: Tapajit Chandra Paul (66860ab)

@k8s-ci-robot
Copy link
Contributor

Welcome @tapojit047!

It looks like this is your first PR to kubernetes-sigs/cluster-api-provider-azure 🎉. 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-azure 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
Copy link
Contributor

Hi @tapojit047. 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 8, 2023
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Sep 8, 2023
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 8, 2023
@tapojit047 tapojit047 force-pushed the fix-nodepool-name branch 2 times, most recently from 01ea9da to 894105b Compare September 8, 2023 13:11
@CecileRobertMichon
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 8, 2023
@tapojit047
Copy link
Contributor Author

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

return -1
}, name)
name = strings.TrimLeftFunc(name, unicode.IsNumber)
if len(name) > 6 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we want to truncate the name from MachinePool to 6 chars and then add 6 chars of random characters?

Wouldn't this be sufficient?:

  • remove/replace invalid characters
  • truncate at the maximum allowed character limit (12)

Choose a reason for hiding this comment

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

We would like to avoid naming conflict created from different CAPZ cluster. So, we want to add a random part to the pool name that is passed to Azure.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the clarification.

So is the scenario that we might run multiple clusters w/ a common MachinePool naming convention. E.g.:

  • cluster1
    • pool1
    • pool2
    • pool3
  • cluster2
    • pool1
    • pool2
    • pool3

And you want to have CAPZ ensure that cluster1 and cluster2 don't produce identically named pool names?

Choose a reason for hiding this comment

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

Yes. We want to avoid naming conflict.

Also, adding a random part to will not affect ux, since user don't really have to interact with this directly unless they are doing something from the Azure portal.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks again.

So, my initial response to this is that is that this type of enforcement should not be the responsibility of CAPZ. There could be other environments with the exact opposite requirements (require identical pool names across common cluster ecosystems).

Could you enforce this pool naming requirement in your cluster creation CI so that you're fully in control of these requirements?

cc @nojnhuh @CecileRobertMichon

Copy link
Contributor

Choose a reason for hiding this comment

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

How about validating the AzureManagedMachinePool metadata name according to the Azure pool name rules if and only if the spec.Name field is not explicitly set? And if the spec.Name field is set, we should validate the spec.Name.

Since we already default spec.name to metadata.name when not set, do we only need to validate spec.name?

Copy link
Contributor

Choose a reason for hiding this comment

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

do we only need to validate spec.name

That would be equivalent, only reason I can think of for doing both is that it might be more user friendly to validate the thing the user is actually setting (otherwise I could see users getting confused with "why am I getting a validation error for something I didn't set"). That's an implementation detail though.

Choose a reason for hiding this comment

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

There is no Azure requirement that a pool name must be unique (it should only be unique within a cluster).

I did not realise that. Thanks for the info.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to convert this into a new PR that validates the AKS 12 character limit, or simply close this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Converted it into a validation for the nodepool name PR. @jackfrancis

@codecov
Copy link

codecov bot commented Sep 18, 2023

Codecov Report

Attention: 15 lines in your changes are missing coverage. Please review.

Comparison is base (b195e9a) 56.57% compared to head (66860ab) 56.56%.
Report is 50 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3974      +/-   ##
==========================================
- Coverage   56.57%   56.56%   -0.01%     
==========================================
  Files         187      187              
  Lines       19130    19168      +38     
==========================================
+ Hits        10823    10843      +20     
- Misses       7676     7691      +15     
- Partials      631      634       +3     
Files Coverage Δ
api/v1beta1/azuremanagedmachinepool_webhook.go 81.42% <64.28%> (-2.87%) ⬇️

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

@tapojit047 tapojit047 changed the title Add a proper validation for nodepool name & Add valid default nodepool name Add a proper validation for nodepool name Sep 22, 2023
@tapojit047 tapojit047 force-pushed the fix-nodepool-name branch 5 times, most recently from 651fe3d to 64b7dc8 Compare September 24, 2023 12:42
Signed-off-by: Tapajit Chandra Paul <[email protected]>
@tapojit047 tapojit047 changed the title Add a proper validation for nodepool name Add proper validation for nodepool name Sep 25, 2023
Copy link
Contributor

@CecileRobertMichon CecileRobertMichon 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 @jackfrancis @nojnhuh

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

LGTM label has been added.

Git tree hash: 60a6bfcab36e64d86d32c985b90b9bed05bc5e6e

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.

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nojnhuh

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 Oct 3, 2023
@k8s-ci-robot k8s-ci-robot merged commit 1f387aa into kubernetes-sigs:main Oct 4, 2023
10 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.12 milestone Oct 4, 2023
@tamalsaha tamalsaha deleted the fix-nodepool-name branch October 4, 2023 01:32
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/bug Categorizes issue or PR as related to a bug. 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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Set a unique valid default name for nodepool when spec.name in AzureManagedMachinePool is not specified
6 participants