Skip to content

Commit

Permalink
Merge pull request #45 from WyriHaximusNet/redirect-add-recycle-cronjob
Browse files Browse the repository at this point in the history
[redirect] Add recycle cronjob
  • Loading branch information
WyriHaximus authored Oct 23, 2020
2 parents eefa4f2 + a0fdd41 commit 7e72917
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 3 deletions.
7 changes: 5 additions & 2 deletions charts/redirect/Chart.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
dependencies:
- name: cron-jobs
repository: https://helm.wyrihaximus.net/
version: 0.1.2
- name: horizontal-pod-autoscalers
repository: https://helm.wyrihaximus.net/
version: 0.2.0
digest: sha256:c24acf3aaf1d76d5b431e2d608ee5162acf6e5bb0ad764b2a3cf81e37bb499bf
generated: "2020-10-21T20:35:46.408821942+02:00"
digest: sha256:da3cabd092499f75f425706a7faae76bdefe5a54d805628ea48a3b769e8cbf2b
generated: "2020-10-23T17:11:42.5637418+02:00"
5 changes: 4 additions & 1 deletion charts/redirect/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ description: Redirect
home: https://github.com/wyrihaximusnet/docker-redirect
icon: https://helm.wyrihaximus.net/images/charts/redirect.png
type: application
version: 0.7.0
version: 0.8.0
kubeVersion: ^1.18
appVersion: random
maintainers:
- name: WyriHaximus
email: [email protected]
dependencies:
- name: cron-jobs
version: ^0.1
repository: https://helm.wyrihaximus.net/
- name: horizontal-pod-autoscalers
version: ^0.2
repository: https://helm.wyrihaximus.net/
5 changes: 5 additions & 0 deletions charts/redirect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ redirect:
# Enable horizontal pod autoscaler
hpa:
enable: true

# Cron job that replaces the oldest pod weekly
cron:
replaceOldestPodWeekly: false
```
Keep in mind that the configuration options are executed in the following order:
Expand All @@ -55,4 +59,5 @@ Keep in mind that the configuration options are executed in the following order:
* Prometheus export annotations are added for metric scraping.
* The default tag is random to randomly cycle through the different implementations, here is the [why](https://github.com/WyriHaximusNet/docker-redirect#why).
* Comes with a pod
* Replace oldest pod every week to hook into the weekly random image retagging

3 changes: 3 additions & 0 deletions charts/redirect/ci/single-replica-values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
replicas: 1

cron:
replaceOldestPodWeekly: false

hpa:
enable: true
20 changes: 20 additions & 0 deletions charts/redirect/templates/cronjob-role-binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- if .Values.cron.replaceOldestPodWeekly -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ include ".helm.fullname" . }}-recycle-cronjob
namespace: {{ .Release.Namespace }}
labels:
app: {{ include ".helm.fullname" . }}
appRevision: {{ template ".helm.nameRevision" . }}
release: {{ include ".helm.fullname" . }}
releaseRevision: {{ .Release.Revision | quote }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ include ".helm.fullname" . }}-recycle-cronjob
subjects:
- kind: ServiceAccount
name: {{ include ".helm.fullname" . }}-recycle-cronjob
namespace: {{ .Release.Namespace }}
{{ end }}
16 changes: 16 additions & 0 deletions charts/redirect/templates/cronjob-role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.cron.replaceOldestPodWeekly -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ include ".helm.fullname" . }}-recycle-cronjob
namespace: {{ .Release.Namespace }}
labels:
app: {{ include ".helm.fullname" . }}
appRevision: {{ template ".helm.nameRevision" . }}
release: {{ include ".helm.fullname" . }}
releaseRevision: {{ .Release.Revision | quote }}
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["list", "delete"]
{{ end }}
13 changes: 13 additions & 0 deletions charts/redirect/templates/cronjob-service-account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.cron.replaceOldestPodWeekly -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include ".helm.fullname" . }}-recycle-cronjob
namespace: {{ .Release.Namespace }}
labels:
app: {{ include ".helm.fullname" . }}
appRevision: {{ template ".helm.nameRevision" . }}
release: {{ include ".helm.fullname" . }}
releaseRevision: {{ .Release.Revision | quote }}
{{- include ".helm.labels" . | nindent 4 }}
{{ end }}
3 changes: 3 additions & 0 deletions charts/redirect/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- if .Values.cron.replaceOldestPodWeekly -}}
{{- include "cron-jobs.cronjob" (fromYaml (.Files.Get "values/cronjob.yaml" | replace "[[fullname]]" (include ".helm.fullname" .) | replace "[[app]]" (include ".helm.name" .) | replace "[[release]]" .Release.Name | replace "[[namespace]]" .Release.Namespace)) -}}
{{ end }}
3 changes: 3 additions & 0 deletions charts/redirect/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ grafana:

replicas: 2

cron:
replaceOldestPodWeekly: false

hpa:
enable: false
maxReplicas: 1024
Expand Down
19 changes: 19 additions & 0 deletions charts/redirect/values/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: replace-oldest-pod-in-deployment
schedule: "0 0 * * 1"
container:
command:
- /bin/sh
args:
- -c
- kubectl delete pod $(kubectl get pods --selector=app=[[app]] --selector=release=[[release]] -n [[namespace]] --sort-by=.status.startTime --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | head -n 1) -n [[namespace]]
image:
repository: bitnami/kubectl
tag: 1.19
pullPolicy: IfNotPresent
spec:
serviceAccountName: [[fullname]]-recycle-cronjob
labels:
cronjob:
purpose: housekeeping
jobTemplate:
purpose: housekeeping

0 comments on commit 7e72917

Please sign in to comment.