From e94e9f55d2d8d542aee1d616363a28c8f4e186b8 Mon Sep 17 00:00:00 2001 From: James Andariese Date: Tue, 17 Oct 2023 00:27:06 -0500 Subject: [PATCH] shorten the name of the job considerably. this will allow for repos that have names much longer than before since a job's name can only be up to 63 characters long and the distinguishing name of the job was taking up 51 of those. --- git-remote-k8s.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/git-remote-k8s.sh b/git-remote-k8s.sh index 9d98662..c9c198d 100755 --- a/git-remote-k8s.sh +++ b/git-remote-k8s.sh @@ -23,7 +23,7 @@ export IMAGE=alpine/git:latest export CONTEXT="$(echo "${2#*://}" | cut -d / -f 1)" export NS="$(echo "${2#*://}" | cut -d / -f 2)" export REPO="$(echo "${2#*://}" | cut -d / -f 3)" -export RUNID="$(uuid)" +export RUNID="$(dd if=/dev/random bs=600 count=1 status=none | base64 | tr -dc a-z0-9 | cut -c 1-6)" while read -r cmd arg rest; do case "$cmd" in @@ -53,6 +53,7 @@ read echo $SUBCOMMAND " +# if you named your pod FILTERME_HFOIQJF, I apologize echo ' --- @@ -67,13 +68,13 @@ spec: resources: requests: storage: 1Gi - storageClassName: longhorn + storageClassName: ${GIT_REMOTE_K8S_STORAGECLASS-FILTERME_HFOIQJF} volumeMode: Filesystem --- apiVersion: batch/v1 kind: Job metadata: - name: ${REPO}-git-connector-${RUNID} + name: ${REPO}-gitc${RUNID} namespace: ${NS} labels: git.kn8v.com/runid: ${RUNID} @@ -98,18 +99,19 @@ spec: persistentVolumeClaim: claimName: ${REPO} restartPolicy: Never -' | yq ea '(.. | select(tag == "!!str")) |= envsubst' | kubectl --context "$CONTEXT" apply -f - 1>&2 +' | grep -v FILTERME_HFOIQJF | yq ea '(.. | select(tag == "!!str")) |= envsubst' | kubectl --context "$CONTEXT" apply -f - 1>&2 + KILLLOGS=: finalize() { - kubectl --context "$CONTEXT" delete job -n "$NS" "${REPO}-git-connector-${RUNID}" 1>&2 + kubectl --context "$CONTEXT" delete job -n "$NS" "${REPO}-gitc${RUNID}" 1>&2 $KILLLOGS exit # must exit for INT and TERM. } trap finalize INT TERM -kubectl --context "$CONTEXT" wait job "${REPO}-git-connector-${RUNID}" --for jsonpath=.status.ready=1 1>&2 -(echo;cat) | kubectl --context "$CONTEXT" attach -i -q -n "$NS" "job/${REPO}-git-connector-${RUNID}" +kubectl --context "$CONTEXT" wait job "${REPO}-gitc${RUNID}" --for jsonpath=.status.ready=1 1>&2 +(echo;cat) | kubectl --context "$CONTEXT" attach -i -q -n "$NS" "job/${REPO}-gitc${RUNID}" # also finalize on exit finalize