Skip to content

Commit

Permalink
chore: update prometheus crd patch script
Browse files Browse the repository at this point in the history
This commit updates the patch script to use a docker image as the
previous code did not run on OSX.

Also, due to the underlying go-parser lib used in the yq docker image,
updating a yaml file automatically reformats the yaml removing empty
newlines and converting multiline strings into one line[1]. This makes
it hard to see the actual needed change for patch7 which is just to
update the crd volumeClaimTemplate.metadata stanza.

Thus, patch7 is changed to apply two commits, one to simply let yq
format the file with no new changes and a second commit with the needed
change. Similar to what we do with chart revision changes.

Also updated the helper script to accept a commit message.

[1] mikefarah/yq#465 (comment)

Signed-off-by: Sam Tran <[email protected]>
  • Loading branch information
samvantran committed Aug 17, 2020
1 parent 3f0c921 commit 8a2c2d7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
10 changes: 9 additions & 1 deletion staging/prometheus-operator/patch/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ function git_add_and_commit {
FILES_PATH=$1
git add ${FILES_PATH}
FILENAME=$(basename "$0")
git commit -m "Apply ${FILENAME}"
git commit -m "chore: apply ${FILENAME}"
}

function git_add_and_commit_with_msg {
FILES_PATH=$1
MSG=$2
git add ${FILES_PATH}
FILENAME=$(basename "$0")
git commit -m "chore: apply ${FILENAME} - ${MSG}"
}

29 changes: 25 additions & 4 deletions staging/prometheus-operator/patch/patch_7_prometheus_crd.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
#!/bin/bash

source $(dirname "$0")/helpers.sh

set -x

if [[ -z $(command -v yq) ]]; then
echo "$0 requires the 'yq' command line tool which is not installed. Please install this and start again."
exit 1
fi

SRCFILE="${BASEDIR}/crds/crd-prometheus.yaml"
TMPFILE=$(mktemp)
yq -y '.spec.validation.openAPIV3Schema.properties.spec.properties.storage.properties.volumeClaimTemplate.properties.metadata.properties.name = {"description": "Name is the name used in the PVC claim", "type": "string"}' ${SRCFILE} >> ${TMPFILE}
mv ${TMPFILE} ${SRCFILE}
SRCFILE=crds/crd-prometheus.yaml
TMPFILE=crds/tmp-prom.yaml

docker run --rm -it \
-v ${BASEDIR}:/basedir \
-w /basedir \
-e SRCFILE=${SRCFILE} \
-e TMPFILE=${TMPFILE} \
mikefarah/yq:3.3.2 \
yq read -P "${SRCFILE}" > "${TMPFILE}" && mv "${TMPFILE}" "${SRCFILE}"

git_add_and_commit_with_msg ${SRCFILE} "reformat yaml with yq"

docker run --rm -it \
-v ${BASEDIR}:/basedir \
-w /basedir \
-e SRCFILE=${SRCFILE} \
-e TMPFILE=${TMPFILE} \
mikefarah/yq:3.3.2 \
yq write -i "${SRCFILE}" spec.validation.openAPIV3Schema.properties.spec.properties.storage.properties.volumeClaimTemplate.properties.metadata.properties.name.description "Name is the name used in the PVC claim" && \
yq write -i "${SRCFILE}" spec.validation.openAPIV3Schema.properties.spec.properties.storage.properties.volumeClaimTemplate.properties.metadata.properties.name.type "string"

git_add_and_commit_with_msg ${SRCFILE} "update volumeClaimTemplate"

0 comments on commit 8a2c2d7

Please sign in to comment.