From db13b2f9ce6bf2469f0e1553b91f3999239a3f56 Mon Sep 17 00:00:00 2001 From: lndrschlz Date: Fri, 10 Jul 2020 10:32:26 +0200 Subject: [PATCH] moved container context method to config package and expose for reuse (#1770) --- cmd/getConfig.go | 25 ++----------------------- pkg/config/config.go | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/cmd/getConfig.go b/cmd/getConfig.go index 277daf99e..12402f8b1 100644 --- a/cmd/getConfig.go +++ b/cmd/getConfig.go @@ -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) - } - } - } - } - } -} diff --git a/pkg/config/config.go b/pkg/config/config.go index c76c64569..d767e4929 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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{}{}