Skip to content

Commit

Permalink
Add ingress (#84)
Browse files Browse the repository at this point in the history
* GEO-6100: add ingress

* Remove versions crap

* Spec ingress enabled per service

* Use dollar as scope

* Fix tests
  • Loading branch information
danduk82 authored Jan 4, 2023
1 parent ea17a2b commit 9cac9b0
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 0 deletions.
42 changes: 42 additions & 0 deletions templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{{- if eq $.Values.ingress.enabled true -}}
{{- $fullName := include "common.fullname" ( dict "root" $ "service" $.Values ) -}}
{{- range $hostGroupName, $hostGroupDefinition := $.Values.ingress.hostGroups }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $fullName }}-{{ $hostGroupName }}
{{- include "common.metadata" ( dict "root" $ "service" $.Values ) | nindent 2 }}
spec:
# Add tls only if ingress.tls.enabled is set to true and the other fields are complete.
{{- if and ( hasKey $hostGroupDefinition "tls" ) ( eq $hostGroupDefinition.tls.enabled true ) }}
tls:
- hosts:
{{- range $hostGroupDefinition.hosts }}
- {{ . | quote }}
{{- end }}
{{- if $hostGroupDefinition.tls.secretName }}
secretName: {{ $hostGroupDefinition.tls.secretName }}
{{- else }}
secretName: {{ $fullName }}-{{ $hostGroupName }}
{{- end }}
{{- end }}
rules:
{{- range $hostGroupDefinition.hosts }}
- host: {{ . | quote }}
http:
paths:
{{- range $serviceName, $serviceDefinition := $.Values.services }}
{{- if and (eq $serviceDefinition.enabled true) (eq $serviceDefinition.ingress.enabled true) }}
- path: "{{ $serviceDefinition.ingress.path }}"
pathType: Prefix
backend:
service:
name: {{ include "common.fullname" ( dict "root" $ "service" $serviceDefinition "serviceName" $serviceName ) }}
port:
number: {{ $serviceDefinition.service.servicePort | default 80 }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
92 changes: 92 additions & 0 deletions tests/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,95 @@ spec:
emptyDir: {}
- name: my-volume-2
emptyDir: {}
---
# Source: custom-pod/templates/ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: custom-custom-pod-host1
labels:
helm.sh/chart: custom-pod
app.kubernetes.io/version: "1.0"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: custom-pod
app.kubernetes.io/instance: custom
app.kubernetes.io/component: main
spec:
# Add tls only if ingress.tls.enabled is set to true and the other fields are complete.
tls:
- hosts:
- "test1.example.com"
- "test2.example.com"
secretName: my-tls-secret
rules:
- host: "test1.example.com"
http:
paths:
- path: "/one"
pathType: Prefix
backend:
service:
name: custom-custom-pod-with-serv
port:
number: 8080
- path: "/two"
pathType: Prefix
backend:
service:
name: custom-with-name-override-example2
port:
number: 8080
- host: "test2.example.com"
http:
paths:
- path: "/one"
pathType: Prefix
backend:
service:
name: custom-custom-pod-with-serv
port:
number: 8080
- path: "/two"
pathType: Prefix
backend:
service:
name: custom-with-name-override-example2
port:
number: 8080
---
# Source: custom-pod/templates/ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: custom-custom-pod-host2
labels:
helm.sh/chart: custom-pod
app.kubernetes.io/version: "1.0"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: custom-pod
app.kubernetes.io/instance: custom
app.kubernetes.io/component: main
spec:
# Add tls only if ingress.tls.enabled is set to true and the other fields are complete.
tls:
- hosts:
- "*.example.com"
secretName: my-tls-secret
rules:
- host: "*.example.com"
http:
paths:
- path: "/one"
pathType: Prefix
backend:
service:
name: custom-custom-pod-with-serv
port:
number: 8080
- path: "/two"
pathType: Prefix
backend:
service:
name: custom-with-name-override-example2
port:
number: 8080
24 changes: 24 additions & 0 deletions tests/values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
servicedefinition: &servicedefinition
type: ClusterIP
servicePort: 8080
ports:
- name: http
port: 8080
Expand All @@ -8,8 +9,28 @@ servicedefinition: &servicedefinition

affinity: {}

ingress:
enabled: true
hostGroups:
host1:
tls:
enabled: true
secretName: 'my-tls-secret'
hosts:
- test1.example.com
- test2.example.com
host2:
tls:
enabled: true
secretName: 'my-tls-secret'
hosts:
- '*.example.com'

services:
example1:
ingress:
enabled: true
path: /one
enabled: true
replicaCount: 1
nodeSelector: {}
Expand Down Expand Up @@ -95,6 +116,9 @@ services:
<<: *servicedefinition

example2:
ingress:
enabled: true
path: /two
enabled: true
replicaCount: 2

Expand Down
5 changes: 5 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ serviceAccount:
# If not set and create is true, a name is generated using the fullname template
name: default

ingress:
enabled: false

services:
example:
enabled: false
ingress:
enabled: false

env: {}

Expand Down

0 comments on commit 9cac9b0

Please sign in to comment.