-
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
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.
test/e2e/data/infrastructure-vsphere-govmomi/main/clusterclass/patch-vm-namingstrategy.yaml
Outdated
Show resolved
Hide resolved
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 |
|
- Add VM naming stragey for vsphere vms and VMs in govami mode
- Rename the type to VSphereVMNamingStrategy and update docs, function name etc
01677ca
to
b39b4d6
Compare
3079d2d
to
ed589aa
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.
Last findings, happy to get this merged once that's fixed.
Thanks for working on it and sorry for taking so long :-) 🎉
pkg/util/template.go
Outdated
|
||
tpl, err := nameTpl.Parse(*nameTemplate) | ||
if err != nil { | ||
return "", errors.Wrapf(err, "failed to generate name: failed to parse template %q", *nameTemplate) |
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.
return "", errors.Wrapf(err, "failed to generate name: failed to parse template %q", *nameTemplate) | |
return "", errors.Wrapf(err, "unable to parse template %q", *nameTemplate) |
(the failed to generate name for VSphereVM / VirtualMachine
comes at above error wraping)
pkg/util/template.go
Outdated
|
||
var buf bytes.Buffer | ||
if err := tpl.Execute(&buf, data); err != nil { | ||
return "", errors.Wrap(err, "failed to generate name") |
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.
return "", errors.Wrap(err, "failed to generate name") | |
return "", err |
pkg/util/template_test.go
Outdated
"k8s.io/utils/ptr" | ||
) | ||
|
||
func Test_GenerateVSphereVMName(t *testing.T) { |
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.
func Test_GenerateVSphereVMName(t *testing.T) { | |
func Test_GenerateMachineNameFromTemplate(t *testing.T) { |
pkg/util/template.go
Outdated
|
||
// GenerateNameFromMachineNameTemplate generate a name from machine name and a naming strategy template. | ||
// the template supports only `trimSuffix` and `trunc` functions. | ||
func GenerateNameFromMachineNameTemplate(machineName string, nameTemplate *string) (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.
func GenerateNameFromMachineNameTemplate(machineName string, nameTemplate *string) (string, error) { | |
func GenerateMachineNameFromTemplate(machineName string, nameTemplate *string) (string, error) { |
pkg/util/template_test.go
Outdated
got, err := GenerateNameFromMachineNameTemplate(tt.machineName, tt.template) | ||
|
||
if (err != nil) != tt.wantErr { | ||
t.Errorf("GenerateVSphereVMName error = %v, wantErr %v", err, tt.wantErr) |
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.
t.Errorf("GenerateVSphereVMName error = %v, wantErr %v", err, tt.wantErr) | |
t.Errorf("GenerateMachineNameFromTemplate error = %v, wantErr %v", err, tt.wantErr) |
pkg/util/template_test.go
Outdated
wantErr bool | ||
}{ | ||
{ | ||
name: "default template", |
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: "default template", | |
name: "return machineName if template is nil", |
Add a slim sprig package to avoid additional dependencies and move the common logic to util package
ed589aa
to
d847731
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.
/lgtm
/assign @sbueringer for a final round
LGTM label has been added. Git tree hash: ff52f7202abf13b802ad93309b20bd03fc9cef12
|
/test help |
@chrischdi: The specified target(s) for
The following commands are available to trigger optional jobs:
Use
In response to this:
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. |
For checking ci /hold |
/test pull-cluster-api-provider-vsphere-e2e-vcsim-govmomi-main |
Let's see how it behaves at team-cluster-api#57 |
/retest to see if its a flake or an issue |
/test pull-cluster-api-provider-vsphere-e2e-vcsim-govmomi-main |
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 #