Skip to content

Commit 10bda2e

Browse files
committed
MTV-3092: document new optional fields in PVC name template
Signed-off-by: A.Arnold <[email protected]>
1 parent 4243c6a commit 10bda2e

File tree

3 files changed

+145
-4
lines changed

3 files changed

+145
-4
lines changed

documentation/doc-Migration_Toolkit_for_Virtualization/master.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ include::modules/selecting-migration-network-for-virt-provider.adoc[leveloffset=
192192

193193
include::modules/creating-plan-wizard-290-vmware.adoc[leveloffset=+2]
194194

195+
include::modules/pvc-naming-vmware-specific-template.adoc[leveloffset=+3]
196+
195197
include::modules/running-migration-plan.adoc[leveloffset=+2]
196198

197199
include::modules/migration-plan-options-ui.adoc[leveloffset=+2]

documentation/modules/creating-plan-wizard-290-vmware.adoc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ If the conversion fails because the boot device provided is incorrect, it is pos
155155
Migrating shared disks might slow down the migration process.
156156
====
157157
+
158-
** To migrate shared disks in the migration plan, verify that *Shared disks* is selected in the checkbox.
158+
** To migrate shared disks in the migration plan, verify that *Shared disks* is selected in the checkbox.
159159
** To avoid migrating shared disks, clear the *Shared disks* checkbox.
160160

161161
. Click *Next*.
@@ -255,8 +255,8 @@ Variable names cannot exceed 63 characters.
255255
*** Click the *Virtual Machines* tab.
256256
*** Select the desired VMs.
257257
*** Click the {kebab} of the VM.
258-
*** Select *Edit PVC name template*.
259-
*** Enter the template according to the instructions.
258+
*** Select *Edit PVC name template*. For more details, see xref:pvc-naming-vmware-specific-template_vmware[PVC naming with {vmw}-specific template variables].
259+
*** *** Enter the template according to the instructions.
260260
*** Click *Save*.
261261
+
262262
[IMPORTANT]
@@ -334,4 +334,3 @@ The *Plan details* page also includes five additional tabs, which are described
334334
|Editable specification of the network and storage maps used by your plan
335335
|Updatable specification of the hooks used by your plan, if any
336336
|===
337-
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * documentation/doc-Migration_Toolkit_for_Virtualization/master.adoc
4+
5+
:_content-type: CONCEPT
6+
[id="pvc-naming-vmware-specific-template_{context}"]
7+
= PVC naming with {vmw}-specific template variables
8+
9+
The {project-first} provides additional template variables for defining custom Persistent Volume Claim (PVC) names in migration plans, enhancing the clarity and manageability of migrated VM disks. These new variables, primarily applicable to {vmw} vSphere source providers, allow for more granular control over PVC naming by incorporating details such as Microsoft Windows drive letters and VMDK filenames.
10+
11+
[id="pvc-name-template-variables_{context}"]
12+
== PVC name template variables
13+
14+
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:
15+
16+
* *`.WinDriveLetter`*: This variable allows you to include the Windows drive letter of a disk (for example, "`c`") in the PVC name.
17+
18+
** *Requirement*: The use of `.WinDriveLetter` *requires the guest agent* to be installed and running on the source Windows VM for this information to be available.
19+
20+
* *`.FileName`*: This variable provides the name of the disk backing file from the source provider (e.g., `vm-disk.vmdk`).
21+
22+
** *Applicability*: This variable is *available for {vmw} vSphere source providers only*.
23+
24+
** *Requirement*: The `.FileName` value is derived directly from the vSphere API and *does not require a guest agent* on the VM.
25+
26+
These variables are part of the `PVCNameTemplateData` structure, which also includes other fields like `VmName`, `PlanName`, `DiskIndex`, `RootDiskIndex`, and `Shared`.
27+
28+
*Usage in a Migration Plan* These new variables can be used in the `pvcNameTemplate` field within your `Plan` CR. For example, you might define a template that incorporates the VM name and the disk’s filename.
29+
30+
This functionality extends to the volume populator flow, ensuring PVC name templates are respected during data import.
31+
32+
Example Plan CR snippet using new PVC template variables:
33+
34+
[source,yaml]
35+
----
36+
apiVersion: forklift.konveyor.io/v1beta1
37+
kind: Plan
38+
metadata:
39+
name: <plan>
40+
namespace: <namespace>
41+
spec:
42+
# ... other plan configurations ...
43+
preserveStaticIPs:
44+
pvcNameTemplate: "{{ .VmName }}-{{ .FileName | regexReplaceAll `\\.vmdk$` `` | toLower }}" # Example using .FileName
45+
# pvcNameTemplate: "{{ .VmName }}-disk-{{ .WinDriveLetter }}" # Example using .WinDriveLetter
46+
pvcNameTemplateUseGenerateName: true # Or false, with caution
47+
targetNamespace: <target_namespace>
48+
vms:
49+
- id: <source_vm1_moRef_or_UUID>
50+
# ... other VM configurations ...
51+
----
52+
53+
[NOTE]
54+
====
55+
The example above uses `regexReplaceAll` and `toLower` functions which might be available in the Go template syntax supported by {project-short}.
56+
====
57+
58+
[id="pvc-naming-important-considerations-validations_{context}"]
59+
== Important considerations and validation
60+
61+
* *Guest Agent for `WinDriveLetter`*: To accurately retrieve the Windows drive letter, ensure that {vmw} Tools (which includes the `qemu-guest-agent`) is installed and running on your source Windows VMs.
62+
63+
* *Filename Format*: The `.FileName` variable will include the `.vmdk` extension for {vmw} vSphere disks. You may use template functions (like string manipulation or regular expressions) to modify this as needed.
64+
65+
* *PVC Name Restrictions*: PVC names generated by templates must adhere to the Kubernetes DNS-1123 label format. This is enforced during validation because PVC names are often reused as Kubernetes labels in other parts of the codebase. Templates that produce whitespace-only or excessively long output (e.g., over 57 characters if `pvcNameTemplateUseGenerateName` is set to `true`) will fail validation.
66+
67+
* *Validation and Error Reporting*: {project-short} now validates the PVC name template earlier in the process using information from the plan’s VM inventory. Any template errors will be detailed in the plan conditions and logged, allowing for quicker identification and troubleshooting.
68+
69+
* *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.
70+
71+
[id="pvc-name-regex-example-template-variables_{context}"]
72+
== Regular expression examples for PVC name templates
73+
74+
The {project-short} supports GoLang template syntax for Persistent Volume Claim (PVC) name templates, which can include regular expressions to create dynamic and descriptive names. This is useful for extracting specific information from source VM characteristics, such as {vmw} vSphere VMDK filenames.
75+
76+
* *Extracting Disk Number from {vmw} VMDK Filename*: This example uses the `.FileName` variable, which provides the name of the disk backing file from {vmw} vSphere, to extract a numeric identifier from the filename. This is especially helpful when the Windows drive letter might be encoded within the filename itself, in cases where the guest agent is not available or reliable for providing the drive letter directly.
77+
+
78+
[source,go]
79+
----
80+
disk-{{ mustRegexReplaceAll \".*[^0-9](+).vmdk\" .FileName \"\$1\" }}
81+
----
82+
+
83+
*Explanation*: This template attempts to find a sequence of one or more digits (`{plus}`) immediately preceding `.vmdk` and preceded by a non-digit character (`++[++^0-9++]++`), capturing these digits (`++\++$1`) for use in the PVC name. This helps in generating PVC names that are based on specific disk identifiers from the original VMDK file.
84+
+
85+
It is important to note that while the `.WinDriveLetter` variable can directly provide the Windows drive letter (if a guest agent is installed on the source Windows VM), using regular expression with `.FileName` offers an alternative for scenarios where the drive letter is embedded in the filename.
86+
+
87+
When creating custom PVC name templates, ensure the generated names comply with Kubernetes DNS-1123 label format, which includes
88+
restrictions on characters and length. {project-short} will validate the template during the plan creation process and report any errors in the plan conditions.
89+
90+
91+
* *Sanitizing Illegal Characters*: This is a common use case to ensure the resulting PVC name is valid for Kubernetes, which has strict naming conventions.
92+
+
93+
[source,go]
94+
----
95+
{{ .VmName | regex.Replace "[^a-zA-Z0-9-]" "-" }}
96+
----
97+
+
98+
*Explanation*: `{{ .VmName }}` is the input variable—the virtual machine's name. `| regex.Replace` is the function that performs the regular expression replacement. The pipe symbol | passes the .VmName value as the input to the function.
99+
+
100+
The `"[^a-zA-Z0-9-]"` regular expression pattern matches any character that is not a lowercase letter (a-z), an uppercase letter (A-Z), a digit (0-9), or a hyphen (-).
101+
+
102+
"-": This is the replacement string. Any character that matches the pattern will be replaced with a hyphen.
103+
+
104+
If your VM is named `vm_name-with.dots`, the resulting PVC name will be `vm-name-with-dots`.
105+
106+
* *Extracting a Specific Part of a Name*: You can use regular expression to extract a piece of information, such as a drive letter, from a more complex filename:
107+
+
108+
[source,go]
109+
----
110+
{{ .FileName | regex.Find "[a-zA-Z]$" }}
111+
----
112+
+
113+
*Explanation*: `{{ .FileName }}` is the input variable, which is the filename of the virtual disk from the source provider.
114+
+
115+
The `| regex.Find` function finds the first substring that matches the provided regular expression pattern.
116+
+
117+
The `"[a-zA-Z]$"` regular expression pattern matches any single letter ([a-zA-Z]) that appears at the end of the string ($).
118+
+
119+
If the disk's filename is `windows-disk-D`, this template will extract just the letter D.
120+
121+
* *Conditional Logic with regular expression*: For more advanced scenarios, you can combine regular expression matching with an if statement to apply logic based on whether a pattern exists:
122+
+
123+
[source,go]
124+
----
125+
{{ if .VmName | regex.Match "^db-" }}{{ .VmName | regex.Replace "^db-" "production-db-" }}{{ else }}{{ .VmName }}{{ end }}
126+
----
127+
+
128+
*Explanation*: `{{ if ... }}` starts a conditional block.
129+
+
130+
`.VmName | regex.Match "^db-"` checks if the VM name starts with the prefix `db-`. The caret `^` anchors the match to the beginning of the string.
131+
+
132+
`{{ .VmName | regex.Replace ... }}` means that if the condition is *true*, this section is executed, replacing `db-` with `production-db-`.
133+
+
134+
`{{ else }}` means that if the condition is *false*, the template falls back to this section.
135+
+
136+
`{{ .VmName }}` means that the original VM name is used if it does not match the regular expression.
137+
+
138+
If your VM is named `db-mysql-primary`, the PVC name will become `production-db-mysql-primary`.
139+
+
140+
While if your VM is named `web-server-01`, the PVC name will remain `web-server-01`.

0 commit comments

Comments
 (0)