Skip to content

Conversation

@anarnold97
Copy link
Collaborator

@anarnold97 anarnold97 requested a review from yaacov August 27, 2025 18:23
@anarnold97 anarnold97 force-pushed the MTV-3092-document-new-optional-fields-in-PVC-name-template branch from b052856 to 10bda2e Compare August 27, 2025 19:37
* *Uniqueness of PVC Names*: If `pvcNameTemplateUseGenerateName` is set to `false`, it is crucial to ensure that your PVC naming template generates unique names to avoid conflicts during migration.

[id="pvc-name-regex-example-template-variables_{context}"]
== Regular expression examples for PVC name templates
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@shdeshpa07 - please could you have a look at these examples

Copy link
Collaborator

@shdeshpa07 shdeshpa07 left a comment

Choose a reason for hiding this comment

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

a minor comment, if I am not rambling.

+
[source,go]
----
disk-{{ mustRegexReplaceAll \".*[^0-9](+).vmdk\" .FileName \"\$1\" }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @anarnold97 - I was trying to analyze this regex based on the explanation, and I think it is missing a . in this pattern (+). Should it be (.+) ? And the \ in the .vmdk\ should be at the start, like this \.vmdk. That way, it will:

  1. .* - match any characters
  2. [^0-9] - match one non-digit character
  3. (.+) - capture one or more characters
  4. .vmdk - match literal ".vmdk"

So for this example, disk-vm001.vmdk, the output will be vm001.
For this example, test-vm-001.vmdk, the output will be 001.

Does that make sense? Or am I over-complicating things? Please feel free to ignore if it does not make sense. Disclaimer: I did use Claude to test the example.

The rest of the section looks good. Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

I agree about the missing dot

.*[^0-9](.+).vmdk

with the file named: win_drive_letter_is_C.vmdk

wil get the C drive letter we want

@anarnold97 anarnold97 force-pushed the MTV-3092-document-new-optional-fields-in-PVC-name-template branch from 6b8f859 to c33b283 Compare October 28, 2025 19:00
Signed-off-by: A.Arnold <[email protected]>
Comment on lines +162 to +163
include::modules/pvc-naming-vmware-specific-template.adoc[leveloffset=+3]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
include::modules/pvc-naming-vmware-specific-template.adoc[leveloffset=+3]

[id="pvc-name-template-variables_{context}"]
== PVC name template variables

When defining a `Plan` Custom Resource (CR) for migrations, you can use the following new variables within the `spec.preserveStaticIPs.pvcNameTemplate` field to dynamically generate PVC names:
Copy link
Member

Choose a reason for hiding this comment

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

    // PVCNameTemplate is a template for generating PVC names for VM disks.
	// Generated names must be valid DNS-1123 labels (lowercase alphanumerics, '-' allowed, max 63 chars).
	// It follows Go template syntax and has access to the following variables:
	//   - .VmName: name of the VM in the source cluster (original source name)
	//   - .TargetVmName: final VM name in the target cluster (may equal .VmName if no rename/normalization)
	//   - .PlanName: name of the migration plan
	//   - .DiskIndex: initial volume index of the disk
	//   - .WinDriveLetter: Windows drive letter (lowercase, if applicable, e.g. "c", requires guest agent)
	//   - .RootDiskIndex: index of the root disk
	//   - .Shared: true if the volume is shared by multiple VMs, false otherwise
	//   - .FileName: name of the file in the source provider (VMware only, filename includes the .vmdk suffix)
	// Note:
	//   This template can be overridden at the individual VM level.
	// Examples:
	//   "{{.TargetVmName}}-disk-{{.DiskIndex}}"
	//   "{{if eq .DiskIndex .RootDiskIndex}}root{{else}}data{{end}}-{{.DiskIndex}}"
	//   "{{if .Shared}}shared-{{end}}{{.VmName | lower}}-{{.DiskIndex}}"
	// See:
	// 	 https://github.com/kubev2v/forklift/tree/main/pkg/templateutil for template functions.

Copy link
Member

Choose a reason for hiding this comment

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

we have more variables, maybe we should put them all in the same list ?

[source,go]
----
{{ .VmName | regex.Replace "[^a-zA-Z0-9-]" "-" }}
----
Copy link
Member

Choose a reason for hiding this comment

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

we don't support regex. syntax, we have a list of supported functions:
https://github.com/kubev2v/forklift/tree/main/pkg/templateutil

Function Description Example
lower Converts string to lowercase {{ lower "TEXT" }} → text
upper Converts string to uppercase {{ upper "text" }} → TEXT
contains Checks if string contains substring {{ contains "hello" "lo" }} → true
replace Replaces occurrences in a string {{"I Am Henry VIII" | replace " " "-"}} → I-Am-Henry-VIII
trim Removes whitespace from both ends {{ trim " text " }} → text
trimAll Removes specified characters from both ends {{ trimAll "$" "$5.00$" }} → 5.00
trimSuffix Removes suffix if present {{ trimSuffix ".go" "file.go" }} → file
trimPrefix Removes prefix if present {{ trimPrefix "go." "go.file" }} → file
title Converts to title case {{ title "hello world" }} → Hello World
untitle Converts to lowercase {{ untitle "Hello World" }} → hello world
repeat Repeats string n times {{ repeat 3 "abc" }} → abcabcabc
substr Extracts substring from start to end {{ substr 1 4 "abcdef" }} → bcd
nospace Removes all whitespace {{ nospace "a b c" }} → abc
trunc Truncates string to specified length {{ trunc 3 "abcdef" }} → abc
initials Extracts first letter of each word {{ initials "John Doe" }} → JD
hasPrefix Checks if string starts with prefix {{ hasPrefix "go" "golang" }} → true
hasSuffix Checks if string ends with suffix {{ hasSuffix "ing" "coding" }} → true
mustRegexReplaceAll Replaces matches using regex with submatch expansion {{ mustRegexReplaceAll "a(x*)b" "-ab-axxb-" "${1}W" }} → -W-xxW-

Copy link
Member

Choose a reason for hiding this comment

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

Function Description Example
add Sum numbers {{ add 1 2 3 }} → 6
add1 Increment by 1 {{ add1 5 }} → 6
sub Subtract second number from first {{ sub 5 3 }} → 2
div Integer division {{ div 10 3 }} → 3
mod Modulo operation {{ mod 10 3 }} → 1
mul Multiply numbers {{ mul 2 3 4 }} → 24
max Return largest integer {{ max 1 5 3 }} → 5
min Return smallest integer {{ min 1 5 3 }} → 1
floor Round down to nearest integer {{ floor 3.75 }} → 3.0
ceil Round up to nearest integer {{ ceil 3.25 }} → 4.0
round Round to specified decimal places {{ round 3.75159 2 }} → 3.75

Copy link
Member

Choose a reason for hiding this comment

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

mustRegexReplaceAll - is the only regexp variant we currently support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants