-
-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR introduces a sidecar container to each deployment using the DSN mechanism. It allows setting a watcher for a mounted file, and restarting the deployment upon changes in the file. This uses inotify-tools, which report upon file changes. In this case we are operating with k8s volumes, which are mounted in some location and symlinked into the desired location. Change to the original file (so unmount and remount) causes the symlink to be deleted and recreated. In some cases this can break the program (f.e if the mounted file is a secret/certificate used by DSN) requiring a restart.
- Loading branch information
1 parent
0fc5506
commit 1103402
Showing
14 changed files
with
280 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
set -eu | ||
|
||
function rollOut() { | ||
DEPLOY=$(kubectl get deploy -n "${NAMESPACE}" -l "${1}" -o name) | ||
kubectl set env -n $NAMESPACE ${DEPLOY} sync=$(date "+%Y%m%d-%H%M%S") | ||
kubectl rollout status -n $NAMESPACE ${DEPLOY} | ||
} | ||
|
||
inotifywait -e DELETE_SELF -m "${WATCH_FILE}" | | ||
while read path _ file; do | ||
echo "---> $path$file modified" | ||
rollOut "${DEPLOYMENT_SELECTOR}" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: {{ include "hydra.fullname" . }} | ||
labels: | ||
{{- include "hydra.labels" . | nindent 4 }} | ||
|
||
{{- if .Values.watcher.enabled }} | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: {{ include "hydra.fullname" . }}-watcher | ||
namespace: {{ .Release.Namespace }} | ||
rules: | ||
- apiGroups: ["apps"] | ||
resources: ["deployments"] | ||
verbs: ["list", "watch"] | ||
- apiGroups: ["apps"] | ||
resources: ["deployments"] | ||
verbs: ["list", "patch", "get", "watch"] | ||
resourceNames: | ||
- {{ include "hydra.fullname" . }} | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: {{ include "hydra.fullname" . }}-watcher | ||
namespace: {{ .Release.Namespace }} | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: {{ include "hydra.fullname" . }}-watcher | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ include "hydra.fullname" . }} | ||
namespace: {{ .Release.Namespace }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
set -eu | ||
|
||
function rollOut() { | ||
DEPLOY=$(kubectl get deploy -n "${NAMESPACE}" -l "${1}" -o name) | ||
kubectl set env -n $NAMESPACE ${DEPLOY} sync=$(date "+%Y%m%d-%H%M%S") | ||
kubectl rollout status -n $NAMESPACE ${DEPLOY} | ||
} | ||
|
||
inotifywait -e DELETE_SELF -m "${WATCH_FILE}" | | ||
while read path _ file; do | ||
echo "---> $path$file modified" | ||
rollOut "${DEPLOYMENT_SELECTOR}" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{{- if .Values.serviceAccount.create -}} | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: {{ include "keto.serviceAccountName" . }} | ||
labels: | ||
{{- include "keto.labels" . | nindent 4 }} | ||
{{- with .Values.serviceAccount.annotations }} | ||
annotations: | ||
{{- toYaml . | nindent 4 }} | ||
{{- end }} | ||
|
||
{{- if .Values.watcher.enabled }} | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: {{ include "keto.fullname" . }}-watcher | ||
namespace: {{ .Release.Namespace }} | ||
rules: | ||
- apiGroups: ["apps"] | ||
resources: ["deployments"] | ||
verbs: ["list", "watch"] | ||
- apiGroups: ["apps"] | ||
resources: ["deployments"] | ||
verbs: ["list", "patch", "get", "watch"] | ||
resourceNames: | ||
- {{ include "keto.fullname" . }} | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: {{ include "keto.fullname" . }}-watcher | ||
namespace: {{ .Release.Namespace }} | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: {{ include "keto.fullname" . }}-watcher | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ include "keto.serviceAccountName" . }} | ||
namespace: {{ .Release.Namespace }} | ||
{{- end }} | ||
|
||
{{- end }} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
set -eu | ||
|
||
function rollOut() { | ||
DEPLOY=$(kubectl get deploy -n "${NAMESPACE}" -l "${1}" -o name) | ||
kubectl set env -n $NAMESPACE ${DEPLOY} sync=$(date "+%Y%m%d-%H%M%S") | ||
kubectl rollout status -n $NAMESPACE ${DEPLOY} | ||
} | ||
|
||
inotifywait -e DELETE_SELF -m "${WATCH_FILE}" | | ||
while read path _ file; do | ||
echo "---> $path$file modified" | ||
rollOut "${DEPLOYMENT_SELECTOR}" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: {{ include "kratos.fullname" . }} | ||
labels: | ||
{{- include "kratos.labels" . | nindent 4 }} | ||
|
||
{{- if .Values.watcher.enabled }} | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: {{ include "kratos.fullname" . }}-watcher | ||
namespace: {{ .Release.Namespace }} | ||
rules: | ||
- apiGroups: ["apps"] | ||
resources: ["deployments"] | ||
verbs: ["list", "watch"] | ||
- apiGroups: ["apps"] | ||
resources: ["deployments"] | ||
verbs: ["list", "patch", "get", "watch"] | ||
resourceNames: | ||
- {{ include "kratos.fullname" . }} | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: {{ include "kratos.fullname" . }}-watcher | ||
namespace: {{ .Release.Namespace }} | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: {{ include "kratos.fullname" . }}-watcher | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ include "kratos.fullname" . }} | ||
namespace: {{ .Release.Namespace }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters