-
Notifications
You must be signed in to change notification settings - Fork 296
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 VM naming strategy for VMs in govmomi mode #3286
base: main
Are you sure you want to change the base?
Conversation
Welcome @viveksyngh! |
Hi @viveksyngh. 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 Once the patch is verified, the new status will be reflected by the 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. |
c0c07cd
to
7ca274d
Compare
7ca274d
to
0deb41a
Compare
026364a
to
782c264
Compare
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.
please give a ping once this is no longer a draft and is ready for review.
/cc
make sure you add a test. |
275cf76
to
bd815fd
Compare
@@ -68,6 +68,30 @@ type VSphereMachineSpec struct { | |||
// | |||
// +optional | |||
GuestSoftPowerOffTimeout *metav1.Duration `json:"guestSoftPowerOffTimeout,omitempty"` | |||
|
|||
// NamingStrategy allows configuring the naming strategy used when calculating the name of the VSphereVM. |
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.
calculating -> preparing
as it's not a math calculation.
EDIT: seems consistent with the supervisor PR. so you can leave it as is.
name of the VSphereVM.
this field is inside VSphereMachineSpec not VSphereVMSpec
// VSphereVMNamingStrategy defines the naming strategy for the VSphereVMs. | ||
type VSphereVMNamingStrategy struct { |
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.
should this be named
VSphereMachineNamingStrategy
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.
+1, as this struct is used at the VSphereMachine
return nil, AggregateObjErrors(newTyped.GroupVersionKind().GroupKind(), newTyped.Name, allErrs) | ||
} | ||
|
||
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type. | ||
func (webhook *VSphereMachineTemplateWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) { | ||
return nil, nil | ||
} | ||
|
||
func validateVSphereVMNamingTemplate(_ context.Context, vsphereMachineTemplate *infrav1.VSphereMachineTemplate) field.ErrorList { |
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.
is this following some code that core CAPI already has or is this done from scratch as a use case for CAPV?
if the former, could you link to that code for reviewer's reference?
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 is based on this MR which was added to support this in supervisor mode #3099
In supervisor mode, the object is called VirtualMachine which drives the creation of vSphere VMs while in govami mode this object is called VSphereVM.
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.
looks like a lot comes from that PR.
why not also name it VirtualMachineNamingStrategy here? that seems more consistent despite the diff backend objects.
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 can do that if we prefer that. I just to wanted to call it what it is being used for.
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.
that would be my preference. not sure what other reviewers will comment 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.
👍 to keep it as VSphereVM, because that's the object which gets created from a VSphereMachine.
pkg/services/vimmachine.go
Outdated
maxNameLength = 63 | ||
) | ||
|
||
// Note: Inlining these functions from sprig to avoid introducing a dependency. |
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.
sprig is a typo?
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.
Its related to https://masterminds.github.io/sprig/
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.
you can't just copy code from another project without attribution. also CNCF has special handling of MIT and some other licenses. see https://github.com/cncf/foundation/blob/main/allowed-third-party-license-policy.md#cncf-allowlist-license-policy
please add the entire dependency and let the go compiler optimize.
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.
/hold
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.
Note: we don't want to simply import the whole sprig library and use the function from there to prevent the transitive dependencies. Instead we should better outline the license part here and propably move the inlined functions to a separate package.
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.
given it will be a fork the project can copy only the bits that it needs. a readme or just a code comment clarifing purpose and origin of the forked bits would suffice. original license file and license header too.
in the k/k third-party dir there are cases like 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.
Took a look at the CAPI go.mod file. We already have a direct dependency to sprig there. I think it's okay to have the same in CAPV. So I would just take the direct dependency and we're good.
(there's not much point to avoiding the dependency in CAPV if we have it in CAPI)
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 is already in the main and we are using it. https://github.com/kubernetes-sigs/cluster-api-provider-vsphere/blob/main/pkg/services/vmoperator/vmopmachine.go#L298
I could not reuse it because they were ware private and not exported. Depending what we decide, I can make the change.
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 is already in the main and we are using it. https://github.com/kubernetes-sigs/cluster-api-provider-vsphere/blob/main/pkg/services/vmoperator/vmopmachine.go#L298
I could not reuse it because they were ware private and not exported. Depending what we decide, I can make the change.
all copied code from a different license without attribution must be removed.
import the library and use its exported functions.
if what you need from the library is not exported, go with the minimal fork 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 have update the MR where I imported the function sprig library and use only those functions which are required.
Please take a look.
- op: add | ||
path: /spec/template/spec/namingStrategy | ||
value: | ||
template: '{{ if le (len .machine.name) 20 }}{{ .machine.name }}{{else}}{{ trimSuffix "-" (trunc 14 .machine.name) }}-{{ trunc -5 .machine.name }}{{end}}' |
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.
add missing new line at the end.
This MR is more or less similar code from this MR which added the functionality in the supervisor mode. #3099 I can make the requested changes but I have tried to align this as much as possible with supervisor mode changes. |
/ok-to-test |
|
[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 |
- Add VM naming stragey for vsphere vms and VMs in govami mode
- Rename the type to VSphereVMNamingStrategy and update docs, function name etc
95e63a5
to
bee7c57
Compare
bee7c57
to
f46b867
Compare
f46b867
to
07f2025
Compare
dario.cat/mergo v1.0.1 // indirect | ||
github.com/Masterminds/goutils v1.1.1 // indirect | ||
github.com/Masterminds/semver/v3 v3.3.0 // indirect |
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.
These dependencies are something we might want to prevent having.
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 these came up from sprig library.
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.
Just noted: This now adds a new dependency to github.com/Masterminds/sprig/v3
, while we currently only have a go dependency to github.com/go-task/slim-sprig/v3
.
github.com/mitchellh/copystructure v1.2.0 // indirect | ||
github.com/mitchellh/reflectwalk v1.0.2 // indirect |
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.
These dependencies are even archived and not maintained anymore.
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.
cc @sbueringer , not sure if we should instead do the third_party approach with "minimal" change 🤔
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.
xref #3286 (comment)
We want to import a different sprig so this may be gone then
{ | ||
name: "successful VSphereMachineTemplate creation with namingStrategy not set", | ||
vsphereMachine: createVSphereMachineTemplate("foo.com", "vmx-17", nil, "", []string{}, nil, nil), | ||
}, |
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.
{ | |
name: "successful VSphereMachineTemplate creation with namingStrategy not set", | |
vsphereMachine: createVSphereMachineTemplate("foo.com", "vmx-17", nil, "", []string{}, nil, nil), | |
}, |
Duplicate test case to above, let's adjust the name above though.
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.
/hold due to the breakage of findVSphereVM
var nameTpl = template.New("name generator").Funcs(nameTemplateFuncs).Option("missingkey=error") | ||
|
||
// GenerateVSphereVMName generates the name of a VSphereVM based on the naming strategy. | ||
func GenerateVSphereVMName(machineName string, namingStrategy *infrav1.VSphereVMNamingStrategy) (string, error) { |
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 function seems to be the same as we have for supervisor?
Let's move this to pkg/util
to a separate go file and use it at both places.
/hold cancel As above noted #3286 (comment) |
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 #