Merge pull request #79 from metal3d/develop

Activable tls
This commit is contained in:
2024-11-09 13:57:35 +01:00
committed by GitHub
3 changed files with 40 additions and 0 deletions

View File

@@ -55,6 +55,7 @@ func NewIngress(service types.ServiceConfig, Chart *HelmChart) *Ingress {
Host: mapping.Hostname, Host: mapping.Hostname,
Class: mapping.Class, Class: mapping.Class,
Annotations: mapping.Annotations, Annotations: mapping.Annotations,
TLS: TLS{Enabled: mapping.TLS.Enabled},
} }
// ingressClassName := `{{ .Values.` + service.Name + `.ingress.class }}` // ingressClassName := `{{ .Values.` + service.Name + `.ingress.class }}`
@@ -131,6 +132,34 @@ func (ingress *Ingress) Yaml() ([]byte, error) {
ret = UnWrapTPL(ret) ret = UnWrapTPL(ret)
lines := strings.Split(string(ret), "\n") 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{ out := []string{
`{{- if .Values.` + serviceName + `.ingress.enabled -}}`, `{{- if .Values.` + serviceName + `.ingress.enabled -}}`,
} }

View File

@@ -2,6 +2,10 @@ package labelStructs
import "gopkg.in/yaml.v3" import "gopkg.in/yaml.v3"
type TLS struct {
Enabled bool `yaml:"enabled"`
}
type Ingress struct { type Ingress struct {
Port *int32 `yaml:"port,omitempty"` Port *int32 `yaml:"port,omitempty"`
Annotations map[string]string `yaml:"annotations,omitempty"` Annotations map[string]string `yaml:"annotations,omitempty"`
@@ -9,6 +13,7 @@ type Ingress struct {
Path string `yaml:"path"` Path string `yaml:"path"`
Class string `yaml:"class"` Class string `yaml:"class"`
Enabled bool `yaml:"enabled"` Enabled bool `yaml:"enabled"`
TLS TLS `yaml:"tls"`
} }
// IngressFrom creates a new Ingress from a compose service. // IngressFrom creates a new Ingress from a compose service.
@@ -19,6 +24,7 @@ func IngressFrom(data string) (*Ingress, error) {
Enabled: false, Enabled: false,
Class: "-", Class: "-",
Port: nil, Port: nil,
TLS: TLS{Enabled: true},
} }
if err := yaml.Unmarshal([]byte(data), &mapping); err != nil { if err := yaml.Unmarshal([]byte(data), &mapping); err != nil {
return nil, err return nil, err

View File

@@ -20,6 +20,10 @@ type PersistenceValue struct {
Enabled bool `yaml:"enabled"` Enabled bool `yaml:"enabled"`
} }
type TLS struct {
Enabled bool `yaml:"enabled"`
}
// IngressValue is a ingress configuration that will be saved in values.yaml. // IngressValue is a ingress configuration that will be saved in values.yaml.
type IngressValue struct { type IngressValue struct {
Annotations map[string]string `yaml:"annotations"` Annotations map[string]string `yaml:"annotations"`
@@ -27,6 +31,7 @@ type IngressValue struct {
Path string `yaml:"path"` Path string `yaml:"path"`
Class string `yaml:"class"` Class string `yaml:"class"`
Enabled bool `yaml:"enabled"` Enabled bool `yaml:"enabled"`
TLS TLS `yaml:"tls"`
} }
// Value will be saved in values.yaml. It contains configuraiton for all deployment and services. // Value will be saved in values.yaml. It contains configuraiton for all deployment and services.