Skip to content

Instantly share code, notes, and snippets.

@skorski
Created December 16, 2017 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skorski/c1d09b65a28c0536b19c12e5f8148c69 to your computer and use it in GitHub Desktop.
Save skorski/c1d09b65a28c0536b19c12e5f8148c69 to your computer and use it in GitHub Desktop.
statefulContainers
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: nifi-example
labels:
app: nifi
spec:
replicas: 1
template:
metadata:
labels:
app: nifi
spec:
initContainers:
- name: init-nifi
image: mkobit/nifi:latest
securityContext:
runAsUser: 0
command:
- /bin/bash
- -ec
- |
apt-get update; apt-get install rsync -y
BOOTSTRAP_DIR=${BOOTSTRAP_DIR:-/opt/nifi/}
OUTPUT_DIR=${OUTPUT_DIR:-/tmp/}
INPUT_TIME=$(find ${BOOTSTRAP_DIR} -type f | xargs stat --format '%Y' 2>/dev/null | sort -nr | head -n1)
OUTPUT_TIME=$(find ${OUTPUT_DIR} -type f | xargs stat --format '%Y' 2>/dev/null | sort -nr | head -n1)
echo IN:${INPUT_TIME} OUT:${OUTPUT_TIME}
if [[ ${INPUT_TIME} -gt 0 ]] || [[ ${OUTPUT_TIME} -gt 0 ]]
then
if [[ ${INPUT_TIME} -eq ${OUTPUT_TIME} ]]
then
echo "File times match. Skipping Rsync"
else
if [[ ${INPUT_TIME} -gt ${OUTPUT_TIME} ]]
then
echo "Input should be copied to output"
rsync -razh ${BOOTSTRAP_DIR} ${OUTPUT_DIR}
echo copied based on rsync -razh ${BOOTSTRAP_DIR} ${OUTPUT_DIR}
fi
if [[ ${INPUT_TIME} -lt ${OUTPUT_TIME} ]]
then
echo "output should be copied to input"
rsync -razh ${OUTPUT_DIR} ${BOOTSTRAP_DIR}
echo copied based on rsync -razh ${OUTPUT_DIR} ${BOOTSTRAP_DIR}
fi
fi
else
echo "No files found"
fi
echo "file staging is done"
volumeMounts:
- name: nifi-backup
mountPath: /tmp
terminationGracePeriodSeconds: 30
containers:
- name: nifi
image: mkobit/nifi:latest
securityContext:
runAsUser: 0
volumeMounts:
- name: nifi-backup
mountPath: /opt/nifi
volumes:
- name: nifi-backup
persistentVolumeClaim:
claimName: nifi-conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment