Skip to content

Commit 0944f23

Browse files
authored
fix: correctly copy Helm charts in init container (#1018)
During upgrades the init container was incorrectly copying the whole directory, instead of just the tars. ``` # bundles directory in the container $ ls /helm-charts/bundles/ charts helm-charts-v0.14.6.tar helm-charts-v0.14.9.tar helm-charts-v0.23.1.tar # incorrectly nested directory with the new charts $ ls /helm-charts/bundles/charts/ helm-charts-v0.14.6.tar helm-charts-v0.14.9.tar helm-charts-v0.25.0.tar ``` **What problem does this PR solve?**: **Which issue(s) this PR fixes**: Fixes # **How Has This Been Tested?**: <!-- Please describe the tests that you ran to verify your changes. Provide output from the tests and any manual steps needed to replicate the tests. --> The file gets copied correctly when the directory does not exist: ``` $ cp -r charts/ dst/ $ ls dst foo.tar ``` When the dir already exists (ie upgrade scenario), the whole directory gets copied: ``` $ mkdir dst $ cp -r charts/ dst/ $ ls dst charts ``` Copying the file works correctly into an existing dst if using .: ``` $ mkdir dst $ cp -r charts/. dst/ $ ls dst foo.tar ``` **Special notes for your reviewer**: <!-- Use this to provide any additional information to the reviewers. This may include: - Best way to review the PR. - Where the author wants the most review attention on. - etc. -->
1 parent a78b9d4 commit 0944f23

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

charts/cluster-api-runtime-extensions-nutanix/templates/helm-repository.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,18 @@ spec:
6363
initContainers:
6464
- name: copy-charts
6565
image: "{{ .Values.helmRepository.images.bundleInitializer.repository }}:{{ default $.Chart.AppVersion .Values.helmRepository.images.bundleInitializer.tag }}"
66-
command: ["/bin/cp", "-r", "/charts/", "/helm-charts/bundles/"]
66+
# Copy the charts bundled in the image to the mounted PVC.
67+
# The combination of flags `--recursive --no-target-directory` ensure that the bundled directory contents only are copied to the destination,
68+
# rather than copying the source directory itself to the destination, which would lead to incorrect nesting.
69+
# See https://unix.stackexchange.com/a/94838 for further explanation.
70+
# Globs cannot be used here because we are not running in a shell and `cp` does not natively support globbing.
71+
command:
72+
- /bin/cp
73+
- --recursive
74+
- --no-target-directory
75+
- --verbose
76+
- /charts/
77+
- /helm-charts/bundles/
6778
imagePullPolicy: "{{ .Values.image.pullPolicy }}"
6879
volumeMounts:
6980
- name: charts-volume

0 commit comments

Comments
 (0)