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

add template implementation of ingress matching humanitec/ingress #122

Merged
merged 3 commits into from
Jan 9, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
for resourceDefinition in ${resourceDefinitions}
do
echo ${resourceDefinition}
if [ "${resourceDefinition}" != "resource-definitions/template-driver/ingress/ingress-traefik-multiple-routes.yaml" ]; then
if [ "${resourceDefinition}" != "resource-definitions/template-driver/ingress/ingress-traefik-multiple-routes.yaml" ] && [ "${resourceDefinition}" != "resource-definitions/template-driver/ingress/ingress-default.yaml" ]; then
inputs=$(echo ${resourceDefinition} | sed "s,/,-,g")
humctl resources test-definition ${resourceDefinition} --generate > ${inputs}
sed -i 's/context.res.id: ""/context.res.id: "modules.test.externals.test"/g' ${inputs}
Expand Down
1 change: 1 addition & 0 deletions resource-definitions/template-driver/ingress/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
This section contains example Resource Definitions for handling Kubernetes ingress traffic.
Instead of the Driver type [Ingress](https://developer.humanitec.com/integration-and-extensions/drivers/k8-drivers/ingress/), we are using the [Template](https://developer.humanitec.com/integration-and-extensions/drivers/generic-drivers/template/) Driver type, which allows us to render any Kubernetes YAML object.

* [ingress-default.yaml](ingress-default.yaml): defines an `Ingress` object in the same way as the [humanitec/ingress](https://developer.humanitec.com/integration-and-extensions/drivers/k8-drivers/ingress/) driver.
* [ingress-traefik.yaml](ingress-traefik.yaml): defines an `IngressRoute` object for the [Traefik Ingress Controller](https://doc.traefik.io/traefik/) using the [IngressRoute custom resource definition](https://doc.traefik.io/traefik/providers/kubernetes-crd/). This format is for use with the [Humanitec CLI](https://developer.humanitec.com/platform-orchestrator/cli/)
* [ingress-traefik-multiple-routes.yaml](./ingress-traefik-multiple-routes.yaml): defines an `IngressRoute` object for the [Traefik Ingress Controller](https://doc.traefik.io/traefik/) using the [IngressRoute custom resource definition](https://doc.traefik.io/traefik/providers/kubernetes-crd/). It dynamically extracts the routes from the `route` resource in the Resource Graph to provide multiple routes. This format is for use with the [Humanitec CLI](https://developer.humanitec.com/platform-orchestrator/cli/)
* [ingress-ambassador.yaml](ingress-ambassador.yaml): defines a `Mapping` object for the [Ambassador Ingress Controller](https://www.getambassador.io/docs/emissary/latest/topics/running/ingress-controller) using the [Mapping custom resource definition](https://www.getambassador.io/docs/edge-stack/latest/topics/using/intro-mappings). This format is for use with the [Humanitec CLI](https://developer.humanitec.com/platform-orchestrator/cli/)
86 changes: 86 additions & 0 deletions resource-definitions/template-driver/ingress/ingress-default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# This Resource Definition provisions the equivalent of the humanitec/ingress driver
apiVersion: entity.humanitec.io/v1b1
kind: Definition
metadata:
id: default-ingress
entity:
name: default-ingress
type: ingress
driver_type: humanitec/template
driver_inputs:
values:
templates:
manifests: |
{{- /*
Only generate an ingress manifest if there are any routes defined.
*/ -}}
{{- if gt (len .driver.values.routePaths ) 0 -}}
ingress.yaml:
location: namespace
data:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
{{- if hasKey .driver.values "annotations" }}
annotations: {{ .driver.values.annotations | toRawJson }}
{{- end}}
{{- if hasKey .driver.values "labels" }}
labels: {{ .driver.values.labels | toRawJson }}
{{- end}}
name: {{ .id }}-ingress
spec:
{{- if .driver.values.class }}
ingressClassName: {{ .driver.values.class | toRawJson }}
{{- end }}
rules:
- host: {{ .driver.values.host | toRawJson }}
http:
paths:
{{- /*
We are guaranteed that .driver.values.routePaths is non-zero in
length from the top level if statement, so we don't need
to deal with the empty condition.
*/ -}}
{{- range $index, $path := .driver.values.routePaths }}
- path: {{ $path | toRawJson }}
pathType: {{ $.driver.values.path_type | default "Prefix" | toRawJson }}
backend:
service:
name: {{ index $.driver.values.routeServices $index | toRawJson }}
port:
number: {{ index $.driver.values.routePorts $index }}
{{- end }}
{{- if not (or .driver.values.no_tls (eq (.driver.values.tls_secret_name | default "") "")) }}
tls:
- hosts:
- {{ .driver.values.host | toRawJson }}
secretName: {{ .driver.values.tls_secret_name | toRawJson }}
{{- end }}
{{- end -}}
outputs: |
no_tls: {{ .driver.values.no_tls | default false }}
id: {{ .id }}-ingress


# The host will be used from the dns resource with the same
# ResID and Class as this ingress.
host: ${resources.dns.outputs.host}

# These 3 selectors are guaranteed to return JSON arrays.
# They will all be empty if there are no routes referencing this.
routePaths: ${resources.dns<route.outputs.path}
routePorts: ${resources.dns<route.outputs.port}
routeServices: ${resources.dns<route.outputs.service}


# The following fields can be set based on the documented driver inputs
# for humanitec/ingress.
# Uncomment and add values.

# annotations: {}
# class: nginx
# labels: {}
# no_tls: true
# path_type: Prefix
# tls_secret_name: ""