Change label system

This commit is contained in:
2021-12-02 14:56:51 +01:00
parent 04d54bc2a3
commit 96de1269fb
4 changed files with 21 additions and 12 deletions

View File

@@ -76,24 +76,25 @@ services:
- database - database
labels: labels:
# explain to katenary that "DB_HOST" value is variable (using release name) # 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 # expose the port 80 as an ingress
katenary.io/ingress: 80 katenary.io/ingress: 80
database: database:
image: mariabd:10 image: mariadb:10
env_file: env_file:
# this will create a configMap # this will create a configMap
- my_env.env - my_env.env
environment: environment:
MARIADB_ROOT_PASSWORD: foobar MARIADB_ROOT_PASSWORD: foobar
expose: labels:
# required to make katenary able to create the init container # no need to declare this port in docker-compose
- 3306 # but katenary will need it
katenary.io/ports: 3306
``` ```
# Labels # 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/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/secret-envfiles`: 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/ports` is a coma separated list of ports if you want to avoid the "ports" section in your docker-compose for any reason

View File

@@ -47,7 +47,7 @@ echo "Done"
func CreateReplicaObject(name string, s compose.Service) chan interface{} { func CreateReplicaObject(name string, s compose.Service) chan interface{} {
// fetch label to specific exposed port, and add them in "ports" section // 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, ",") services := strings.Split(portlabel, ",")
for _, serviceport := range services { for _, serviceport := range services {
portexists := false portexists := false
@@ -76,7 +76,7 @@ func parseService(name string, s compose.Service, ret chan interface{}) {
// prepare secrets // prepare secrets
secretsFiles := make([]string, 0) 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, ",") secretsFiles = strings.Split(v, ",")
} }
@@ -300,7 +300,7 @@ func createService(name string, s compose.Service) []interface{} {
ks.Spec.Selector = buildSelector(name, s) ks.Spec.Selector = buildSelector(name, s)
ret = append(ret, ks) 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) port, err := strconv.Atoi(v)
if err != nil { if err != nil {
log.Fatalf("The given port \"%v\" as ingress port in %s service is not an integer\n", v, name) log.Fatalf("The given port \"%v\" as ingress port in %s service is not an integer\n", v, name)

View File

@@ -57,8 +57,9 @@ func NewContainer(name, image string, environment, labels map[string]string) *Co
EnvFrom: make([]map[string]map[string]string, 0), EnvFrom: make([]map[string]map[string]string, 0),
} }
// find bound environment variable to a service
toServices := make([]string, 0) toServices := make([]string, 0)
if bound, ok := labels[K+"/to-services"]; ok { if bound, ok := labels[LABEL_ENV_SERVICE]; ok {
toServices = strings.Split(bound, ",") toServices = strings.Split(bound, ",")
} }

View File

@@ -9,6 +9,13 @@ import (
) )
const K = "katenary.io" 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 = "" var Appname = ""