From 626b2f3437f17d8557dc1279073321c5cdcbf8c0 Mon Sep 17 00:00:00 2001 From: dy46 Date: Thu, 25 Jan 2024 17:09:16 -0800 Subject: [PATCH 1/2] [dy] Add ingress chart --- charts/ingress/.helmignore | 23 +++++++ charts/ingress/Chart.yaml | 70 ++++++++++++++++++++ charts/ingress/templates/NOTES.txt | 8 +++ charts/ingress/templates/_helpers.tpl | 92 +++++++++++++++++++++++++++ charts/ingress/templates/ingress.yaml | 59 +++++++++++++++++ charts/ingress/values.yaml | 20 ++++++ charts/mageai/values.yaml | 3 + 7 files changed, 275 insertions(+) create mode 100644 charts/ingress/.helmignore create mode 100644 charts/ingress/Chart.yaml create mode 100644 charts/ingress/templates/NOTES.txt create mode 100644 charts/ingress/templates/_helpers.tpl create mode 100644 charts/ingress/templates/ingress.yaml create mode 100644 charts/ingress/values.yaml diff --git a/charts/ingress/.helmignore b/charts/ingress/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/ingress/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/ingress/Chart.yaml b/charts/ingress/Chart.yaml new file mode 100644 index 0000000..672aa12 --- /dev/null +++ b/charts/ingress/Chart.yaml @@ -0,0 +1,70 @@ +annotations: + artifacthub.io/alternativeName: Mage-Ingress + artifacthub.io/category: integration-delivery + artifacthub.io/images: | + - name: mageai + image: mageai/mageai:0.9.44 + platforms: + - linux/amd64 + - linux/arm64 + - name: busybox + image: busybox + whitelisted: true + artifacthub.io/license: Apache-2.0 + artifacthub.io/links: | + - name: Homepage + url: https://www.mage.ai/ + - name: Source + url: https://github.com/mage-ai/helm-charts + - name: Documentation + url: https://mage-ai.github.io/helm-charts/ + artifacthub.io/maintainers: | + - name: Mage + email: eng@mage.ai + artifacthub.io/screenshots: | + - title: Build Pipeline + url: https://www.mage.ai/images/pages/home/screenshots/v5/Build@2x.png + - title: Preview Pipeline + url: https://www.mage.ai/images/pages/home/screenshots/v5/Preview@2x.png + - title: Launch Pipeline + url: https://www.mage.ai/images/pages/home/screenshots/v5/Launch@2x.webp + +apiVersion: v2 + +# 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.9.55" + +description: A Helm chart for deploying ingress for Mage AI + +home: https://www.mage.ai + +icon: https://avatars.githubusercontent.com/u/69371472 + +maintainers: + - name: mage-ai + url: https://www.mage.ai + email: eng@mage.ai + +name: mageai-ingress + + +sources: +- https://github.com/mage-ai/helm-charts/tree/master/charts/ingress + +# 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.0.1 diff --git a/charts/ingress/templates/NOTES.txt b/charts/ingress/templates/NOTES.txt new file mode 100644 index 0000000..d35b0de --- /dev/null +++ b/charts/ingress/templates/NOTES.txt @@ -0,0 +1,8 @@ +{{- if .Values.ingress.enabled }} +The following hosts were added to the ingress: +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- end }} diff --git a/charts/ingress/templates/_helpers.tpl b/charts/ingress/templates/_helpers.tpl new file mode 100644 index 0000000..08ffbfa --- /dev/null +++ b/charts/ingress/templates/_helpers.tpl @@ -0,0 +1,92 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "mageai.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "mageai.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "mageai.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "mageai.labels" -}} +helm.sh/chart: {{ include "mageai.chart" . }} +{{ include "mageai.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "mageai.selectorLabels" -}} +app.kubernetes.io/name: {{ include "mageai.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + + +{{/* +Scheduler Selector labels +*/}} +{{- define "mageai.schedulerSelectorLabels" -}} +app.kubernetes.io/name: {{ .Values.scheduler.name }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + + +{{/* +Create the name of the service account to use +*/}} +{{- define "mageai.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "mageai.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{/* +Generate chart secret name +*/}} +{{- define "mageai.secretName" -}} +{{ default (printf "%s-secret-env" (include "mageai.fullname" .)) .Values.existingSecret }} +{{- end -}} + +{{/* +Base path +*/}} +{{- define "mageai.basePath" -}} +{{- if .Values.extraEnvs }} +{{- range .Values.extraEnvs }} +{{- if eq .name "MAGE_BASE_PATH" }} +{{- printf "/%s" .value }} +{{- end -}} +{{- end -}} +{{- end -}} +{{- end -}} diff --git a/charts/ingress/templates/ingress.yaml b/charts/ingress/templates/ingress.yaml new file mode 100644 index 0000000..21beaa7 --- /dev/null +++ b/charts/ingress/templates/ingress.yaml @@ -0,0 +1,59 @@ +{{- if .Values.ingress.enabled -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ .Values.ingress.name }} + labels: + {{- include "mageai.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ .backend.service.name }} + port: + number: {{ .backend.service.port }} + {{- else }} + serviceName: {{ .backend.service.name }} + servicePort: {{ .backend.service.port }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/ingress/values.yaml b/charts/ingress/values.yaml new file mode 100644 index 0000000..09d5706 --- /dev/null +++ b/charts/ingress/values.yaml @@ -0,0 +1,20 @@ +ingress: + name: mageai + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + backend: + service: + name: mageai + port: 6789 + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local diff --git a/charts/mageai/values.yaml b/charts/mageai/values.yaml index a09ead5..f550c92 100644 --- a/charts/mageai/values.yaml +++ b/charts/mageai/values.yaml @@ -95,6 +95,9 @@ customLivenessProbe: {} # Custom readiness probe customReadinessProbe: {} +# We recommend creating the ingress separately instead of creating it using this chart. +# There is a corresponding Mage-Ingress chart to create an ingress for Mage if needed. +# This section is kept here for backwards compatibility. ingress: enabled: false className: "" From c487c2a54293a39c7fb66f7f049c5c70ad44ecc7 Mon Sep 17 00:00:00 2001 From: dy46 Date: Wed, 31 Jan 2024 10:45:13 -0800 Subject: [PATCH 2/2] [dy] Update Chart.yaml --- charts/ingress/Chart.yaml | 17 +------- charts/ingress/templates/_helpers.tpl | 59 --------------------------- 2 files changed, 1 insertion(+), 75 deletions(-) diff --git a/charts/ingress/Chart.yaml b/charts/ingress/Chart.yaml index 672aa12..4c813ca 100644 --- a/charts/ingress/Chart.yaml +++ b/charts/ingress/Chart.yaml @@ -1,15 +1,6 @@ annotations: artifacthub.io/alternativeName: Mage-Ingress - artifacthub.io/category: integration-delivery - artifacthub.io/images: | - - name: mageai - image: mageai/mageai:0.9.44 - platforms: - - linux/amd64 - - linux/arm64 - - name: busybox - image: busybox - whitelisted: true + artifacthub.io/category: networking artifacthub.io/license: Apache-2.0 artifacthub.io/links: | - name: Homepage @@ -31,12 +22,6 @@ annotations: apiVersion: v2 -# 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.9.55" - description: A Helm chart for deploying ingress for Mage AI home: https://www.mage.ai diff --git a/charts/ingress/templates/_helpers.tpl b/charts/ingress/templates/_helpers.tpl index 08ffbfa..23a9f2c 100644 --- a/charts/ingress/templates/_helpers.tpl +++ b/charts/ingress/templates/_helpers.tpl @@ -5,24 +5,6 @@ Expand the name of the chart. {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} {{- end }} -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -If release name contains chart name it will be used as a full name. -*/}} -{{- define "mageai.fullname" -}} -{{- if .Values.fullnameOverride }} -{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- $name := default .Chart.Name .Values.nameOverride }} -{{- if contains $name .Release.Name }} -{{- .Release.Name | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} -{{- end }} -{{- end }} -{{- end }} - {{/* Create chart name and version as used by the chart label. */}} @@ -49,44 +31,3 @@ Selector labels app.kubernetes.io/name: {{ include "mageai.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} - - -{{/* -Scheduler Selector labels -*/}} -{{- define "mageai.schedulerSelectorLabels" -}} -app.kubernetes.io/name: {{ .Values.scheduler.name }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end }} - - -{{/* -Create the name of the service account to use -*/}} -{{- define "mageai.serviceAccountName" -}} -{{- if .Values.serviceAccount.create }} -{{- default (include "mageai.fullname" .) .Values.serviceAccount.name }} -{{- else }} -{{- default "default" .Values.serviceAccount.name }} -{{- end }} -{{- end }} - -{{/* -Generate chart secret name -*/}} -{{- define "mageai.secretName" -}} -{{ default (printf "%s-secret-env" (include "mageai.fullname" .)) .Values.existingSecret }} -{{- end -}} - -{{/* -Base path -*/}} -{{- define "mageai.basePath" -}} -{{- if .Values.extraEnvs }} -{{- range .Values.extraEnvs }} -{{- if eq .name "MAGE_BASE_PATH" }} -{{- printf "/%s" .value }} -{{- end -}} -{{- end -}} -{{- end -}} -{{- end -}}