mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-28 05:47:08 +02:00
added volume bindings to the step meta data
This commit is contained in:
parent
5b58ce830f
commit
90449d6226
@ -80,15 +80,22 @@ type StepSecrets struct {
|
||||
// Container defines an execution container
|
||||
type Container struct {
|
||||
//ToDo: check dockerOptions, dockerVolumeBind, containerPortMappings, sidecarOptions, sidecarVolumeBind
|
||||
Command []string `json:"command"`
|
||||
EnvVars []EnvVar `json:"env"`
|
||||
Image string `json:"image"`
|
||||
ImagePullPolicy string `json:"imagePullPolicy"`
|
||||
Name string `json:"name"`
|
||||
ReadyCommand string `json:"readyCommand"`
|
||||
Shell string `json:"shell"`
|
||||
WorkingDir string `json:"workingDir"`
|
||||
Conditions []Condition `json:"conditions,omitempty"`
|
||||
Command []string `json:"command"`
|
||||
EnvVars []EnvVar `json:"env"`
|
||||
Image string `json:"image"`
|
||||
ImagePullPolicy string `json:"imagePullPolicy"`
|
||||
Name string `json:"name"`
|
||||
ReadyCommand string `json:"readyCommand"`
|
||||
Shell string `json:"shell"`
|
||||
WorkingDir string `json:"workingDir"`
|
||||
Conditions []Condition `json:"conditions,omitempty"`
|
||||
VolumeBind []VolumeBind `json:"volumeBind,omitempty"`
|
||||
}
|
||||
|
||||
// VolumeBind defines an environment variable
|
||||
type VolumeBind struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
// EnvVar defines an environment variable
|
||||
@ -229,6 +236,7 @@ func (m *StepData) GetContextDefaults(stepName string) (io.ReadCloser, error) {
|
||||
p["dockerName"] = container.Name
|
||||
p["dockerPullImage"] = container.ImagePullPolicy != "Never"
|
||||
p["dockerWorkspace"] = container.WorkingDir
|
||||
p["dockerVolumeBind"] = volumeBindAsStringSlice(container.VolumeBind)
|
||||
|
||||
// Ready command not relevant for main runtime container so far
|
||||
//p[] = container.ReadyCommand
|
||||
@ -246,14 +254,13 @@ func (m *StepData) GetContextDefaults(stepName string) (io.ReadCloser, error) {
|
||||
root["sidecarPullImage"] = m.Spec.Sidecars[0].ImagePullPolicy != "Never"
|
||||
root["sidecarReadyCommand"] = m.Spec.Sidecars[0].ReadyCommand
|
||||
root["sidecarWorkspace"] = m.Spec.Sidecars[0].WorkingDir
|
||||
root["sidecarVolumeBind"] = volumeBindAsStringSlice(m.Spec.Sidecars[0].VolumeBind)
|
||||
}
|
||||
|
||||
// not filled for now since this is not relevant in Kubernetes case
|
||||
//p["dockerOptions"] = container.
|
||||
//p["dockerVolumeBind"] = container.
|
||||
//root["containerPortMappings"] = m.Spec.Sidecars[0].
|
||||
//root["sidecarOptions"] = m.Spec.Sidecars[0].
|
||||
//root["sidecarVolumeBind"] = m.Spec.Sidecars[0].
|
||||
|
||||
if len(m.Spec.Inputs.Resources) > 0 {
|
||||
keys := []string{}
|
||||
@ -310,3 +317,11 @@ func envVarsAsStringSlice(envVars []EnvVar) []string {
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
func volumeBindAsStringSlice(volumeBind []VolumeBind) []string {
|
||||
e := []string{}
|
||||
for _, v := range volumeBind {
|
||||
e = append(e, fmt.Sprintf("%v:%v", v.Name, v.Value))
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
@ -338,6 +338,10 @@ func TestGetContextDefaults(t *testing.T) {
|
||||
Image: "testImage:tag",
|
||||
Shell: "/bin/bash",
|
||||
WorkingDir: "/test/dir",
|
||||
VolumeBind: []VolumeBind{
|
||||
{Name: "vbn1", Value: "vbv1"},
|
||||
{Name: "vbn2", Value: "vbv2"},
|
||||
},
|
||||
},
|
||||
},
|
||||
Sidecars: []Container{
|
||||
@ -352,6 +356,10 @@ func TestGetContextDefaults(t *testing.T) {
|
||||
ImagePullPolicy: "Never",
|
||||
ReadyCommand: "/sidecar/command",
|
||||
WorkingDir: "/sidecar/dir",
|
||||
VolumeBind: []VolumeBind{
|
||||
{Name: "vbn3", Value: "vbv3"},
|
||||
{Name: "vbn4", Value: "vbv4"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -379,6 +387,7 @@ func TestGetContextDefaults(t *testing.T) {
|
||||
assert.Equal(t, "testcontainer", d.Defaults[0].Steps["testStep"]["dockerName"], "dockerName default not available")
|
||||
assert.Equal(t, true, d.Defaults[0].Steps["testStep"]["dockerPullImage"], "dockerPullImage default not available")
|
||||
assert.Equal(t, "/test/dir", d.Defaults[0].Steps["testStep"]["dockerWorkspace"], "dockerWorkspace default not available")
|
||||
assert.Equal(t, []interface{}{"vbn1:vbv1", "vbn2:vbv2"}, d.Defaults[0].Steps["testStep"]["dockerVolumeBind"], "dockerVolumeBind default not available")
|
||||
|
||||
assert.Equal(t, "/sidecar/command", d.Defaults[0].Steps["testStep"]["sidecarCommand"], "sidecarCommand default not available")
|
||||
assert.Equal(t, []interface{}{"env3=val3", "env4=val4"}, d.Defaults[0].Steps["testStep"]["sidecarEnvVars"], "sidecarEnvVars default not available")
|
||||
@ -387,6 +396,7 @@ func TestGetContextDefaults(t *testing.T) {
|
||||
assert.Equal(t, false, d.Defaults[0].Steps["testStep"]["sidecarPullImage"], "sidecarPullImage default not available")
|
||||
assert.Equal(t, "/sidecar/command", d.Defaults[0].Steps["testStep"]["sidecarReadyCommand"], "sidecarReadyCommand default not available")
|
||||
assert.Equal(t, "/sidecar/dir", d.Defaults[0].Steps["testStep"]["sidecarWorkspace"], "sidecarWorkspace default not available")
|
||||
assert.Equal(t, []interface{}{"vbn3:vbv3", "vbn4:vbv4"}, d.Defaults[0].Steps["testStep"]["sidecarVolumeBind"], "sidecarVolumeBind default not available")
|
||||
})
|
||||
|
||||
t.Run("Negative case", func(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user