Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
set entire ingress spec to configurable var (#109)
Browse files Browse the repository at this point in the history
Solves #92
  • Loading branch information
WafflesVonMaple authored Oct 12, 2023
1 parent 663949d commit e0a7641
Show file tree
Hide file tree
Showing 12 changed files with 398 additions and 4 deletions.
2 changes: 1 addition & 1 deletion helm/rollup/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.3.1
version: 0.3.2

# 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
Expand Down
32 changes: 32 additions & 0 deletions helm/rollup/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{/*
Return if ingress is stable.
*/}}
{{- define "rollup.ingress.isStable" -}}
{{- eq (include "rollup.ingress.apiVersion" .) "networking.k8s.io/v1" }}
{{- end }}

{{/*
Return if ingress supports ingressClassName.
*/}}
{{- define "rollup.ingress.supportsIngressClassName" -}}
{{- or (eq (include "rollup.ingress.isStable" .) "true") (and (eq (include "rollup.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) }}
{{- end }}

{{/*
Return if ingress supports pathType.
*/}}
{{- define "rollup.ingress.supportsPathType" -}}
{{- or (eq (include "rollup.ingress.isStable" .) "true") (and (eq (include "rollup.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) }}
{{- end }}

Return the appropriate apiVersion for ingress.
*/}}
{{- define "rollup.ingress.apiVersion" -}}
{{- if and ($.Capabilities.APIVersions.Has "networking.k8s.io/v1") (semverCompare ">= 1.19-0" .Capabilities.KubeVersion.Version) }}
{{- print "networking.k8s.io/v1" }}
{{- else if $.Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" }}
{{- print "networking.k8s.io/v1beta1" }}
{{- else }}
{{- print "extensions/v1beta1" }}
{{- end }}
{{- end }}
57 changes: 57 additions & 0 deletions helm/rollup/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,64 @@
{{- if .Values.ingress.enabled -}}
{{- $ingressApiIsStable := eq (include "rollup.ingress.isStable" .) "true" -}}
{{- $ingressSupportsIngressClassName := eq (include "rollup.ingress.supportsIngressClassName" .) "true" -}}
{{- $ingressSupportsPathType := eq (include "rollup.ingress.supportsPathType" .) "true" -}}
{{- $servicePort := .Values.ingress.service.port -}}
{{- $serviceName := .Values.ingress.service.name -}}
{{- $ingressPath := .Values.ingress.path -}}
{{- $ingressPathType := .Values.ingress.pathType -}}
{{- $extraPaths := .Values.ingress.extraPaths -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ .Values.config.rollup.name }}-ingress
namespace: {{ .Values.namespace }}
labels:
{{- with .Values.ingress.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.ingress.annotations }}
annotations:
{{- range $key, $value := . }}
{{ $key }}: {{ tpl $value $ | quote }}
{{- end }}
{{- end }}
spec:
{{- if and $ingressSupportsIngressClassName .Values.ingress.ingressClassName }}
ingressClassName: {{ .Values.ingress.ingressClassName }}
{{- end -}}
{{- with .Values.ingress.defaultBackend }}
defaultBackend:
{{- tpl (toYaml .) $ | nindent 4 }}
{{- end }}
rules:
{{- if .Values.ingress.hosts }}
{{- range .Values.ingress.hosts }}
- host: {{ tpl . $ }}
http:
paths:
{{- with $extraPaths }}
{{- toYaml . | nindent 10 }}
{{- end }}
- path: {{ $ingressPath }}
{{- if $ingressSupportsPathType }}
pathType: {{ $ingressPathType }}
{{- end }}
backend:
{{- if $ingressApiIsStable }}
service:
name: {{ $serviceName }}
port:
number: {{ $servicePort }}
{{- else }}
serviceName: {{ $serviceName }}
servicePort: {{ $servicePort }}
{{- end }}
{{- end }}
{{- with .Values.ingress.tls }}
tls:
{{- tpl (toYaml .) $ | nindent 4 }}
{{- end }}
{{- else }}
- host: executor.{{ .Values.config.rollup.name }}.localdev.me
http:
paths:
Expand Down Expand Up @@ -45,3 +99,6 @@ spec:
name: {{ .Values.config.rollup.name }}-blockscout-svc
port:
name: blockscout-svc
{{- end -}}
{{- end }}

45 changes: 44 additions & 1 deletion helm/rollup/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,50 @@ secretProvider:
filename: evmPrivateKey.txt
resourceName: "projects/$PROJECT_ID/secrets/evmPrivateKey/versions/latest"
key: token


ingress:
enabled: true
# For Kubernetes >= 1.18 you should specify the ingress-controller via the field ingressClassName
# See https://kubernetes.io/blog/2020/04/02/improvements-to-the-ingress-api-in-kubernetes-1.18/#specifying-the-class-of-an-ingress
# ingressClassName: nginx
# Values can be templated
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
labels: {}
path: {}
# pathType is only for k8s >= 1.1=
pathType: Prefix
hosts: {}
# - chart-example.local
service: {}
# name: astria-evm-service
# port:
# name: json-rpc-svc
defaultBackend: {}
# service:
# name: astria-evm-service
# port:
# name: json-rpc-svc
## Extra paths to prepend to every host configuration. This is useful when working with annotation based services.
extraPaths: {}
# - path: /*
# backend:
# serviceName: ssl-redirect
# servicePort: use-annotation
## Or for k8s > 1.19
# - path: /*
# pathType: Prefix
# backend:
# service:
# name: ssl-redirect
# port:
# name: use-annotation
tls: {}
# - secretName: chart-example-tls
# hosts:
# - chart-example.local

# Default persistent storage values
# NOTE - `rollupName` will be used with `persistentVolumeName` to generate names for kubernetes resources.
# e.g. astria-executor-pv, astria-executor-pvc
Expand Down
2 changes: 1 addition & 1 deletion helm/sequencer-faucet/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.2.0
version: 0.2.1

# 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
Expand Down
32 changes: 32 additions & 0 deletions helm/sequencer-faucet/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{/*
Return if ingress is stable.
*/}}
{{- define "sequencer.ingress.isStable" -}}
{{- eq (include "sequencer.ingress.apiVersion" .) "networking.k8s.io/v1" }}
{{- end }}

{{/*
Return if ingress supports ingressClassName.
*/}}
{{- define "sequencer.ingress.supportsIngressClassName" -}}
{{- or (eq (include "sequencer.ingress.isStable" .) "true") (and (eq (include "sequencer.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) }}
{{- end }}

{{/*
Return if ingress supports pathType.
*/}}
{{- define "sequencer.ingress.supportsPathType" -}}
{{- or (eq (include "sequencer.ingress.isStable" .) "true") (and (eq (include "sequencer.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) }}
{{- end }}

Return the appropriate apiVersion for ingress.
*/}}
{{- define "sequencer.ingress.apiVersion" -}}
{{- if and ($.Capabilities.APIVersions.Has "networking.k8s.io/v1") (semverCompare ">= 1.19-0" .Capabilities.KubeVersion.Version) }}
{{- print "networking.k8s.io/v1" }}
{{- else if $.Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" }}
{{- print "networking.k8s.io/v1beta1" }}
{{- else }}
{{- print "extensions/v1beta1" }}
{{- end }}
{{- end }}
56 changes: 56 additions & 0 deletions helm/sequencer-faucet/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,64 @@
{{- if .Values.ingress.enabled -}}
{{- $ingressApiIsStable := eq (include "sequencer.ingress.isStable" .) "true" -}}
{{- $ingressSupportsIngressClassName := eq (include "sequencer.ingress.supportsIngressClassName" .) "true" -}}
{{- $ingressSupportsPathType := eq (include "sequencer.ingress.supportsPathType" .) "true" -}}
{{- $servicePort := .Values.ingress.service.port -}}
{{- $serviceName := .Values.ingress.service.name -}}
{{- $ingressPath := .Values.ingress.path -}}
{{- $ingressPathType := .Values.ingress.pathType -}}
{{- $extraPaths := .Values.ingress.extraPaths -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: sequencer-faucet-ingress
namespace: {{ .Values.namespace }}
labels:
{{- with .Values.ingress.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.ingress.annotations }}
annotations:
{{- range $key, $value := . }}
{{ $key }}: {{ tpl $value $ | quote }}
{{- end }}
{{- end }}
spec:
{{- if and $ingressSupportsIngressClassName .Values.ingress.ingressClassName }}
ingressClassName: {{ .Values.ingress.ingressClassName }}
{{- end -}}
{{- with .Values.ingress.defaultBackend }}
defaultBackend:
{{- tpl (toYaml .) $ | nindent 4 }}
{{- end }}
rules:
{{- if .Values.ingress.hosts }}
{{- range .Values.ingress.hosts }}
- host: {{ tpl . $ }}
http:
paths:
{{- with $extraPaths }}
{{- toYaml . | nindent 10 }}
{{- end }}
- path: {{ $ingressPath }}
{{- if $ingressSupportsPathType }}
pathType: {{ $ingressPathType }}
{{- end }}
backend:
{{- if $ingressApiIsStable }}
service:
name: {{ $serviceName }}
port:
number: {{ $servicePort }}
{{- else }}
serviceName: {{ $serviceName }}
servicePort: {{ $servicePort }}
{{- end }}
{{- end }}
{{- with .Values.ingress.tls }}
tls:
{{- tpl (toYaml .) $ | nindent 4 }}
{{- end }}
{{- else }}
- host: sequencer-faucet.localdev.me
http:
paths:
Expand All @@ -15,3 +69,5 @@ spec:
name: sequencer-faucet-service
port:
name: seq-faucet-svc
{{- end -}}
{{- end }}
43 changes: 43 additions & 0 deletions helm/sequencer-faucet/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,46 @@ secretProvider:

ports:
faucet: 8080

ingress:
enabled: true
# For Kubernetes >= 1.18 you should specify the ingress-controller via the field ingressClassName
# See https://kubernetes.io/blog/2020/04/02/improvements-to-the-ingress-api-in-kubernetes-1.18/#specifying-the-class-of-an-ingress
# ingressClassName: nginx
# Values can be templated
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
labels: {}
path: {}
# pathType is only for k8s >= 1.1=
pathType: Prefix
hosts: {}
# - chart-example.local
service: {}
# name: sequencer-faucet-service
# port:
# name: seq-faucet-svc
defaultBackend: {}
# service:
# name: sequencer-faucet-service
# port:
# name: seq-faucet-svc
## Extra paths to prepend to every host configuration. This is useful when working with annotation based services.
extraPaths: {}
# - path: /*
# backend:
# serviceName: ssl-redirect
# servicePort: use-annotation
## Or for k8s > 1.19
# - path: /*
# pathType: Prefix
# backend:
# service:
# name: ssl-redirect
# port:
# name: use-annotation
tls: {}
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
2 changes: 1 addition & 1 deletion helm/sequencer/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.3.0
version: 0.3.2

# 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
Expand Down
32 changes: 32 additions & 0 deletions helm/sequencer/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{/*
Return if ingress is stable.
*/}}
{{- define "sequencer.ingress.isStable" -}}
{{- eq (include "sequencer.ingress.apiVersion" .) "networking.k8s.io/v1" }}
{{- end }}

{{/*
Return if ingress supports ingressClassName.
*/}}
{{- define "sequencer.ingress.supportsIngressClassName" -}}
{{- or (eq (include "sequencer.ingress.isStable" .) "true") (and (eq (include "sequencer.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) }}
{{- end }}

{{/*
Return if ingress supports pathType.
*/}}
{{- define "sequencer.ingress.supportsPathType" -}}
{{- or (eq (include "sequencer.ingress.isStable" .) "true") (and (eq (include "sequencer.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) }}
{{- end }}

Return the appropriate apiVersion for ingress.
*/}}
{{- define "sequencer.ingress.apiVersion" -}}
{{- if and ($.Capabilities.APIVersions.Has "networking.k8s.io/v1") (semverCompare ">= 1.19-0" .Capabilities.KubeVersion.Version) }}
{{- print "networking.k8s.io/v1" }}
{{- else if $.Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" }}
{{- print "networking.k8s.io/v1beta1" }}
{{- else }}
{{- print "extensions/v1beta1" }}
{{- end }}
{{- end }}
Loading

0 comments on commit e0a7641

Please sign in to comment.