From 96de1269fbd7aa1165e0749ac7c2342110b769b2 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Thu, 2 Dec 2021 14:56:51 +0100 Subject: [PATCH] Change label system --- README.md | 17 +++++++++-------- generator/main.go | 6 +++--- helm/deployment.go | 3 ++- helm/types.go | 7 +++++++ 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 706d000..f565fd5 100644 --- a/README.md +++ b/README.md @@ -76,24 +76,25 @@ services: - database labels: # explain to katenary that "DB_HOST" value is variable (using release name) - katenary.io/to-servie: DB_HOST + katenary.io/env-is-service: DB_HOST # expose the port 80 as an ingress katenary.io/ingress: 80 database: - image: mariabd:10 + image: mariadb:10 env_file: # this will create a configMap - my_env.env environment: MARIADB_ROOT_PASSWORD: foobar - expose: - # required to make katenary able to create the init container - - 3306 + labels: + # no need to declare this port in docker-compose + # but katenary will need it + katenary.io/ports: 3306 ``` # Labels -- `katenary.io/to-service` binds the given (coma separated) variables names to {{ .Release.Name }}-value +- `katenary.io/env-to-service` binds the given (coma separated) variables names to {{ .Release.Name }}-value - `katenary.io/ingress`: create an ingress and bind it to the given port -- `katenary.io/as-secret`: force the creation of a secret for the given coma separated list of "env_file" -- `katenary.io/service-ports` is a coma separated list of ports if you want to avoid the "ports" section in your docker-compose for any reason +- `katenary.io/secret-envfiles`: force the creation of a secret for the given coma separated list of "env_file" +- `katenary.io/ports` is a coma separated list of ports if you want to avoid the "ports" section in your docker-compose for any reason diff --git a/generator/main.go b/generator/main.go index 7f1bcec..66a44a2 100644 --- a/generator/main.go +++ b/generator/main.go @@ -47,7 +47,7 @@ echo "Done" func CreateReplicaObject(name string, s compose.Service) chan interface{} { // fetch label to specific exposed port, and add them in "ports" section - if portlabel, ok := s.Labels[helm.K+"/service-ports"]; ok { + if portlabel, ok := s.Labels[helm.LABEL_PORT]; ok { services := strings.Split(portlabel, ",") for _, serviceport := range services { portexists := false @@ -76,7 +76,7 @@ func parseService(name string, s compose.Service, ret chan interface{}) { // prepare secrets secretsFiles := make([]string, 0) - if v, ok := s.Labels[helm.K+"/as-secret"]; ok { + if v, ok := s.Labels[helm.LABEL_ENV_SECRET]; ok { secretsFiles = strings.Split(v, ",") } @@ -300,7 +300,7 @@ func createService(name string, s compose.Service) []interface{} { ks.Spec.Selector = buildSelector(name, s) ret = append(ret, ks) - if v, ok := s.Labels[helm.K+"/ingress"]; ok { + if v, ok := s.Labels[helm.LABEL_INGRESS]; ok { port, err := strconv.Atoi(v) if err != nil { log.Fatalf("The given port \"%v\" as ingress port in %s service is not an integer\n", v, name) diff --git a/helm/deployment.go b/helm/deployment.go index b9ba057..873b724 100644 --- a/helm/deployment.go +++ b/helm/deployment.go @@ -57,8 +57,9 @@ func NewContainer(name, image string, environment, labels map[string]string) *Co EnvFrom: make([]map[string]map[string]string, 0), } + // find bound environment variable to a service toServices := make([]string, 0) - if bound, ok := labels[K+"/to-services"]; ok { + if bound, ok := labels[LABEL_ENV_SERVICE]; ok { toServices = strings.Split(bound, ",") } diff --git a/helm/types.go b/helm/types.go index 95d3233..e00b3d6 100644 --- a/helm/types.go +++ b/helm/types.go @@ -9,6 +9,13 @@ import ( ) const K = "katenary.io" +const ( + LABEL_ENV_SECRET = K + "/secret-envfiles" + LABEL_PORT = K + "/ports" + LABEL_INGRESS = K + "/ingress" + LABEL_ENV_SERVICE = K + "/env-to-service" + LABEL_VOL_CM = K + "/configmap-volumes" +) var Appname = ""