Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(chart): external ingress #1967

Merged
merged 3 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions charts/external-ingress/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions charts/external-ingress/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -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 }}
75 changes: 75 additions & 0 deletions charts/external-ingress/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{{- $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 -}}
{{- $_ := 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 -}}
{{- $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 }}
16 changes: 16 additions & 0 deletions charts/external-ingress/templates/services.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
34 changes: 34 additions & 0 deletions charts/external-ingress/values.yaml
Original file line number Diff line number Diff line change
@@ -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: {}