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 NamingStrategy to MachineDeployment #11172

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adilGhaffarDev
Copy link
Contributor

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 part of #10577

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 11, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign enxebre for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-area PR is missing an area label size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 11, 2024
@enxebre
Copy link
Member

enxebre commented Oct 2, 2024

/hold
on #11123 so we make sure feedback there is incorporated here

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 2, 2024
@adilGhaffarDev
Copy link
Contributor Author

/area machineset
/area machinedeployment

@k8s-ci-robot k8s-ci-robot added area/machineset Issues or PRs related to machinesets area/machinedeployment Issues or PRs related to machinedeployments and removed do-not-merge/needs-area PR is missing an area label labels Oct 23, 2024
@adilGhaffarDev adilGhaffarDev force-pushed the md-naming-issue-fix/adil branch 2 times, most recently from f588f68 to 10956bd Compare October 28, 2024 11:44
@adilGhaffarDev adilGhaffarDev marked this pull request as ready for review October 28, 2024 11:44
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 28, 2024
@adilGhaffarDev adilGhaffarDev changed the title 🌱 Add NamingStrategy to MachineDeployment wip:🌱 Add NamingStrategy to MachineDeployment Oct 29, 2024
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 29, 2024
@adilGhaffarDev adilGhaffarDev force-pushed the md-naming-issue-fix/adil branch 2 times, most recently from 5438128 to 6c5de96 Compare October 29, 2024 08:23
@adilGhaffarDev adilGhaffarDev changed the title wip:🌱 Add NamingStrategy to MachineDeployment 🌱 Add NamingStrategy to MachineDeployment Oct 29, 2024
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 29, 2024
@adilGhaffarDev
Copy link
Contributor Author

cc @sbueringer @fabriziopandini @chrischdi
This one is ready for review, please check.

@lentzi90
Copy link
Contributor

I have verified that it is working as expected with a real end-to-end test. Thanks for working on this @adilGhaffarDev !

@adilGhaffarDev
Copy link
Contributor Author

/unhold
Unholding because kcp pr is merged.

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Oct 31, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 4, 2024
@sbueringer
Copy link
Member

I don't know when I'll get around to it. Not much time but a lot of work left until code freeze / PTO.

In general I'm fine with keeping the flag for another minor release

nameTemplate := "{{ .machineDeployment.name }}-{{ .random }}"
if owner.Spec.MachineNamingStrategy != nil && owner.Spec.MachineNamingStrategy.Template != "" {
nameTemplate = owner.Spec.MachineNamingStrategy.Template
if !strings.Contains(nameTemplate, "{{ .random }}") {
Copy link
Member

Choose a reason for hiding this comment

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

This should be checked on admission and not be a possible path in practice. I think It's worth a // comment clarifying that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I think It'd be nice to have a comment on the piece of code that will never be exercised in practice
e.g.

// This should never happen as this is validated on admission.
if !strings.Contains(nameTemplate, "{{ .random }}") {
...

if err != nil {
return nil, err
}
nameTemplate := "{{ .machineDeployment.name }}-{{ .random }}"
Copy link
Member

Choose a reason for hiding this comment

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

This changes current behaviour as today we are using machineName := names.SimpleNameGenerator.GenerateName(fmt.Sprintf("%s-", machineSet.Name)) for this code path, right? is that intended? if so why?

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, I agree let's keep the default behavior the same as before, I will add another variable .machineSet.name in MachineNamingStrategy.Template in addition to .cluster.name , .machineDeployment.name and .random. End users can use it or skip it however they want.
But default will always be "{{ .machineSet.name }}-{{ .random }}"

machineName := names.SimpleNameGenerator.GenerateName(fmt.Sprintf("%s-", machineSet.Name))
// If the MachineSet is part of a MachineDeployment, check MachineNamingStrategy
// and name Machine accordingly.
if isDeploymentChild(machineSet) {
Copy link
Member

@sbueringer sbueringer Nov 6, 2024

Choose a reason for hiding this comment

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

TBD in my opinion if the MS controller should read this from the MD or if the MD controller should propagate the field down to the MS object and then the MS controller should read it from there

(I'm not sure myself at the moment :))

Copy link
Contributor Author

@adilGhaffarDev adilGhaffarDev Nov 6, 2024

Choose a reason for hiding this comment

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

Adding MachineNamingStrategy to MachineSet with values populated by the MachineDeployment controller would enable users to customize the MachineNamingStrategy for MachineSets that are not managed by a MachineDeployment. If we want to support this flexibility, we could consider adding MachineNamingStrategy to MachineSet too. Open to suggestions on this approach.

Copy link
Member

Choose a reason for hiding this comment

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

I'm leaning toward propagating via machineSet support, which I think is actually part of the original driving use case #10577.
That said, the current approach doesn't preclude us from implementing the latter in the future.

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 was adding MachineNamingStrategy to MachineSet and encountered an issue. Currently, MachineNamingStrategy.Template allows users to include the variable machineDeployment.name. However, if a MachineSet is not owned by a MachineDeployment, attempting to use the machineDeployment.name variable in the MachineNamingStrategy of a MachineSet will result in a failure.
To simplify this, I propose we remove support for machineDeployment.name and only retain machineSet.name. This change would streamline the logic, reducing potential confusion. If we were to support both variables, we would need to introduce a separate MachineNamingStrategy type specifically for MachineSet that only includes the machineSet.name variable, which would add complexity.
I’m leaning towards the simpler approach of removing machineDeployment.name and solely using machineSet.name. What are your thoughts on this?

Signed-off-by: Muhammad Adil Ghaffar <[email protected]>
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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 needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/machinedeployment Issues or PRs related to machinedeployments area/machineset Issues or PRs related to machinesets cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants