-
Notifications
You must be signed in to change notification settings - Fork 28
MTV-3092: document new optional fields in PVC name template #749
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
base: main
Are you sure you want to change the base?
MTV-3092: document new optional fields in PVC name template #749
Conversation
b052856 to
10bda2e
Compare
| * *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 |
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.
@shdeshpa07 - please could you have a look at these examples
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.
a minor comment, if I am not rambling.
| + | ||
| [source,go] | ||
| ---- | ||
| disk-{{ mustRegexReplaceAll \".*[^0-9](+).vmdk\" .FileName \"\$1\" }} |
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.
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:
- .* - match any characters
- [^0-9] - match one non-digit character
- (.+) - capture one or more characters
- .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.
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 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
Signed-off-by: A.Arnold <[email protected]>
6b8f859 to
c33b283
Compare
Signed-off-by: A.Arnold <[email protected]>
| include::modules/pvc-naming-vmware-specific-template.adoc[leveloffset=+3] | ||
|
|
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.
| 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: |
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.
// 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.
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 have more variables, maybe we should put them all in the same list ?
| [source,go] | ||
| ---- | ||
| {{ .VmName | regex.Replace "[^a-zA-Z0-9-]" "-" }} | ||
| ---- |
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 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- |
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.
| 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 |
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.
mustRegexReplaceAll - is the only regexp variant we currently support
JIRA
PREVIEW