Fix sidecar env vars (#1292)

This commit is contained in:
Daniel Kurzynski
2020-03-20 11:36:16 +01:00
committed by GitHub
parent 8fbeddb26c
commit 6bd259e5d4
3 changed files with 14 additions and 15 deletions
@@ -294,6 +294,7 @@ class DockerExecuteOnKubernetesTest extends BasePiperTest {
dockerEnvVars: ['http_proxy': 'http://proxy:8000'],
dockerWorkspace: '/home/piper',
sidecarEnvVars: ['testEnv': 'testVal'],
sidecarWorkspace: '/home/piper/sidecar',
sidecarImage: 'postgres',
sidecarName: 'postgres',
sidecarReadyCommand: 'pg_isready'
@@ -305,6 +306,9 @@ class DockerExecuteOnKubernetesTest extends BasePiperTest {
assertThat(containersList, allOf(hasItem('postgres'), hasItem('mavenexecute')))
assertThat(imageList, allOf(hasItem('maven:3.5-jdk-8-alpine'), hasItem('postgres')))
assertThat(envList, hasItem(hasItem(allOf(hasEntry('name', 'testEnv'), hasEntry ('value','testVal')))))
assertThat(envList, hasItem(hasItem(allOf(hasEntry('name', 'HOME'), hasEntry ('value','/home/piper/sidecar')))))
}
@Test
@@ -510,11 +514,11 @@ class DockerExecuteOnKubernetesTest extends BasePiperTest {
}
assertThat(stashList, hasItem(allOf(
not(hasEntry('allowEmpty', true)),
hasEntry('includes','workspace/include.test'),
hasEntry('includes','workspace/include.test'),
hasEntry('excludes','workspace/exclude.test'))))
assertThat(stashList, hasItem(allOf(
not(hasEntry('allowEmpty', true)),
hasEntry('includes','container/include.test'),
hasEntry('includes','container/include.test'),
hasEntry('excludes','container/exclude.test'))))
}
+2
View File
@@ -48,10 +48,12 @@ import groovy.transform.Field
*/
'dockerName',
/**
* Docker only:
* Docker options to be set when starting the container (List or String).
*/
'dockerOptions',
/**
* Docker only:
* Volumes that should be mounted into the container.
*/
'dockerVolumeBind',
+6 -13
View File
@@ -108,14 +108,7 @@ import hudson.AbortException
* as `dockerWorkspace` for the sidecar container
*/
'sidecarWorkspace',
/**
* as `dockerVolumeBind` for the sidecar container
*/
'sidecarVolumeBind',
/**
* as `dockerOptions` for the sidecar container
*/
'sidecarOptions',
/** Defines the Kubernetes nodeSelector as per [https://github.com/jenkinsci/kubernetes-plugin](https://github.com/jenkinsci/kubernetes-plugin).*/
'nodeSelector',
/**
@@ -361,7 +354,7 @@ private List getContainerList(config) {
name : containerName.toLowerCase(),
image : imageName,
imagePullPolicy: pullImage ? "Always" : "IfNotPresent",
env : getContainerEnvs(config, imageName)
env : getContainerEnvs(config, imageName, config.dockerEnvVars, config.dockerWorkspace)
]
def configuredCommand = config.containerCommands?.get(imageName)
@@ -403,7 +396,7 @@ private List getContainerList(config) {
name : config.sidecarName.toLowerCase(),
image : config.sidecarImage,
imagePullPolicy: config.sidecarPullImage ? "Always" : "IfNotPresent",
env : getContainerEnvs(config, config.sidecarImage),
env : getContainerEnvs(config, config.sidecarImage, config.sidecarEnvVars, config.sidecarWorkspace),
command : []
]
@@ -419,10 +412,10 @@ private List getContainerList(config) {
* @param config Map with configurations
*/
private List getContainerEnvs(config, imageName) {
private List getContainerEnvs(config, imageName, defaultEnvVars, defaultConfig) {
def containerEnv = []
def dockerEnvVars = config.containerEnvVars?.get(imageName) ?: config.dockerEnvVars ?: [:]
def dockerWorkspace = config.containerWorkspaces?.get(imageName) != null ? config.containerWorkspaces?.get(imageName) : config.dockerWorkspace ?: ''
def dockerEnvVars = config.containerEnvVars?.get(imageName) ?: defaultEnvVars ?: [:]
def dockerWorkspace = config.containerWorkspaces?.get(imageName) != null ? config.containerWorkspaces?.get(imageName) : defaultConfig ?: ''
def envVar = { e ->
[name: e.key, value: e.value]