Skip to content

Commit

Permalink
rename the type to VSphereVMNamingStrategy
Browse files Browse the repository at this point in the history
- Rename the type to VSphereVMNamingStrategy and update docs, function name etc
  • Loading branch information
viveksyngh committed Dec 11, 2024
1 parent 0deb41a commit 782c264
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 40 deletions.
12 changes: 6 additions & 6 deletions apis/v1beta1/vspheremachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ type VSphereMachineSpec struct {
// +optional
GuestSoftPowerOffTimeout *metav1.Duration `json:"guestSoftPowerOffTimeout,omitempty"`

// NamingStrategy allows configuring the naming strategy used when calculating the name of the VirtualMachine.
// NamingStrategy allows configuring the naming strategy used when calculating the name of the VSphereVMs.
// +optional
NamingStrategy *VirtualMachineNamingStrategy `json:"namingStrategy,omitempty"`
NamingStrategy *VSphereVMNamingStrategy `json:"namingStrategy,omitempty"`
}

// VirtualMachineNamingStrategy defines the naming strategy for the VirtualMachines.
type VirtualMachineNamingStrategy struct {
// Template defines the template to use for generating the name of the VirtualMachine object.
// VSphereVMNamingStrategy defines the naming strategy for the VSphereVMs.
type VSphereVMNamingStrategy struct {
// Template defines the template to use for generating the name of the VSphereVMs object.
// If not defined, it will fall back to `{{ .machine.name }}`.
// The templating has the following data available:
// * `.machine.name`: The name of the Machine object.
Expand All @@ -86,7 +86,7 @@ type VirtualMachineNamingStrategy struct {
// Notes:
// * While the template offers some flexibility, we would like the name to link to the Machine name
// to ensure better user experience when troubleshooting
// * Generated names must be valid Kubernetes names as they are used to create a VirtualMachine object
// * Generated names must be valid Kubernetes names as they are used to create a VSphereVMs object
// and usually also as the name of the Node object.
// * Names are automatically truncated at 63 characters. Please note that this can lead to name conflicts,
// so we highly recommend to use a template which leads to a name shorter than 63 characters.
Expand Down
42 changes: 21 additions & 21 deletions apis/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1028,11 +1028,11 @@ spec:
type: integer
namingStrategy:
description: NamingStrategy allows configuring the naming strategy
used when calculating the name of the VirtualMachine.
used when calculating the name of the VSphereVMs.
properties:
template:
description: |-
Template defines the template to use for generating the name of the VirtualMachine object.
Template defines the template to use for generating the name of the VSphereVMs object.
If not defined, it will fall back to `{{ .machine.name }}`.
The templating has the following data available:
* `.machine.name`: The name of the Machine object.
Expand All @@ -1042,7 +1042,7 @@ spec:
Notes:
* While the template offers some flexibility, we would like the name to link to the Machine name
to ensure better user experience when troubleshooting
* Generated names must be valid Kubernetes names as they are used to create a VirtualMachine object
* Generated names must be valid Kubernetes names as they are used to create a VSphereVMs object
and usually also as the name of the Node object.
* Names are automatically truncated at 63 characters. Please note that this can lead to name conflicts,
so we highly recommend to use a template which leads to a name shorter than 63 characters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -898,11 +898,11 @@ spec:
type: integer
namingStrategy:
description: NamingStrategy allows configuring the naming
strategy used when calculating the name of the VirtualMachine.
strategy used when calculating the name of the VSphereVMs.
properties:
template:
description: |-
Template defines the template to use for generating the name of the VirtualMachine object.
Template defines the template to use for generating the name of the VSphereVMs object.
If not defined, it will fall back to `{{ .machine.name }}`.
The templating has the following data available:
* `.machine.name`: The name of the Machine object.
Expand All @@ -912,7 +912,7 @@ spec:
Notes:
* While the template offers some flexibility, we would like the name to link to the Machine name
to ensure better user experience when troubleshooting
* Generated names must be valid Kubernetes names as they are used to create a VirtualMachine object
* Generated names must be valid Kubernetes names as they are used to create a VSphereVMs object
and usually also as the name of the Node object.
* Names are automatically truncated at 63 characters. Please note that this can lead to name conflicts,
so we highly recommend to use a template which leads to a name shorter than 63 characters.
Expand Down
14 changes: 7 additions & 7 deletions pkg/services/vimmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func (v *VimMachineService) createOrPatchVSphereVM(ctx context.Context, vimMachi
// generateVMObjectName returns a new VM object name in specific cases, otherwise return the same
// passed in the parameter.
func generateVMObjectName(vimMachineCtx *capvcontext.VIMMachineContext, machineName string) (string, error) {
name, err := GenerateVirtualMachineName(machineName, vimMachineCtx.VSphereMachine.Spec.NamingStrategy)
name, err := GenerateVSphereVMName(machineName, vimMachineCtx.VSphereMachine.Spec.NamingStrategy)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -442,11 +442,11 @@ var nameTemplateFuncs = map[string]any{

var nameTpl = template.New("name generator").Funcs(nameTemplateFuncs).Option("missingkey=error")

// GenerateVirtualMachineName generates the name of a VirtualMachine based on the naming strategy.
func GenerateVirtualMachineName(machineName string, namingStrategy *infrav1.VirtualMachineNamingStrategy) (string, error) {
// Per default the name of the VirtualMachine should be equal to the Machine name (this is the same as "{{ .machine.name }}")
// GenerateVSphereVMName generates the name of a VSphereVM based on the naming strategy.
func GenerateVSphereVMName(machineName string, namingStrategy *infrav1.VSphereVMNamingStrategy) (string, error) {
// Per default the name of the VSphereVM should be equal to the Machine name (this is the same as "{{ .machine.name }}")
if namingStrategy == nil || namingStrategy.Template == nil {
// Note: No need to trim to max length in this case as valid Machine names will also be valid VirtualMachine names.
// Note: No need to trim to max length in this case as valid Machine names will also be valid VSphereVM names.
return machineName, nil
}

Expand All @@ -459,12 +459,12 @@ func GenerateVirtualMachineName(machineName string, namingStrategy *infrav1.Virt

tpl, err := nameTpl.Parse(nameTemplate)
if err != nil {
return "", errors.Wrapf(err, "failed to generate name for VirtualMachine: failed to parse namingStrategy.template %q", nameTemplate)
return "", errors.Wrapf(err, "failed to generate name for VSphereVM: failed to parse namingStrategy.template %q", nameTemplate)
}

var buf bytes.Buffer
if err := tpl.Execute(&buf, data); err != nil {
return "", errors.Wrap(err, "failed to generate name for VirtualMachine")
return "", errors.Wrap(err, "failed to generate name for VSphereVM")
}

name := buf.String()
Expand Down

0 comments on commit 782c264

Please sign in to comment.