From db4442e4dc352124cac69953c2e2f212f5152813 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Sun, 12 Apr 2020 15:15:06 +0200 Subject: [PATCH] Add readme's and some changes to make the redirect chart simple --- README.md | 8 +++ charts/redirect/Chart.yaml | 2 +- charts/redirect/README.md | 49 +++++++++++++++++++ charts/redirect/templates/deployment.yaml | 6 +-- .../templates/grafana-influxdb-dashboard.yaml | 2 + charts/redirect/templates/ingress.yaml | 5 +- .../templates/pod-disruption-budget.yaml | 4 +- charts/redirect/templates/service.yaml | 8 +-- .../tests/test-metrics-connection.yaml | 2 +- .../tests/test-redirect-connection.yaml | 2 +- charts/redirect/values.yaml | 5 +- 11 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 README.md create mode 100644 charts/redirect/README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..000e726 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# WyriHaximus.net Helm charts + +Opinionated helm chats for my personal projects, and OSS Projects that either don't have public helm charts, and don't meet my requirements for them. + +## Charts in this repository + +* [`redirect`](https://hub.helm.sh/charts/wyrihaximusnet/redirect) + diff --git a/charts/redirect/Chart.yaml b/charts/redirect/Chart.yaml index 5d9abaf..051fe3f 100644 --- a/charts/redirect/Chart.yaml +++ b/charts/redirect/Chart.yaml @@ -15,7 +15,7 @@ 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. -version: 0.0.4 +version: 0.1.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. diff --git a/charts/redirect/README.md b/charts/redirect/README.md new file mode 100644 index 0000000..b64d330 --- /dev/null +++ b/charts/redirect/README.md @@ -0,0 +1,49 @@ +# Redirect + +Opinionated helm chart for [`wyrihaximusnet/redirect`](https://github.com/wyrihaximusnet/docker-redirect). + +## Provided tags + +* `random` - Each time when the images are build a random image is selected and build. +* `reactphp` - Using [ReactPHP](https://reactphp.org/) +* `nodejs` - Using [NodeJS](https://nodejs.org/en/) + +## Configuration + +These images comes with 3 mandatory configuration options: +* `redirect.defaultFallbackTarget` - Requests not matching other rules will be redirected here +* `redirect.buildin` - Can be either `nonWwwToWww` or `wwwToNonWww`, anything else will make the image error and stop + +There is also one optional configuration option for custom hostname based redirection: +* `redirect.hosts` - from -> to based key value mapping + +While the Docker image doesn't care, for the helm chart you also have to supply all the `redirect.ingressHosts` you +intend to be handled by this chart. + +Full configuration example: + +```yaml +redirect: +# The default fallback is use in case the application can't find a domain to redirect to within the other configuration options + defaultFallbackTarget: https://www.wyrihaximus.net/ + buildin: wwwToNonWww + hosts: + www.ceesjankiewiet.nl: wyrihaximus.net + ingressHosts: + - www.wyrihaximus.net +``` + +Keep in mind that the configuration options are executed in the following order: +1. `redirect.hosts` +2. `redirect.buildin` +3. `redirect.defaultFallbackTarget` + +## Opinionated decisions + +* Ports are hardcoded to `7132` for the service, and `7133` for the metrics. +* TLS is assumed to be required, and is set up based on supplied hosts in `redirect.hosts` and `redirect.ingressHosts`. +* It's assumed that this helm chart will be run in it's own namespace, so the naming for all resources is kept as simple as possible. +* Prometheus export annotations are added for metric scraping. +* The default tag is random to randomly cycle through the different implementations, here is the [why](https://github.com/WyriHaximusNet/docker-redirect#why). +* Comes with a pod + diff --git a/charts/redirect/templates/deployment.yaml b/charts/redirect/templates/deployment.yaml index 7ed4b2e..0ff2638 100644 --- a/charts/redirect/templates/deployment.yaml +++ b/charts/redirect/templates/deployment.yaml @@ -16,7 +16,7 @@ spec: metadata: annotations: prometheus.io/scrape: "true" - prometheus.io/port: {{ .Values.service.metricsPort | quote}} + prometheus.io/port: "7133" labels: app: {{ include ".helm.fullname" . }} release: {{ include ".helm.fullname" . }} @@ -38,10 +38,10 @@ spec: imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - name: http - containerPort: {{ .Values.service.port }} + containerPort: 7132 protocol: TCP - name: http-metrics - containerPort: {{ .Values.service.metricsPort }} + containerPort: 7133 protocol: TCP livenessProbe: httpGet: diff --git a/charts/redirect/templates/grafana-influxdb-dashboard.yaml b/charts/redirect/templates/grafana-influxdb-dashboard.yaml index 1081cfd..fcb99e4 100644 --- a/charts/redirect/templates/grafana-influxdb-dashboard.yaml +++ b/charts/redirect/templates/grafana-influxdb-dashboard.yaml @@ -1,3 +1,4 @@ +{{- if .Values.grafana.influxdb -}} apiVersion: v1 kind: ConfigMap metadata: @@ -193,3 +194,4 @@ data: "uid": "Tcemi9yZz", "version": 1 } +{{ end }} \ No newline at end of file diff --git a/charts/redirect/templates/ingress.yaml b/charts/redirect/templates/ingress.yaml index 125500d..1dc96b0 100644 --- a/charts/redirect/templates/ingress.yaml +++ b/charts/redirect/templates/ingress.yaml @@ -1,5 +1,4 @@ {{- $fullName := include ".helm.fullname" . -}} -{{- $svcPort := .Values.service.port -}} {{- $hosts := .Values.redirect.hosts -}} {{- $ingressHosts := .Values.redirect.ingressHosts -}} apiVersion: networking.k8s.io/v1beta1 @@ -31,14 +30,14 @@ spec: rules: {{- if $hosts -}} {{- range $hostFrom, $hostTo := $hosts }} - {{- $host := dict "Host" $hostFrom "FullName" $fullName "SvcPort" $svcPort -}} + {{- $host := dict "Host" $hostFrom "FullName" $fullName "SvcPort" 7132 -}} {{ include ".helm.hostRule" $host | nindent 4 }} {{- end }} {{- end }} {{- if $ingressHosts -}} {{- range $host := $ingressHosts }} {{- if eq (hasKey $hosts $host) false -}} - {{- $host := dict "Host" $host "FullName" $fullName "SvcPort" $svcPort -}} + {{- $host := dict "Host" $host "FullName" $fullName "SvcPort" 7132 -}} {{ include ".helm.hostRule" $host | nindent 4 }} {{- end }} {{- end }} diff --git a/charts/redirect/templates/pod-disruption-budget.yaml b/charts/redirect/templates/pod-disruption-budget.yaml index 0a628df..3ee545f 100644 --- a/charts/redirect/templates/pod-disruption-budget.yaml +++ b/charts/redirect/templates/pod-disruption-budget.yaml @@ -1,3 +1,4 @@ +{{- if gt (.Values.replicaCount | int) 1 -}} apiVersion: policy/v1beta1 kind: PodDisruptionBudget metadata: @@ -7,4 +8,5 @@ spec: selector: matchLabels: app: {{ include ".helm.fullname" . }} - release: {{ include ".helm.fullname" . }} \ No newline at end of file + release: {{ include ".helm.fullname" . }} +{{ end }} \ No newline at end of file diff --git a/charts/redirect/templates/service.yaml b/charts/redirect/templates/service.yaml index 43a8506..8382548 100644 --- a/charts/redirect/templates/service.yaml +++ b/charts/redirect/templates/service.yaml @@ -7,12 +7,12 @@ metadata: spec: type: {{ .Values.service.type }} ports: - - port: {{ .Values.service.port }} - targetPort: {{ .Values.service.port }} + - port: 7132 + targetPort: 7132 protocol: TCP name: http - - port: {{ .Values.service.metricsPort }} - targetPort: {{ .Values.service.metricsPort }} + - port: 7133 + targetPort: 7133 protocol: TCP name: http-metrics selector: diff --git a/charts/redirect/templates/tests/test-metrics-connection.yaml b/charts/redirect/templates/tests/test-metrics-connection.yaml index 7aadf18..f03c292 100644 --- a/charts/redirect/templates/tests/test-metrics-connection.yaml +++ b/charts/redirect/templates/tests/test-metrics-connection.yaml @@ -11,5 +11,5 @@ spec: - name: wget image: busybox command: ['wget'] - args: ['{{ include ".helm.fullname" . }}:{{ .Values.service.metricsPort }}'] + args: ['{{ include ".helm.fullname" . }}:7133'] restartPolicy: Never diff --git a/charts/redirect/templates/tests/test-redirect-connection.yaml b/charts/redirect/templates/tests/test-redirect-connection.yaml index 655650d..b8e0329 100644 --- a/charts/redirect/templates/tests/test-redirect-connection.yaml +++ b/charts/redirect/templates/tests/test-redirect-connection.yaml @@ -11,5 +11,5 @@ spec: - name: wget image: busybox command: ['wget'] - args: ['{{ include ".helm.fullname" . }}:{{ .Values.service.port }}'] + args: ['{{ include ".helm.fullname" . }}:7132'] restartPolicy: Never diff --git a/charts/redirect/values.yaml b/charts/redirect/values.yaml index 6e890da..28f9025 100644 --- a/charts/redirect/values.yaml +++ b/charts/redirect/values.yaml @@ -14,6 +14,9 @@ redirect: ingressHosts: - www.wyrihaximus.net +grafana: + influxdb: false + replicaCount: 2 # Available tags: https://github.com/wyrihaximusnet/docker-redirect#provided-tags @@ -45,8 +48,6 @@ securityContext: {} service: type: ClusterIP - port: 7132 - metricsPort: 7133 ingress: annotations: