diff --git a/generator/ingress.go b/generator/ingress.go index f2f1ef0..7d012d4 100644 --- a/generator/ingress.go +++ b/generator/ingress.go @@ -55,6 +55,7 @@ func NewIngress(service types.ServiceConfig, Chart *HelmChart) *Ingress { Host: mapping.Hostname, Class: mapping.Class, Annotations: mapping.Annotations, + TLS: TLS{Enabled: mapping.TLS.Enabled}, } // ingressClassName := `{{ .Values.` + service.Name + `.ingress.class }}` @@ -131,6 +132,34 @@ func (ingress *Ingress) Yaml() ([]byte, error) { ret = UnWrapTPL(ret) lines := strings.Split(string(ret), "\n") + + // first pass, wrap the tls part with `{{- if .Values.serviceName.ingress.tlsEnabled -}}` + // and `{{- end -}}` + + from := -1 + to := -1 + spaces := -1 + for i, line := range lines { + if strings.Contains(line, "tls:") { + from = i + spaces = utils.CountStartingSpaces(line) + continue + } + if from > -1 { + if utils.CountStartingSpaces(line) >= spaces { + to = i + continue + } + } + } + if from > -1 && to > -1 { + lines[from] = strings.Repeat(" ", spaces) + + `{{- if .Values.` + serviceName + `.ingress.tls.enabled }}` + + "\n" + + lines[from] + lines[to] = strings.Repeat(" ", spaces) + `{{ end -}}` + } + out := []string{ `{{- if .Values.` + serviceName + `.ingress.enabled -}}`, } diff --git a/generator/labelStructs/ingress.go b/generator/labelStructs/ingress.go index 22c5b01..86faea4 100644 --- a/generator/labelStructs/ingress.go +++ b/generator/labelStructs/ingress.go @@ -2,6 +2,10 @@ package labelStructs import "gopkg.in/yaml.v3" +type TLS struct { + Enabled bool `yaml:"enabled"` +} + type Ingress struct { Port *int32 `yaml:"port,omitempty"` Annotations map[string]string `yaml:"annotations,omitempty"` @@ -9,6 +13,7 @@ type Ingress struct { Path string `yaml:"path"` Class string `yaml:"class"` Enabled bool `yaml:"enabled"` + TLS TLS `yaml:"tls"` } // IngressFrom creates a new Ingress from a compose service. @@ -19,6 +24,7 @@ func IngressFrom(data string) (*Ingress, error) { Enabled: false, Class: "-", Port: nil, + TLS: TLS{Enabled: true}, } if err := yaml.Unmarshal([]byte(data), &mapping); err != nil { return nil, err diff --git a/generator/values.go b/generator/values.go index cec4fef..2b6f83a 100644 --- a/generator/values.go +++ b/generator/values.go @@ -20,6 +20,10 @@ type PersistenceValue struct { Enabled bool `yaml:"enabled"` } +type TLS struct { + Enabled bool `yaml:"enabled"` +} + // IngressValue is a ingress configuration that will be saved in values.yaml. type IngressValue struct { Annotations map[string]string `yaml:"annotations"` @@ -27,6 +31,7 @@ type IngressValue struct { Path string `yaml:"path"` Class string `yaml:"class"` Enabled bool `yaml:"enabled"` + TLS TLS `yaml:"tls"` } // Value will be saved in values.yaml. It contains configuraiton for all deployment and services.