Skip to content

Commit 9358076

Browse files
committedNov 8, 2024
chore(ingress): Allow tls activation
1 parent 8ab1763 commit 9358076

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed
 

‎generator/ingress.go

+29
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func NewIngress(service types.ServiceConfig, Chart *HelmChart) *Ingress {
5555
Host: mapping.Hostname,
5656
Class: mapping.Class,
5757
Annotations: mapping.Annotations,
58+
TLS: mapping.TLS,
5859
}
5960

6061
// ingressClassName := `{{ .Values.` + service.Name + `.ingress.class }}`
@@ -131,6 +132,34 @@ func (ingress *Ingress) Yaml() ([]byte, error) {
131132
ret = UnWrapTPL(ret)
132133

133134
lines := strings.Split(string(ret), "\n")
135+
136+
// first pass, wrap the tls part with `{{- if .Values.serviceName.ingress.tlsEnabled -}}`
137+
// and `{{- end -}}`
138+
139+
from := -1
140+
to := -1
141+
spaces := -1
142+
for i, line := range lines {
143+
if strings.Contains(line, "tls:") {
144+
from = i
145+
spaces = utils.CountStartingSpaces(line)
146+
continue
147+
}
148+
if from > -1 {
149+
if utils.CountStartingSpaces(line) >= spaces {
150+
to = i
151+
continue
152+
}
153+
}
154+
}
155+
if from > -1 && to > -1 {
156+
lines[from] = strings.Repeat(" ", spaces) +
157+
`{{- if .Values.` + serviceName + `.ingress.tls.enabled }}` +
158+
"\n" +
159+
lines[from]
160+
lines[to] = strings.Repeat(" ", spaces) + `{{ end -}}`
161+
}
162+
134163
out := []string{
135164
`{{- if .Values.` + serviceName + `.ingress.enabled -}}`,
136165
}

‎generator/labelStructs/ingress.go

+6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ package labelStructs
22

33
import "gopkg.in/yaml.v3"
44

5+
type TLS struct {
6+
Enabled bool `yaml:"enabled"`
7+
}
8+
59
type Ingress struct {
610
Port *int32 `yaml:"port,omitempty"`
711
Annotations map[string]string `yaml:"annotations,omitempty"`
812
Hostname string `yaml:"hostname"`
913
Path string `yaml:"path"`
1014
Class string `yaml:"class"`
1115
Enabled bool `yaml:"enabled"`
16+
TLS TLS `yaml:"tls"`
1217
}
1318

1419
// IngressFrom creates a new Ingress from a compose service.
@@ -19,6 +24,7 @@ func IngressFrom(data string) (*Ingress, error) {
1924
Enabled: false,
2025
Class: "-",
2126
Port: nil,
27+
TLS: TLS{Enabled: true},
2228
}
2329
if err := yaml.Unmarshal([]byte(data), &mapping); err != nil {
2430
return nil, err

‎generator/values.go

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ type IngressValue struct {
2727
Path string `yaml:"path"`
2828
Class string `yaml:"class"`
2929
Enabled bool `yaml:"enabled"`
30+
TLS struct {
31+
Enabled bool `yaml:"enabled"`
32+
} `yaml:"tls"`
3033
}
3134

3235
// Value will be saved in values.yaml. It contains configuraiton for all deployment and services.

0 commit comments

Comments
 (0)