diff --git a/charts/base/Chart.yaml b/charts/base/Chart.yaml index 99bfd67..1965756 100644 --- a/charts/base/Chart.yaml +++ b/charts/base/Chart.yaml @@ -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" diff --git a/charts/base/templates/NOTES.txt b/charts/base/templates/NOTES.txt index 4dd4ee9..708d9c4 100644 --- a/charts/base/templates/NOTES.txt +++ b/charts/base/templates/NOTES.txt @@ -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 }} @@ -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 }} diff --git a/charts/base/templates/_helpers.tpl b/charts/base/templates/_helpers.tpl index 86766a2..f61a7bc 100644 --- a/charts/base/templates/_helpers.tpl +++ b/charts/base/templates/_helpers.tpl @@ -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" @@ -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 }} diff --git a/charts/base/templates/deployment.yaml b/charts/base/templates/deployment.yaml index 010f0d2..9967f29 100644 --- a/charts/base/templates/deployment.yaml +++ b/charts/base/templates/deployment.yaml @@ -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 diff --git a/charts/base/templates/external-secrets.yaml b/charts/base/templates/external-secrets.yaml index 785f6ed..baeafc4 100644 --- a/charts/base/templates/external-secrets.yaml +++ b/charts/base/templates/external-secrets.yaml @@ -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 diff --git a/charts/base/templates/ingress.yaml b/charts/base/templates/ingress.yaml index 3b99bf6..94e9c13 100644 --- a/charts/base/templates/ingress.yaml +++ b/charts/base/templates/ingress.yaml @@ -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 -}} @@ -11,15 +14,18 @@ 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 }} @@ -27,12 +33,12 @@ spec: 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: @@ -62,3 +68,4 @@ spec: {{- end }} {{- end }} {{- end }} +{{- end }} diff --git a/charts/base/values.yaml b/charts/base/values.yaml index 6f29927..0706b17 100644 --- a/charts/base/values.yaml +++ b/charts/base/values.yaml @@ -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 @@ -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" @@ -203,4 +230,4 @@ serviceMonitor: enabled: false interval: 30s targetPort: 80 - path: /metrics \ No newline at end of file + path: /metrics