Fix: use POSIX path separators for node-agent hostPath volumes. Fix issue #9415#9416
Fix: use POSIX path separators for node-agent hostPath volumes. Fix issue #9415#9416Mykhailo-Roit wants to merge 1 commit intovmware-tanzu:mainfrom
Conversation
When running velero install from Windows CLI, filepath.Join() was generating Windows-style paths with backslashes (e.g., \var\lib\kubelet\pods) in the generated DaemonSet manifest. However, these manifests are applied to Linux Kubernetes clusters which require forward slashes. This fix ensures hostPath.path always uses forward slashes by replacing filepath.Join() with string concatenation, so the generated manifests work correctly regardless of the CLI host OS. Fixes vmware-tanzu#9415
| hostPluginsVolumePath := filepath.Join(c.kubeletRootDir, "plugins") | ||
| // Use forward slashes for hostPath paths to ensure POSIX-style paths in generated manifests | ||
| // even when velero CLI runs on Windows. Kubernetes hostPath.path must use '/' separator. | ||
| kubeletRoot := strings.TrimRight(c.kubeletRootDir, "/\\") |
There was a problem hiding this comment.
kubeletRootDir could be specified by users, so in a Windows cluster, users may specify a Windows styled path, e.g., C:\\var\\lib\\kubelet.
As a result, it ends with a path mixed with / and \\, e.g., C:\\var\\lib\\kubelet/pods.
Even though Windows supports this mix, but since you are making this change for the purpose of Use forward slashes for hostPath paths to ensure POSIX-style path in generated manifests and it looks the right way, could you consider the above case and make the entire path in POSIX style?
There was a problem hiding this comment.
The --use-node-agent flag indicates that an agent must be deployed on the Linux cluster.
There was a problem hiding this comment.
Yes, but the code here is shared by both linux cluster installation and Windows cluster installation.
Please add a summary of your change
When running velero install from Windows CLI, filepath.Join() was generating Windows-style paths with backslashes (e.g., \var\lib\kubelet\pods) in the generated DaemonSet manifest. However, these manifests are applied to Linux Kubernetes clusters which require forward slashes.
This fix ensures hostPath.path always uses forward slashes by replacing filepath.Join() with string concatenation, so the generated manifests work correctly regardless of the CLI host OS.
Does your change fix a particular issue?
Fixes #(9415)