fix: interpolate a task file before it is parsed
A var used in container_limits broke the build, because FileConfigSource parses the file into an atc.TaskConfig before any interpolation happens, and '((container_mem_limit))' is not a memory limit. Only fields that are plain strings survived that first parse. FileConfigSource can now hand back the file as written, and InterpolateTemplateConfigSource resolves those bytes and parses once, instead of parsing, marshalling back and parsing again. For a task file the interpolation pass now always runs, with the pipeline vars followed by the credential variables, so a var resolves the same way wherever it appears in the file.
This commit is contained in:
1 parent
af4510fc7f
commit
10dad07bcd
4 files changed
+154
-24
No files matched your search
@@ -556,6 +556,64 @@ run: {path: a/file}
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when the config comes from a file that uses vars in container_limits", func() {
|
||||
var (
|
||||
fakeStreamer *execfakes.FakeStreamer
|
||||
artifactName string
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
artifactName = "some-artifact-name"
|
||||
fakeStreamer = new(execfakes.FakeStreamer)
|
||||
repo.RegisterArtifact(build.ArtifactName(artifactName), runtimetest.NewVolume("some-volume"), false)
|
||||
fakeStreamer.StreamFileReturns(gbytes.BufferWithBytes([]byte(`
|
||||
platform: linux
|
||||
|
||||
container_limits:
|
||||
cpu: ((container_cpu_limit))
|
||||
memory: ((container_mem_limit))
|
||||
|
||||
run: {path: ls}
|
||||
`)), nil)
|
||||
})
|
||||
|
||||
JustBeforeEach(func() {
|
||||
configSource = FileConfigSource{
|
||||
ConfigPath: artifactName + "/build.yml",
|
||||
Streamer: fakeStreamer,
|
||||
}
|
||||
configSource = InterpolateTemplateConfigSource{
|
||||
ConfigSource: configSource,
|
||||
Vars: []vars.Variables{vars.StaticVariables{
|
||||
"container_cpu_limit": 512,
|
||||
"container_mem_limit": "5gb",
|
||||
}},
|
||||
ExpectAllKeys: true,
|
||||
}
|
||||
fetchedConfig, fetchErr = configSource.FetchConfig(context.TODO(), logger, repo)
|
||||
})
|
||||
|
||||
It("interpolates the vars before the config is parsed", func() {
|
||||
Expect(fetchErr).ToNot(HaveOccurred())
|
||||
Expect(fetchedConfig.Limits).To(Equal(&atc.ContainerLimits{
|
||||
CPU: newCPULimit(512),
|
||||
Memory: newMemoryLimit(5 * 1024 * 1024 * 1024),
|
||||
}))
|
||||
})
|
||||
|
||||
Context("when the file is still invalid once the vars are resolved", func() {
|
||||
BeforeEach(func() {
|
||||
fakeStreamer.StreamFileReturns(gbytes.BufferWithBytes([]byte(`
|
||||
container_limits: {cpu: ((container_cpu_limit))}
|
||||
`)), nil)
|
||||
})
|
||||
|
||||
It("names the file it could not parse", func() {
|
||||
Expect(fetchErr).To(MatchError(ContainSubstring(artifactName + "/build.yml")))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Context("BaseResourceTypeDefaultsApplySource", func() {
|
||||
|
||||
Reference in new issue
Block a user