From 1e8f417418519b6b57ee2bf53c131befda5e8e34 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Thu, 5 May 2022 19:02:13 +0200 Subject: [PATCH] Set environment variables to values.yaml --- generator/main.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/generator/main.go b/generator/main.go index 28c4be5..0499cd3 100644 --- a/generator/main.go +++ b/generator/main.go @@ -53,7 +53,6 @@ echo "Done" // Create a Deployment for a given compose.Service. It returns a list of objects: a Deployment and a possible Service (kubernetes represnetation as maps). func CreateReplicaObject(name string, s types.ServiceConfig, linked map[string]types.ServiceConfig) chan interface{} { ret := make(chan interface{}, len(s.Ports)+len(s.Expose)+2) - applyEnvMapLabel(&s) go parseService(name, s, linked, ret) return ret } @@ -62,8 +61,11 @@ func CreateReplicaObject(name string, s types.ServiceConfig, linked map[string]t func parseService(name string, s types.ServiceConfig, linked map[string]types.ServiceConfig, ret chan interface{}) { logger.Magenta(ICON_PACKAGE+" Generating deployment for ", name) - deployment := helm.NewDeployment(name) + // adapt env + applyEnvMapLabel(&s) + setEnvToValues(name, &s) + deployment := helm.NewDeployment(name) container := helm.NewContainer(name, s.Image, s.Environment, s.Labels) prepareContainer(container, s, name) prepareEnvFromFiles(name, s, container, ret) @@ -87,6 +89,8 @@ func parseService(name string, s types.ServiceConfig, linked map[string]types.Se // Now, the linked services for lname, link := range linked { + applyEnvMapLabel(&link) + setEnvToValues(lname, &link) container := helm.NewContainer(lname, link.Image, link.Environment, link.Labels) prepareContainer(container, link, lname) prepareEnvFromFiles(lname, link, container, ret) @@ -683,5 +687,19 @@ func applyEnvMapLabel(s *types.ServiceConfig) { for k, v := range envmap { s.Environment[k] = &v } - +} + +// setEnvToValues will set the environment variables to the values.yaml map. +func setEnvToValues(name string, s *types.ServiceConfig) { + // crete the "environment" key + env := make(map[string]interface{}) + for k, v := range s.Environment { + env[k] = v + } + + AddValues(name, map[string]interface{}{"environment": env}) + for k := range s.Environment { + v := "{{ .Values." + name + ".environment." + k + " }}" + s.Environment[k] = &v + } }