Skip to content

Commit

Permalink
Merge pull request #115 from dasmeta/DMVP-5341-base-additional-ingres…
Browse files Browse the repository at this point in the history
…ses-support

fix(DMVP-5341): support multiple ingress creation
  • Loading branch information
mrdntgrn authored Sep 19, 2024
2 parents 59758d9 + 938287d commit 538e432
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 20 deletions.
4 changes: 2 additions & 2 deletions charts/base/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.2.3
version: 0.2.4

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.2.3"
appVersion: "0.2.4"
4 changes: 4 additions & 0 deletions charts/base/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
1. Get the application URL by running these commands:
{{- if not (kindIs "slice" .Values.ingress) }}
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
Expand All @@ -20,3 +21,6 @@
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
{{- else }}
kubectl get ingress
{{- end }}
12 changes: 6 additions & 6 deletions charts/base/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ Return the target/server Kubernetes version
{{- end -}}

{{- define "annotations" -}}
{{- $ingressAnnotations := .Values.ingress.annotations -}}
{{- $ingressAnnotations := .annotations -}}

{{- if eq .Values.ingress.class "alb" }}
{{- if eq .class "alb" }}
{{- $defaultAnnotations := dict "kubernetes.io/ingress.class" "alb"
"alb.ingress.kubernetes.io/target-type" "ip"
"alb.ingress.kubernetes.io/scheme" "internet-facing"
Expand All @@ -87,20 +87,20 @@ Return the target/server Kubernetes version
"alb.ingress.kubernetes.io/success-codes" "200-399" -}}
{{- $mergedAnnotations := merge $ingressAnnotations $defaultAnnotations -}}
{{- $mergedAnnotations | toYaml }}
{{- else if eq .Values.ingress.class "application-gateway" }}
{{- else if eq .class "application-gateway" }}
{{- $defaultAnnotations := dict "kubernetes.io/ingress.class" "azure/application-gateway"
"external-dns.alpha.kubernetes.io/ttl" "60"
"appgw.ingress.kubernetes.io/backend-protocol" "http"
"appgw.ingress.kubernetes.io/ssl-redirect" "true" -}}
{{- $mergedAnnotations := merge $defaultAnnotations $ingressAnnotations -}}
{{- $mergedAnnotations | toYaml }}
{{- else if eq .Values.ingress.class "cce" }}
{{- else if eq .class "cce" }}
{{- $defaultAnnotations := dict "kubernetes.io/ingress.class" "cce"
"kubernetes.io/elb.port" "443" -}}
{{- $mergedAnnotations := merge $ingressAnnotations $defaultAnnotations -}}
{{- $mergedAnnotations | toYaml }}
{{- else if eq .Values.ingress.class "nginx" }}
{{- $defaultAnnotations := dict "kubernetes.io/ingress.class" "nginx" -}}
{{- else }}
{{- $defaultAnnotations := (ternary ("{}" | fromYaml) (dict "kubernetes.io/ingress.class" .class) .Values.setIngressClassByField) -}}
{{- $mergedAnnotations := merge $ingressAnnotations $defaultAnnotations -}}
{{- $mergedAnnotations | toYaml }}
{{- end }}
Expand Down
2 changes: 1 addition & 1 deletion charts/base/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ spec:
- configMapRef:
name: {{ .Values.externalConfigmap.name }}
{{- end }}
{{- if eq .Values.secretsDefaultEngine "ExternalSecrets" }}
{{- if and (eq .Values.secretsDefaultEngine "ExternalSecrets") .Values.secrets }}
- secretRef:
name: {{ include "base.fullname" . }}
optional: true
Expand Down
2 changes: 1 addition & 1 deletion charts/base/templates/external-secrets.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if eq .Values.secretsDefaultEngine "ExternalSecrets" -}}
{{- if and (eq .Values.secretsDefaultEngine "ExternalSecrets") .Values.secrets -}}
{{ $fullName := include "base.fullname" .}}
apiVersion: external-secrets.io/v1alpha1
kind: ExternalSecret
Expand Down
25 changes: 16 additions & 9 deletions charts/base/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{{- if .Values.ingress.enabled -}}
{{- if or (and (kindIs "slice" .Values.ingress) .Values.ingress ) ((.Values.ingress).enabled) -}}
{{- $fullName := include "base.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- $kubeVersion := (include "base.capabilities.kubeVersion" .) -}}
{{- $outerScope := . -}}
{{- range $key, $ingress := (ternary .Values.ingress (list .Values.ingress) (kindIs "slice" .Values.ingress)) }}
---
{{- if semverCompare ">=1.19-0" $kubeVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" $kubeVersion -}}
Expand All @@ -11,28 +14,31 @@ apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
name: {{ $fullName }}{{ coalesce $ingress.nameSuffix $key "" }}
labels:
{{- include "base.labels" . | nindent 4 }}
{{- include "base.labels" $outerScope | nindent 4 }}
annotations:
{{- include "annotations" . | nindent 4 }}
{{- include "annotations" (merge . $) | nindent 4 }}
spec:
{{- if .Values.ingress.tls }}
{{- if $.Values.setIngressClassByField }}
ingressClassName: {{ $ingress.class }}
{{- end }}
{{- if $ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
{{- range $ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
{{- if .Values.ingress.defaultBackend }}
{{- if $ingress.defaultBackend }}
defaultBackend:
{{- toYaml .Values.ingress.defaultBackend | nindent 4 }}
{{- toYaml $ingress.defaultBackend | nindent 4 }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
{{- range $ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
Expand Down Expand Up @@ -62,3 +68,4 @@ spec:
{{- end }}
{{- end }}
{{- end }}
{{- end }}
29 changes: 28 additions & 1 deletion charts/base/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ service:
# protocol: TCP
# name: http-second

# The ingress class setting by annotation is deprecated and we have setIngressClassByField option for backward compatibility for now, check doc here https://kubernetes.io/docs/concepts/services-networking/ingress/#deprecated-annotation
# have 'setIngressClassByField: true' to set ingress class by spec.ingressClassName,
# we seems cant have both "kubernetes.io/ingress.class" and spec.ingressClassName set at once, so there is check(for alb, application-gateway and cce the check is missing for now) to not set annotation if we set ingress class fy field
# TODO: have ingress class setting by field used always and remove deprecated "kubernetes.io/ingress.class" annotations
setIngressClassByField: false

# it allows also to pass list of ingresses in following form
# NOTE: in case of list it will auto attach uniq identify numbers to ingress names starting from second item, you can use nameSuffix field to set custom suffix instead of number
ingress:
enabled: false
class: alb
Expand All @@ -89,6 +97,25 @@ ingress:
servicePort: 80
path: /*
tls: []
# example how can be ingress list passed
# ingress:
# - class: nginx
# hosts:
# - host: host.name.com
# paths:
# - backend:
# serviceName: base
# servicePort: 80
# path: /*
# - class: nginx-second
# nameSuffix: -second
# hosts:
# - host: host-second.name.com
# paths:
# - path: /*
# backend:
# serviceName: base
# servicePort: 8080

secrets: []
secretsDefaultEngine: "ExternalSecrets"
Expand Down Expand Up @@ -203,4 +230,4 @@ serviceMonitor:
enabled: false
interval: 30s
targetPort: 80
path: /metrics
path: /metrics

0 comments on commit 538e432

Please sign in to comment.