Skip to content
Snippets Groups Projects
Commit f4ed8db3 authored by Mitchell Nielsen's avatar Mitchell Nielsen Committed by Jason Plum
Browse files

Use 'global.ingress.class' in IngressClass name

- Creates a new template that returns only the IngressClass value
- Uses that new template in the existing template that writes
  `ingressClassName: "value"`
- Uses the new template in the IngressClass template to ensure that
  'global.ingress.class' is considered when setting its name
- Updates the fork documentation for the change

Changelog: fixed
parent 47846c02
No related branches found
No related tags found
1 merge request!2351Clean up ingress-related templates
{{ if (pluck "configureCertmanager" .Values.global.ingress (dict "configureCertmanager" false) | first) }}
{{- $ingressCfg := dict "global" $.Values.global.ingress "local" .ingress "context" $ -}}
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
......@@ -21,5 +22,5 @@ spec:
- selector: {}
http01:
ingress:
class: {{ template "gitlab.ingress.className" . }}
class: {{ template "ingress.class.name" $ingressCfg }}
{{ end }}
......@@ -52,10 +52,3 @@ if there is a shared tls secret for all ingresses.
{{- end -}}
{{- pluck "secretName" .Values.ingress.tls .Values.global.ingress.tls $defaultName | first -}}
{{- end -}}
{{/*
Returns the nginx ingress class
*/}}
{{- define "minio.ingress.className" -}}
{{- pluck "class" .Values.global.ingress (dict "class" (printf "%s-nginx" .Release.Name)) | first -}}
{{- end -}}
......@@ -145,11 +145,3 @@ IngressClass parameters.
{{- define "ingress-nginx.tcp-configmap" -}}
{{ default (printf "%s-%s" (include "ingress-nginx.fullname" .) "tcp") .Values.tcpExternalConfig }}
{{- end -}}
{{- define "ingress-nginx.controller.ingress-class" -}}
{{- if not .Values.controller.ingressClass -}}
{{ .Release.Name }}-nginx
{{- else -}}
nginx
{{- end -}}
{{- end -}}
......@@ -59,13 +59,6 @@ hostname part of the url.
{{- end -}}
{{- end -}}
{{/*
Returns the nginx ingress class
*/}}
{{- define "registry.ingress.className" -}}
{{- pluck "class" .Values.global.ingress (dict "class" (printf "%s-nginx" .Release.Name)) | first -}}
{{- end -}}
{{/*
Populate registry notifications
*/}}
......
......@@ -18,7 +18,6 @@ The following adjustments were made to the NGINX fork:
- `controller-deployment.yaml`: `.spec.template.spec.containers[0].args` uses `ingress-nginx.tcp-configmap` template for ConfigMap name
- GitLab chart overrides `ingress-nginx.tcp-configmap` so that `gitlab/gitlab-org/charts/gitlab-shell` can configure its TCP service
- Ability to use a templated Ingress name based on the release name
- `controller-deployment.yaml`: `.spec.template.spec.containers[0].args` uses `ingress-nginx.controller.ingress-class`
- Replace `controller.service.loadBalancerIP` with `global.hosts.externalIP`
- Added support to add common labels through `common.labels` configuration option
- `controller-deployment.yaml`:
......
......@@ -12,6 +12,10 @@ describe 'GitLab Ingress configuration(s)' do
template.dig("Ingress/#{ingress_name}", 'apiVersion')
end
def get_ingress_class_name(template, ingress_class_name)
template.dig("IngressClass/#{ingress_class_name}", 'metadata', 'name')
end
def get_ingress_class_annotation(template, ingress_name)
template.dig("Ingress/#{ingress_name}", 'metadata', 'annotations', 'kubernetes.io/ingress.class')
end
......@@ -299,4 +303,36 @@ describe 'GitLab Ingress configuration(s)' do
end
end
end
describe 'ingress class name' do
let(:ingress_class_specified) do
default_values.deep_merge(YAML.safe_load(%(
global:
ingress:
class: specified
)))
end
context 'default' do
it 'populates the default name' do
template = HelmTemplate.new(default_values)
expect(template.exit_code).to eq(0)
expected_name = 'test-nginx'
name = get_ingress_class_name(template, expected_name)
expect(name).to eq(expected_name)
end
end
context 'specified' do
it 'populates the specified name' do
template = HelmTemplate.new(ingress_class_specified)
expect(template.exit_code).to eq(0)
expected_name = 'specified'
name = get_ingress_class_name(template, expected_name)
expect(name).to eq(expected_name)
end
end
end
end
......@@ -352,13 +352,6 @@ kubernetes.io/ingress.provider: "{{ template "gitlab.ingress.provider" $ingressC
{{- end -}}
{{- end -}}
{{/*
Returns the nginx ingress class
*/}}
{{- define "gitlab.ingress.className" -}}
{{- pluck "class" .Values.global.ingress (dict "class" (printf "%s-nginx" .Release.Name)) | first -}}
{{- end -}}
{{/*
Returns the ingress provider
......@@ -377,13 +370,6 @@ Overrides the ingress-nginx template to make sure gitlab-shell name matches
{{ .Release.Name}}-nginx-ingress-tcp
{{- end -}}
{{/*
Overrides the ingress-nginx template to make sure our ingresses match
*/}}
{{- define "ingress-nginx.controller.ingress-class" -}}
{{ template "gitlab.ingress.className" . }}
{{- end -}}
{{/* ######### annotations */}}
{{/*
......
......@@ -7,12 +7,32 @@ It expects a dictionary with two entries:
*/}}
{{- define "ingress.class.annotation" -}}
{{- $apiVersion := include "gitlab.ingress.apiVersion" . -}}
{{- $className := .global.class | default (printf "%s-nginx" .context.Release.Name) -}}
{{- $className := include "ingress.class.name" . -}}
{{- if not (eq $apiVersion "networking.k8s.io/v1") -}}
kubernetes.io/ingress.class: {{ $className }}
{{- end -}}
{{- end -}}
{{/*
Calculates the IngressClass name.
It expects either:
- a dictionary with two entries:
- `global` which contains global ingress settings, e.g. .Values.global.ingress
- `context` which is the parent context (either `.` or `$`)
- the parent context ($ from caller)
- This detected by access to both `.Capabilities` and `.Release`
*/}}
{{- define "ingress.class.name" -}}
{{- $here := dict }}
{{- if and (hasKey $ "Release") (hasKey $ "Capabilities") -}}
{{- $here = dict "global" $.Values.global.ingress "context" $ -}}
{{- else -}}
{{- $here = . -}}
{{- end -}}
{{- $here.global.class | default (printf "%s-nginx" $here.context.Release.Name) -}}
{{- end -}}
{{/*
Sets `ingressClassName` based on the API version of Ingress.
......@@ -22,8 +42,7 @@ It expects a dictionary with two entries:
*/}}
{{- define "ingress.class.field" -}}
{{- $apiVersion := include "gitlab.ingress.apiVersion" . -}}
{{- $className := .global.class | default (printf "%s-nginx" .context.Release.Name) -}}
{{- if eq $apiVersion "networking.k8s.io/v1" -}}
ingressClassName: {{ $className }}
ingressClassName: {{ include "ingress.class.name" . }}
{{- end -}}
{{- end -}}
......@@ -736,7 +736,7 @@ nginx-ingress:
externalTrafficPolicy: "Local"
ingressClassByName: false
ingressClassResource:
name: '{{ include "gitlab.ingress.className" . }}'
name: '{{ include "ingress.class.name" $ }}'
resources:
requests:
cpu: 100m
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment