Skip to content

Commit

Permalink
Add commons library
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Dec 9, 2020
1 parent 0bbc88b commit 1cc09b0
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/helm-charts-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ jobs:
echo ::set-output name=url::$(echo "postgresql://postgres:${{ steps.postgresql_passowrd.outputs.password }}@postgresql-helm-charts-${{ github.run_number }}.default/postgres")
- name: Prepare library charts
run: |
cp charts/commons/library-ci/*.yaml charts/commons/templates/
cp charts/cron-jobs/library-ci/*.yaml charts/cron-jobs/templates/
cp charts/horizontal-pod-autoscalers/library-ci/*.yaml charts/horizontal-pod-autoscalers/templates/
cp charts/pi-hole-exporter/library-ci/*.yaml charts/pi-hole-exporter/templates/
sed -i '$ d' charts/commento/ci/postgresql-values.yaml
echo -e " manual: \"${{ steps.postgresql.outputs.url }}\"\r\n" >> charts/commento/ci/postgresql-values.yaml
sed -i 's/library/application/g' charts/commons/Chart.yaml
sed -i 's/library/application/g' charts/cron-jobs/Chart.yaml
sed -i 's/library/application/g' charts/horizontal-pod-autoscalers/Chart.yaml
- name: Test charts
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Opinionated helm chats for my personal projects, and OSS Projects that either do

### Library

* [`commons`](https://artifacthub.io/packages/helm/wyrihaximusnet/commons)
* [`cron-jobs`](https://artifacthub.io/packages/helm/wyrihaximusnet/cron-jobs)
* [`commons`](https://artifacthub.io/packages/helm/wyrihaximusnet/commons)
* [`horizontal-pod-autoscalers`](https://artifacthub.io/packages/helm/wyrihaximusnet/horizontal-pod-autoscalers)

## Opinionated decisions shared by all charts
Expand Down
22 changes: 22 additions & 0 deletions charts/commons/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
10 changes: 10 additions & 0 deletions charts/commons/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v2
name: commons
description: commons library
home: https://github.com/wyrihaximusnet/helm-charts
icon: https://helm.wyrihaximus.net/images/charts/commons.png
type: library
version: 0.1.0
maintainers:
- name: WyriHaximus
email: [email protected]
76 changes: 76 additions & 0 deletions charts/commons/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Commons

<p align="center">
<img src="https://helm.wyrihaximus.net/images/charts/commons.png">
</p>

Opinionated helm library chart containing metadata helpers for helm application charts.

Example deployment using helpers from this chart:
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "commons.fullname" . }}
labels:
{{- include "commons.labels" . | nindent 4 }}
app.kubernetes.io/component: controller
spec:
selector:
matchLabels:
{{- include "commons.selectorLabels" . | nindent 6 }}
replicas: 1
template:
metadata:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9696"
labels:
{{- include "commons.labels" . | nindent 8 }}
spec:
containers:
- name: default-backend
image: "ghcr.io/wyrihaximusnet/default-backend:random"
imagePullPolicy: Always
ports:
- name: default-backend
containerPort: 6969
protocol: TCP
- name: metrics
containerPort: 9696
protocol: TCP
livenessProbe:
failureThreshold: 6
httpGet:
path: /
port: metrics
readinessProbe:
failureThreshold: 6
httpGet:
path: /
port: metrics
startupProbe:
httpGet:
path: /
port: metrics
failureThreshold: 90
periodSeconds: 1
resources:
limits:
cpu: 75m
memory: 64Mi
requests:
cpu: 75m
memory: 64Mi
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: appRevision
operator: In
values:
- {{ template "commons.nameRevision" . }}
topologyKey: "kubernetes.io/hostname"

```
64 changes: 64 additions & 0 deletions charts/commons/library-ci/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "commons.fullname" . }}
labels:
{{- include "commons.labels" . | nindent 4 }}
app.kubernetes.io/component: controller
spec:
selector:
matchLabels:
{{- include "commons.selectorLabels" . | nindent 6 }}
replicas: 1
template:
metadata:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9696"
labels:
{{- include "commons.labels" . | nindent 8 }}
spec:
containers:
- name: default-backend
image: "ghcr.io/wyrihaximusnet/default-backend:random"
imagePullPolicy: Always
ports:
- name: default-backend
containerPort: 6969
protocol: TCP
- name: metrics
containerPort: 9696
protocol: TCP
livenessProbe:
failureThreshold: 6
httpGet:
path: /
port: metrics
readinessProbe:
failureThreshold: 6
httpGet:
path: /
port: metrics
startupProbe:
httpGet:
path: /
port: metrics
failureThreshold: 90
periodSeconds: 1
resources:
limits:
cpu: 75m
memory: 64Mi
requests:
cpu: 75m
memory: 64Mi
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: appRevision
operator: In
values:
- {{ template "commons.nameRevision" . }}
topologyKey: "kubernetes.io/hostname"
7 changes: 7 additions & 0 deletions charts/commons/templates/_chart.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "commons.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
15 changes: 15 additions & 0 deletions charts/commons/templates/_labels.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "commons.labels" -}}
app: {{ template "commons.name" . }}
app.kubernetes.io/instance: {{ template "commons.instance" . }}
app.kubernetes.io/name: {{ template "commons.name" . }}
app.kubernetes.io/version: {{ .Chart.Version | quote }}
appRevision: {{ template "commons.nameRevision" . }}
chart: {{ template "commons.chart" . }}
release: {{ .Release.Name }}
releaseRevision: {{ .Release.Revision | quote }}
heritage: {{ .Release.Service }}
{{- end -}}
34 changes: 34 additions & 0 deletions charts/commons/templates/_name.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "commons.name" -}}
{{- .Chart.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Append the deployed version
*/}}
{{- define "commons.instance" -}}
{{ template "commons.name" . }}-{{ .Chart.Version }}
{{- end -}}

{{/*
Append the deployed revision
*/}}
{{- define "commons.nameRevision" -}}
{{ template "commons.name" . }}___{{ .Release.Revision }}
{{- 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 "commons.fullname" -}}
{{- if contains .Chart.Name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name .Chart.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
8 changes: 8 additions & 0 deletions charts/commons/templates/_selectorLabels.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "commons.selectorLabels" -}}
app: {{ template "commons.name" . }}
release: {{ .Release.Name }}
{{- end -}}
Empty file added charts/commons/values.yaml
Empty file.

0 comments on commit 1cc09b0

Please sign in to comment.