Skip to content

Commit 45dd158

Browse files
authored
Harden values files exclusion from bundle resources (#3956)
Values files may be referenced by file name alone, or with a directory prefix. Both variants now lead to values files being excluded from bundles resources, regardless of where a `fleet.yaml` file referencing them lives (inside or outside of a chart directory).
1 parent e8cd686 commit 45dd158

10 files changed

Lines changed: 81 additions & 0 deletions

File tree

integrationtests/cli/apply/apply_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,38 @@ var _ = Describe("Fleet apply", Ordered, func() {
219219
})
220220
})
221221
})
222+
223+
When("a fleet.yaml located beside a local chart dir references a values file prefixed by its directory", func() {
224+
BeforeEach(func() {
225+
name = "helm-values-ignore"
226+
dirs = []string{cli.AssetsPath + name}
227+
})
228+
229+
It("creates a bundle without the values file", func() {
230+
bundle, err := cli.GetBundleFromOutput(buf)
231+
Expect(err).NotTo(HaveOccurred())
232+
Expect(bundle.Spec.Resources).To(HaveLen(2))
233+
234+
Expect(cli.AssetsPath + "helm-values-ignore/config-chart/templates/configmap.yaml").To(bePresentInBundleResources(bundle.Spec.Resources))
235+
Expect(cli.AssetsPath + "helm-values-ignore/config-chart/Chart.yaml").To(bePresentInBundleResources(bundle.Spec.Resources))
236+
})
237+
})
238+
239+
When("a fleet.yaml located within a local chart dir references a values file prefixed by its directory", func() {
240+
BeforeEach(func() {
241+
name = "helm-in-chart-fleetyaml-values-ignore"
242+
dirs = []string{cli.AssetsPath + name}
243+
})
244+
245+
It("creates a bundle without the values file", func() {
246+
bundle, err := cli.GetBundleFromOutput(buf)
247+
Expect(err).NotTo(HaveOccurred())
248+
Expect(bundle.Spec.Resources).To(HaveLen(2))
249+
250+
Expect(cli.AssetsPath + "helm-in-chart-fleetyaml-values-ignore/config-chart/templates/configmap.yaml").To(bePresentInBundleResources(bundle.Spec.Resources))
251+
Expect(cli.AssetsPath + "helm-in-chart-fleetyaml-values-ignore/config-chart/Chart.yaml").To(bePresentInBundleResources(bundle.Spec.Resources))
252+
})
253+
})
222254
})
223255

224256
var _ = Describe("Fleet apply driven", Ordered, func() {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v2
2+
name: config-chart
3+
description: A test chart that verifies its config
4+
type: application
5+
version: 0.1.0
6+
appVersion: "1.16.0"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
helm:
2+
valuesFiles:
3+
- config-chart/values.yaml # resolves to `values.yaml` inside the same directory, but looks like an out-of-tree file
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: app-config
5+
data:
6+
test: "value"
7+
name: {{ .Values.name }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name: global.fleet.clusterLabels.management.cattle.io/cluster-display-name
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v2
2+
name: config-chart
3+
description: A test chart that verifies its config
4+
type: application
5+
version: 0.1.0
6+
appVersion: "1.16.0"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: app-config
5+
data:
6+
test: "value"
7+
name: {{ .Values.name }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name: global.fleet.clusterLabels.management.cattle.io/cluster-display-name
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
helm:
2+
chart: config-chart
3+
valuesFiles:
4+
- config-chart/values.yaml

internal/bundlereader/resources.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,29 @@ type loadOpts struct {
9898
// * spec.Targets[].Helm.ValuesFiles
9999
func ignoreApplyConfigs(spec *fleet.HelmOptions, targets ...fleet.BundleTarget) []string {
100100
ignore := []string{"fleet.yaml"}
101+
102+
// Values files may be referenced from `fleet.yaml` files either with their file name
103+
// alone, or with a directory prefix, for instance for a chart directory.
104+
// Values files must be ignored in both cases, and determining which of the filename or full path will be needed
105+
// depends on where the `fleet.yaml` file lives relatively to the values file(s) which it references.
101106
if spec != nil {
102107
ignore = append(ignore, spec.ValuesFiles...)
108+
109+
for _, vf := range spec.ValuesFiles {
110+
ignore = append(ignore, filepath.Base(vf))
111+
}
103112
}
104113

105114
for _, target := range targets {
106115
if target.Helm == nil {
107116
continue
108117
}
118+
109119
ignore = append(ignore, target.Helm.ValuesFiles...)
120+
121+
for _, vf := range target.Helm.ValuesFiles {
122+
ignore = append(ignore, filepath.Base(vf))
123+
}
110124
}
111125

112126
return ignore

0 commit comments

Comments
 (0)