From d1fd35a8b581669cddeb0315c02a08e8e388e5c9 Mon Sep 17 00:00:00 2001 From: Jordan Oroshiba Date: Wed, 10 Jul 2024 13:51:32 +0200 Subject: [PATCH 1/2] feat(chart): external ingress --- charts/external-ingress/Chart.yaml | 32 +++++++++ .../external-ingress/templates/_helpers.tpl | 40 +++++++++++ .../external-ingress/templates/ingress.yaml | 69 +++++++++++++++++++ .../external-ingress/templates/services.yaml | 16 +++++ charts/external-ingress/values.yaml | 34 +++++++++ 5 files changed, 191 insertions(+) create mode 100644 charts/external-ingress/Chart.yaml create mode 100644 charts/external-ingress/templates/_helpers.tpl create mode 100644 charts/external-ingress/templates/ingress.yaml create mode 100644 charts/external-ingress/templates/services.yaml create mode 100644 charts/external-ingress/values.yaml diff --git a/charts/external-ingress/Chart.yaml b/charts/external-ingress/Chart.yaml new file mode 100644 index 0000000000..c1dacd1e16 --- /dev/null +++ b/charts/external-ingress/Chart.yaml @@ -0,0 +1,32 @@ +apiVersion: v2 +name: external-ingress +description: A Helm chart for deploying ingress access to services in another application set. + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +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.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. 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.1.0" + +maintainers: + - name: wafflesvonmaple + url: astria.org + - name: quasystaty1 + url: astria.org + - name: joroshiba + url: astria.org diff --git a/charts/external-ingress/templates/_helpers.tpl b/charts/external-ingress/templates/_helpers.tpl new file mode 100644 index 0000000000..c14ecb0a94 --- /dev/null +++ b/charts/external-ingress/templates/_helpers.tpl @@ -0,0 +1,40 @@ +{{/* +Namepsace to deploy elements into. +*/}} +{{- define "external-ingress.namespace" -}} +{{- default .Release.Namespace .Values.global.namespaceOverride | trunc 63 | trimSuffix "-" -}} +{{- end }} + +{{/* +Return if ingress is stable. +*/}} +{{- define "external-ingress.isStable" -}} +{{- eq (include "external-ingress.apiVersion" .) "networking.k8s.io/v1" }} +{{- end }} + +{{/* +Return if ingress supports ingressClassName. +*/}} +{{- define "external-ingress.supportsIngressClassName" -}} +{{- or (eq (include "external-ingress.isStable" .) "true") (and (eq (include "external-ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) }} +{{- end }} + +{{/* +Return if ingress supports pathType. +*/}} +{{- define "external-ingress.supportsPathType" -}} +{{- or (eq (include "external-ingress.isStable" .) "true") (and (eq (include "external-ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) }} +{{- end }} + +{{/* +Return the appropriate apiVersion for ingress. +*/}} +{{- define "external-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 }} diff --git a/charts/external-ingress/templates/ingress.yaml b/charts/external-ingress/templates/ingress.yaml new file mode 100644 index 0000000000..04e525730e --- /dev/null +++ b/charts/external-ingress/templates/ingress.yaml @@ -0,0 +1,69 @@ +{{- $ingressApiIsStable := eq (include "external-ingress.isStable" .) "true" -}} +{{- $ingressSupportsIngressClassName := eq (include "external-ingress.supportsIngressClassName" .) "true" -}} +{{- $ingressSupportsPathType := eq (include "external-ingress.supportsPathType" .) "true" -}} + +{{- range $name, $ingress := .Values.ingress }} +{{- $serviceName := $ingress.service -}} +{{- $servicePort := $ingress.port -}} +{{- $ingressPath := default "/" $ingress.path -}} +{{- $ingressPathType := default "Prefix" $ingress.pathType -}} +{{- $extraPaths := $ingress.extraPaths -}} +{{- $ingressClassName := default "nginx" $ingress.className }} +apiVersion: {{ include "external-ingress.apiVersion" $ }} +kind: Ingress +metadata: + name: {{ $name }}-ingress + namespace: {{ include "external-ingress.namespace" $ }} + labels: + {{- with $ingress.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} + annotations: + {{- if not $ingressSupportsIngressClassName }} + kubernetes.io/ingress.class: {{ $ingressClassName }} + {{- end }} + {{- if $ingressApiIsStable }} + {{- range $key, $value := $ingress.annotations }} + {{ $key }}: {{ tpl $value $ | quote }} + {{- end }} + {{- end }} +spec: + {{- if $ingressSupportsIngressClassName }} + ingressClassName: {{ $ingressClassName }} + {{- end }} + defaultBackend: + service: + name: {{ $serviceName }} + port: + number: {{ $servicePort }} + rules: + {{- with $ingress.hosts }} + {{- range $host := . }} + - host: {{ tpl $host $ }} + 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: {{ tpl $serviceName $ }} + servicePort: {{ tpl $servicePort $ }} + {{- end }} + {{- end }} + {{- end }} + {{- if $ingress.tls }} + tls: + {{- tpl (toYaml $ingress.tls) $ | nindent 4 }} + {{- end }} +--- +{{- end }} diff --git a/charts/external-ingress/templates/services.yaml b/charts/external-ingress/templates/services.yaml new file mode 100644 index 0000000000..e512709cf9 --- /dev/null +++ b/charts/external-ingress/templates/services.yaml @@ -0,0 +1,16 @@ +{{ $namespace := include "external-ingress.namespace" . }} +{{- range $name, $service := .Values.services }} +kind: Service +apiVersion: v1 +metadata: + name: {{ $name }} + namespace: {{ $namespace }} + labels: + {{- range $key, $value := $service.labels }} + {{ $key }}: {{ $value }} + {{- end }} +spec: + type: ExternalName + externalName: {{ $service.externalServiceName }} +--- +{{- end }} diff --git a/charts/external-ingress/values.yaml b/charts/external-ingress/values.yaml new file mode 100644 index 0000000000..4be483aae2 --- /dev/null +++ b/charts/external-ingress/values.yaml @@ -0,0 +1,34 @@ +global: + namespaceOverride: "" + +services: +# evm-rpc: +# externalServiceName: astria-evm-service.astria-dev-cluster.svc.cluster.local +# evm-faucet: +# externalServiceName: astria-faucet-service.astria-dev-cluster.svc.cluster.local + +ingress: +# rpc: +# service: evm-rpc +# port: 8545 +# hosts: +# - rpc.flame.localdev.me +# labels: {} +# annotations: {} +# tls: {} +# ws: +# service: evm-rpc +# port: 8546 +# hosts: +# - ws.flame.localdev.me +# labels: {} +# annotations: {} +# tls: {} +# faucet: +# service: evm-faucet +# port: 8080 +# hosts: +# - faucet.flame.localdev.me +# labels: { } +# annotations: {} +# tls: {} From 12a03262c8f93cb8e27a693f2a5ffec65675d826 Mon Sep 17 00:00:00 2001 From: Jordan Oroshiba Date: Wed, 12 Feb 2025 11:48:53 -0800 Subject: [PATCH 2/2] add requirement --- charts/external-ingress/templates/ingress.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/charts/external-ingress/templates/ingress.yaml b/charts/external-ingress/templates/ingress.yaml index 04e525730e..5f3adadb11 100644 --- a/charts/external-ingress/templates/ingress.yaml +++ b/charts/external-ingress/templates/ingress.yaml @@ -4,6 +4,12 @@ {{- range $name, $ingress := .Values.ingress }} {{- $serviceName := $ingress.service -}} +{{- $_ := hasKey $.Values.services $serviceName | required "ingress.service must be one of the chart services" -}} +{{- $servicePort := $ingress.port -}} +{{- $ingressPath := default "/" $ingress.path -}} +{{- $ingressPathType := default "Prefix" $ingress.pathType -}} +{{- $extraPaths := $ingress.extraPaths -}} +{{- $ingressClassName := default "nginx" $ingress.className }} {{- $servicePort := $ingress.port -}} {{- $ingressPath := default "/" $ingress.path -}} {{- $ingressPathType := default "Prefix" $ingress.pathType -}}