Skip to content

Commit

Permalink
add k8s-resources chart
Browse files Browse the repository at this point in the history
  • Loading branch information
rlex committed Dec 7, 2023
1 parent 6d8de50 commit 8a3bcad
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/k8s-resources/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
18 changes: 18 additions & 0 deletions charts/k8s-resources/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions charts/k8s-resources/README.md
Original file line number Diff line number Diff line change
@@ -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.<br>
Since not every chart offers something like extraResources parameter, i use this chart to deploy some stuff along with application - for example, VerticalPodAutoscaler CRs.<br>
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.
43 changes: 43 additions & 0 deletions charts/k8s-resources/README.md.gotmpl
Original file line number Diff line number Diff line change
@@ -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.<br>
Since not every chart offers something like extraResources parameter, i use this chart to deploy some stuff along with application - for example, VerticalPodAutoscaler CRs.<br>
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.
51 changes: 51 additions & 0 deletions charts/k8s-resources/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -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 }}
20 changes: 20 additions & 0 deletions charts/k8s-resources/templates/resource.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
21 changes: 21 additions & 0 deletions charts/k8s-resources/values.yaml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 8a3bcad

Please sign in to comment.