-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
base: main
Are you sure you want to change the base?
🌱 Add NamingStrategy to MachineDeployment #11172
Conversation
Skipping CI for Draft Pull Request. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
61ad775
to
e03d550
Compare
/hold |
e03d550
to
3559d2c
Compare
/area machineset |
f588f68
to
10956bd
Compare
10956bd
to
2cf9110
Compare
5438128
to
6c5de96
Compare
cc @sbueringer @fabriziopandini @chrischdi |
I have verified that it is working as expected with a real end-to-end test. Thanks for working on this @adilGhaffarDev ! |
/unhold |
6c5de96
to
f56abac
Compare
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 }}") { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are checking it in webhook: https://github.com/kubernetes-sigs/cluster-api/pull/11172/files#diff-b6bae0ed28a4f55a318d296bc63afcff0c7751968346a551ef23f7360a89fd74R313
Where should I add the // comment ?
There was a problem hiding this comment.
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 }}" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 :))
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me
f56abac
to
87df1f2
Compare
87df1f2
to
6f6380a
Compare
6f6380a
to
b409bfa
Compare
Signed-off-by: Muhammad Adil Ghaffar <[email protected]>
b409bfa
to
be9737a
Compare
If the PR is not merged in the meantime, I'll get back to this once I'm back from PTO |
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