1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

moved container context method to config package and expose for reuse (#1770)

This commit is contained in:
lndrschlz 2020-07-10 10:32:26 +02:00 committed by GitHub
parent 111e4de8c3
commit db13b2f9ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 23 deletions

View File

@ -143,32 +143,11 @@ func applyContextConditions(metadata config.StepData, stepConfig *config.StepCon
//consider conditions for context configuration
//containers
applyContainerConditions(metadata.Spec.Containers, stepConfig)
config.ApplyContainerConditions(metadata.Spec.Containers, stepConfig)
//sidecars
applyContainerConditions(metadata.Spec.Sidecars, stepConfig)
config.ApplyContainerConditions(metadata.Spec.Sidecars, stepConfig)
//ToDo: remove all unnecessary sub maps?
// e.g. extract delete() from applyContainerConditions - loop over all stepConfig.Config[param.Value] and remove ...
}
func applyContainerConditions(containers []config.Container, stepConfig *config.StepConfig) {
for _, container := range containers {
if len(container.Conditions) > 0 {
for _, param := range container.Conditions[0].Params {
if container.Conditions[0].ConditionRef == "strings-equal" && stepConfig.Config[param.Name] == param.Value {
var containerConf map[string]interface{}
if stepConfig.Config[param.Value] != nil {
containerConf = stepConfig.Config[param.Value].(map[string]interface{})
for key, value := range containerConf {
if stepConfig.Config[key] == nil {
stepConfig.Config[key] = value
}
}
delete(stepConfig.Config, param.Value)
}
}
}
}
}
}

View File

@ -318,6 +318,28 @@ func (s *StepConfig) mixInStepDefaults(stepParams []StepParameters) {
}
}
// ApplyContainerConditions evaluates conditions in step yaml container definitions
func ApplyContainerConditions(containers []Container, stepConfig *StepConfig) {
for _, container := range containers {
if len(container.Conditions) > 0 {
for _, param := range container.Conditions[0].Params {
if container.Conditions[0].ConditionRef == "strings-equal" && stepConfig.Config[param.Name] == param.Value {
var containerConf map[string]interface{}
if stepConfig.Config[param.Value] != nil {
containerConf = stepConfig.Config[param.Value].(map[string]interface{})
for key, value := range containerConf {
if stepConfig.Config[key] == nil {
stepConfig.Config[key] = value
}
}
delete(stepConfig.Config, param.Value)
}
}
}
}
}
}
func filterMap(data map[string]interface{}, filter []string) map[string]interface{} {
result := map[string]interface{}{}