From 8a3bcad855938d298de0a7df77386b275efc71f9 Mon Sep 17 00:00:00 2001 From: Lex Rivera Date: Thu, 7 Dec 2023 18:52:45 +0300 Subject: [PATCH] add k8s-resources chart --- charts/k8s-resources/.helmignore | 23 +++++++++ charts/k8s-resources/Chart.yaml | 18 +++++++ charts/k8s-resources/README.md | 45 +++++++++++++++++ charts/k8s-resources/README.md.gotmpl | 43 +++++++++++++++++ charts/k8s-resources/templates/_helpers.tpl | 51 ++++++++++++++++++++ charts/k8s-resources/templates/resource.yaml | 20 ++++++++ charts/k8s-resources/values.yaml | 21 ++++++++ 7 files changed, 221 insertions(+) create mode 100644 charts/k8s-resources/.helmignore create mode 100644 charts/k8s-resources/Chart.yaml create mode 100644 charts/k8s-resources/README.md create mode 100644 charts/k8s-resources/README.md.gotmpl create mode 100644 charts/k8s-resources/templates/_helpers.tpl create mode 100644 charts/k8s-resources/templates/resource.yaml create mode 100644 charts/k8s-resources/values.yaml diff --git a/charts/k8s-resources/.helmignore b/charts/k8s-resources/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/charts/k8s-resources/.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/k8s-resources/Chart.yaml b/charts/k8s-resources/Chart.yaml new file mode 100644 index 000000000..ca806cef6 --- /dev/null +++ b/charts/k8s-resources/Chart.yaml @@ -0,0 +1,18 @@ +apiVersion: v2 +name: k8s-resources +description: Helm chart to create any type of k8s resource + +# 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 diff --git a/charts/k8s-resources/README.md b/charts/k8s-resources/README.md new file mode 100644 index 000000000..4bdc7f44a --- /dev/null +++ b/charts/k8s-resources/README.md @@ -0,0 +1,45 @@ +# k8s-resources + +![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) + +Helm chart to create any type of k8s resource + +This is a very simple chart to create any type of kubernetes resources with helm.
+Since not every chart offers something like extraResources parameter, i use this chart to deploy some stuff along with application - for example, VerticalPodAutoscaler CRs.
+Example usage with all supported parameters: +```yaml +resources: + - name: vpa-loki-ingester + # override generated resource name + fullnameOverride: "vpa-loki-ingester" + # add annotations + annotations: + annotation: value + # add annotations + labels: + some-label: value + # apiVersion of resource + apiVersion: autoscaling.k8s.io/v1 + # kind of resource + kind: VerticalPodAutoscaler + # resource spec + spec: + targetRef: + apiVersion: "apps/v1" + kind: Deployment + name: loki-ingester + updatePolicy: + updateMode: "Off" +``` + +## Values + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| fullnameOverride | string | `""` | Overrides helm-generated chart fullname | +| nameOverride | string | `""` | overrides chart name | +| resources | object | `{}` | dict with user-provided resources | + +## Upgrading + +A major chart version change indicates that there is an incompatible breaking change needing manual actions. \ No newline at end of file diff --git a/charts/k8s-resources/README.md.gotmpl b/charts/k8s-resources/README.md.gotmpl new file mode 100644 index 000000000..40fc3b1cc --- /dev/null +++ b/charts/k8s-resources/README.md.gotmpl @@ -0,0 +1,43 @@ +{{ template "chart.header" . }} + +{{ template "chart.versionBadge" . }}{{ template "chart.typeBadge" . }} + +{{ template "chart.description" . }} + +{{ template "chart.sourcesSection" . }} + +{{ template "chart.requirementsSection" . }} + +This is a very simple chart to create any type of kubernetes resources with helm.
+Since not every chart offers something like extraResources parameter, i use this chart to deploy some stuff along with application - for example, VerticalPodAutoscaler CRs.
+Example usage with all supported parameters: +```yaml +resources: + - name: vpa-loki-ingester + # override generated resource name + fullnameOverride: "vpa-loki-ingester" + # add annotations + annotations: + annotation: value + # add annotations + labels: + some-label: value + # apiVersion of resource + apiVersion: autoscaling.k8s.io/v1 + # kind of resource + kind: VerticalPodAutoscaler + # resource spec + spec: + targetRef: + apiVersion: "apps/v1" + kind: Deployment + name: loki-ingester + updatePolicy: + updateMode: "Off" +``` + +{{ template "chart.valuesSection" . }} + +## Upgrading + +A major chart version change indicates that there is an incompatible breaking change needing manual actions. \ No newline at end of file diff --git a/charts/k8s-resources/templates/_helpers.tpl b/charts/k8s-resources/templates/_helpers.tpl new file mode 100644 index 000000000..627502302 --- /dev/null +++ b/charts/k8s-resources/templates/_helpers.tpl @@ -0,0 +1,51 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "k8s-resources.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 "k8s-resources.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 "k8s-resources.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "k8s-resources.labels" -}} +helm.sh/chart: {{ include "k8s-resources.chart" . }} +{{ include "k8s-resources.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "k8s-resources.selectorLabels" -}} +app.kubernetes.io/name: {{ include "k8s-resources.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/charts/k8s-resources/templates/resource.yaml b/charts/k8s-resources/templates/resource.yaml new file mode 100644 index 000000000..593c2b727 --- /dev/null +++ b/charts/k8s-resources/templates/resource.yaml @@ -0,0 +1,20 @@ +{{- if .Values.resources -}} +{{- range .Values.resources }} +apiVersion: {{ .apiVersion }} +kind: {{ .kind }} +metadata: + name: {{ if .fullnameOverride }}{{ .fullnameOverride }}{{ else }}{{ include "k8s-resources.fullname" $ }}-{{ .name }}{{ end }} + labels: + {{- include "k8s-resources.labels" $ | nindent 4 }} + {{- with .labels }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: +{{- toYaml .spec | nindent 2 }} +--- +{{- end }} +{{- end }} diff --git a/charts/k8s-resources/values.yaml b/charts/k8s-resources/values.yaml new file mode 100644 index 000000000..db8b748e9 --- /dev/null +++ b/charts/k8s-resources/values.yaml @@ -0,0 +1,21 @@ +# -- overrides chart name +nameOverride: "" +# -- Overrides helm-generated chart fullname +fullnameOverride: "" +# -- dict with user-provided resources +resources: {} +# - name: vpa-loki-ingester +# fullnameOverride: "vpa-loki-ingester" +# annotations: +# annotation: value +# labels: +# some-label: value +# apiVersion: autoscaling.k8s.io/v1 +# kind: VerticalPodAutoscaler +# spec: +# targetRef: +# apiVersion: "apps/v1" +# kind: Deployment +# name: loki-ingester +# updatePolicy: +# updateMode: "Off" \ No newline at end of file