mirror of
https://github.com/tektoncd/catalog.git
synced 2024-11-21 05:55:35 +00:00
Go back to appending sidecars with python
- Check for libraries in a pip agnostic way - allow for adding multiple sidecars with a reusable `add_sidecars` function - fix overwriting sidecars issue for previous python - make it more readable
This commit is contained in:
parent
686f9ca027
commit
442e379fd6
@ -42,21 +42,51 @@ function require_command() {
|
||||
fi
|
||||
}
|
||||
|
||||
require_command ${KUBECTL_CMD}
|
||||
require_command ${KUBECTL_CMD} python3
|
||||
|
||||
## Python Modules
|
||||
|
||||
function require_python_module() {
|
||||
for arg in "$@"; do
|
||||
if ! python3 -c "import ${arg}" &> /dev/null;then
|
||||
echo "required 'python3' module '${arg}' not be found"
|
||||
echo "NOTE: the library name may be different but you you can try installing it via 'python3 -m pip install ${arg}'"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
require_python_module yaml
|
||||
|
||||
source $(dirname $0)/../vendor/github.com/tektoncd/plumbing/scripts/e2e-tests.sh
|
||||
|
||||
# Add sidecar resources, first argument is the file
|
||||
# following arguments are string formed json/yaml processed by yaml.safe_load
|
||||
# e.g. '{"image": "registry", "name": "registry"}'
|
||||
function add_sidecars() {
|
||||
cp ${1} ${TMPF}.read
|
||||
SCRIPT='
|
||||
import sys, yaml
|
||||
|
||||
f=open(0, encoding="utf-8")
|
||||
data=yaml.load(f.read(), Loader=yaml.FullLoader)
|
||||
|
||||
sidecars = map(lambda v: yaml.safe_load(v), sys.argv[1:]) # after -c
|
||||
for sidecar in sidecars:
|
||||
if "sidecars" in data["spec"]:
|
||||
data["spec"]["sidecars"].append(sidecar)
|
||||
else:
|
||||
data["spec"]["sidecars"] = [sidecar]
|
||||
print(yaml.dump(data, default_flow_style=False))
|
||||
'
|
||||
cat ${TMPF}.read | python3 -c "$SCRIPT" "${@:2}" > ${TMPF}
|
||||
rm -f ${TMPF}.read
|
||||
}
|
||||
|
||||
# Add an internal registry as sidecar to a task so we can upload it directly
|
||||
# from our tests withouth having to go to an external registry.
|
||||
function add_sidecar_registry() {
|
||||
cp ${1} ${TMPF}.read
|
||||
|
||||
cat ${TMPF}.read | sed -E 's/spec:/spec:\
|
||||
sidecars:\
|
||||
- image: registry\
|
||||
name: registry/' > ${TMPF}
|
||||
|
||||
rm -f ${TMPF}.read
|
||||
add_sidecars ${1} '{"image":"registry", "name": "registry"}'
|
||||
}
|
||||
|
||||
function add_task() {
|
||||
|
Loading…
Reference in New Issue
Block a user