From bf29646c600d750969c4df3387eaf201085708b4 Mon Sep 17 00:00:00 2001 From: Ruslan Timofieiev Date: Thu, 14 Dec 2023 14:02:01 +0200 Subject: [PATCH] Init helm chart --- README.md | 1 + chart/.helmignore | 23 ++++++++++++ chart/Chart.yaml | 24 +++++++++++++ chart/templates/_helpers.tpl | 53 +++++++++++++++++++++++++++ chart/templates/endpoint.yaml | 21 +++++++++++ chart/templates/ingress.yaml | 68 +++++++++++++++++++++++++++++++++++ chart/templates/service.yaml | 20 +++++++++++ chart/values.yaml | 28 +++++++++++++++ 8 files changed, 238 insertions(+) create mode 100644 README.md create mode 100644 chart/.helmignore create mode 100644 chart/Chart.yaml create mode 100644 chart/templates/_helpers.tpl create mode 100644 chart/templates/endpoint.yaml create mode 100644 chart/templates/ingress.yaml create mode 100644 chart/templates/service.yaml create mode 100644 chart/values.yaml diff --git a/README.md b/README.md new file mode 100644 index 0000000..73f5ba8 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# External Services Helm chart diff --git a/chart/.helmignore b/chart/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/chart/.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/chart/Chart.yaml b/chart/Chart.yaml new file mode 100644 index 0000000..6492179 --- /dev/null +++ b/chart/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: external-services +description: A Helm chart for Kubernetes + +# 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: "1.16.0" diff --git a/chart/templates/_helpers.tpl b/chart/templates/_helpers.tpl new file mode 100644 index 0000000..adcf898 --- /dev/null +++ b/chart/templates/_helpers.tpl @@ -0,0 +1,53 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "external-services.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 "external-services.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 "external-services.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "external-services.labels" -}} +helm.sh/chart: {{ include "external-services.chart" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "external-services.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "external-services.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/chart/templates/endpoint.yaml b/chart/templates/endpoint.yaml new file mode 100644 index 0000000..aaca23b --- /dev/null +++ b/chart/templates/endpoint.yaml @@ -0,0 +1,21 @@ +{{- $name := include "external-services.name" . -}} + +{{- range .Values.services -}} +{{- $endpointName := printf "%s-%s" $name .name }} +--- +apiVersion: v1 +kind: Endpoints +metadata: + name: {{ $endpointName }} + labels: + {{- include "external-services.labels" $ | nindent 4 }} +subsets: +- addresses: + {{- range .addresses }} + - ip: {{ . }} + {{- end }} + ports: + - name: {{ .portName }} + port: {{ .targetPort }} + protocol: {{ .protocol }} +{{- end }} diff --git a/chart/templates/ingress.yaml b/chart/templates/ingress.yaml new file mode 100644 index 0000000..80bbfb2 --- /dev/null +++ b/chart/templates/ingress.yaml @@ -0,0 +1,68 @@ +{{- $fullName := include "external-services.fullname" . -}} +{{- $name := include "external-services.name" . -}} + +{{- range .Values.services }} +{{- if and $.Values.ingress.className (not (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .ingress.annotations "kubernetes.io/ingress.class" $.Values.ingress.className}} + {{- end }} +{{- end -}} + +{{- $ingressName := printf "%s-%s" $fullName .name }} +{{- $serviceName := printf "%s-%s" $name .name }} +{{- $servicePort := .port }} +{{- $servicePortName := .portName }} +--- +{{- 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: {{ $ingressName }} + labels: + {{- include "external-services.labels" $ | nindent 4 }} + {{- with .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 .ingress.tls }} + tls: + {{- range .ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .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: {{ $serviceName }} + port: + name: {{ $servicePortName }} + {{- else }} + serviceName: {{ $serviceName }} + servicePort: {{ $servicePort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/chart/templates/service.yaml b/chart/templates/service.yaml new file mode 100644 index 0000000..4b43b5b --- /dev/null +++ b/chart/templates/service.yaml @@ -0,0 +1,20 @@ +{{- $name := include "external-services.name" . -}} + +{{- range .Values.services -}} +{{- $serviceName := printf "%s-%s" $name .name }} +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ $serviceName }} + labels: + {{- include "external-services.labels" $ | nindent 4 }} +spec: + type: ClusterIP + ports: + - name: {{ .portName }} + port: {{ .port }} + targetPort: {{ .targetPort }} + protocol: {{ .protocol }} + clusterIP: None +{{- end }} diff --git a/chart/values.yaml b/chart/values.yaml new file mode 100644 index 0000000..493b97b --- /dev/null +++ b/chart/values.yaml @@ -0,0 +1,28 @@ +# Default values for external-services. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +ingress: + className: nginx + +# services: +# - name: proxmox +# portName: app +# port: 80 +# targetPort: 8006 +# protocol: TCP +# addresses: +# - 192.168.1.1 +# ingress: +# annotations: +# cert-manager.io/cluster-issuer: letsencrypt-production +# hosts: +# - host: proxmox.op8.fun +# paths: +# - path: / +# pathType: Prefix +# tls: +# - hosts: +# - proxmox.op8.fun +# secretName: proxmox-letsencrypt +services: []