Skip to content

Commit

Permalink
Add values templating in ingresses (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
evgkrsk authored Jul 16, 2022
1 parent e5d24b6 commit 87fae46
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 3 deletions.
3 changes: 3 additions & 0 deletions charts/universal-chart/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## 3.4.2 - Jul 16, 2022
* fix: add values templating in ingresses

## 3.4.1 - Jul 3, 2022
* fix: bool variables quoting in configmaps
* fix: set up valid default schedule for cronjobs
Expand Down
2 changes: 1 addition & 1 deletion charts/universal-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
description: Nixys universal Helm chart for deploy your apps to Kubernetes
name: universal-chart
version: 3.4.1
version: 3.4.2
maintainers:
- name: Roman Andreev
email: [email protected]
Expand Down
7 changes: 7 additions & 0 deletions charts/universal-chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,10 @@ or
```bash
--set-file "secrets.json-file.data.file\.json=path/to/file.json"
```

### Values Templating features

You can use go-templates as part of your values.

> **Note**
> Use single quotes to escape strings containing templates to avoid manifest generation errors.
97 changes: 97 additions & 0 deletions charts/universal-chart/results/ingress-rendering.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
# Source: universal-chart/templates/deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-someapi
namespace: default
labels:
app.kubernetes.io/name: test
app.kubernetes.io/instance: test
app.kubernetes.io/managed-by: Helm
annotations:
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: test
app.kubernetes.io/instance: test
template:
metadata:
labels:
app.kubernetes.io/name: test
app.kubernetes.io/instance: test
annotations:
spec:
affinity:
nodeAffinity:
{}
podAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/name: test
app.kubernetes.io/instance: test
namespaces:
- "default"
topologyKey: kubernetes.io/hostname
weight: 1
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/name: test
app.kubernetes.io/instance: test
namespaces:
- "default"
topologyKey: kubernetes.io/hostname
weight: 1

containers:
- name: some-api
image: nginx:latest
imagePullPolicy: IfNotPresent
env:
- name: PUBLIC_URL
value: https://api.dev2.somedomain.ru
ports:
- containerPort: 1337
name: http
volumeMounts:

[]
volumes:
[]
---
# Source: universal-chart/templates/ingress.yml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-someApiIngress
namespace: "default"
labels:
app.kubernetes.io/name: test
app.kubernetes.io/instance: test
app.kubernetes.io/managed-by: Helm
annotations:
kubernetes.io/tls-acme: "true"
cert-manager.io/cluster-issuer: letsencrypt
nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
rules:
- host: api.dev2.somedomain.ru
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: test-some-api-svc
port:
name: http
tls:
- hosts:
- api.dev2.somedomain.ru
secretName: test-someApiIngress-tls
26 changes: 26 additions & 0 deletions charts/universal-chart/samples/ingress-rendering.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
defaultURL: "api.dev2.somedomain.ru"

deployments:
someApi:
replicas: 1
containers:
- name: some-api
ports:
- name: http
containerPort: 1337
env:
- name: PUBLIC_URL
value: 'https://{{ .Values.defaultURL }}'

ingresses:
someApiIngress:
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "true"
certManager:
issuerType: cluster-issuer
issuerName: letsencrypt
hosts:
- hostname: '{{ .Values.defaultURL }}'
paths:
- serviceName: some-api-svc
servicePort: http
12 changes: 10 additions & 2 deletions charts/universal-chart/templates/ingress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ spec:
{{- end }}
rules:
{{- range $ing.hosts }}
- host: {{ default $host .hostname }}
{{- if .hostname }}
- host: {{ include "helpers.tplvalues.render" (dict "value" .hostname "context" $)}}
{{- else }}
- host: {{ $host }}
{{- end }}
http:
paths:
{{- range .paths }}
Expand All @@ -40,7 +44,11 @@ spec:
{{- if $ing.certManager }}
- hosts:
{{- range $ing.hosts }}
- {{ default $host .hostname }}
{{- if .hostname }}
- {{ include "helpers.tplvalues.render" (dict "value" .hostname "context" $)}}
{{- else }}
- {{ $host }}
{{- end }}
{{- end }}
secretName: {{ .tlsName | default (include "helpers.app.fullname" (dict "name" ($ing.name | default $host) "context" $)) }}-tls
{{- end }}
Expand Down

0 comments on commit 87fae46

Please sign in to comment.