Skip to content

Commit

Permalink
(Fixes tektoncd#481) prevent e2e-test script from overriding task sid…
Browse files Browse the repository at this point in the history
…ecar

The end to end test attaches a sidecar with a image registry for tasks to push into to. This task is optional and is encouraged to be used for testing. However, the function add_sidecar_registry sets the sidecar registry instead of appending it. Allowing the sidecar-registry to run alongside with other tasks will fix this bug. Also, refactored the python script that manipulate json and yaml payloads in order to increase readability and improve local dev environment. tektoncd#481
  • Loading branch information
popcor255 committed Aug 12, 2020
1 parent 755fed0 commit 1781208
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
5 changes: 2 additions & 3 deletions test/e2e-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ source $(dirname $0)/../vendor/github.com/tektoncd/plumbing/scripts/e2e-tests.sh
# from our tests withouth having to go to an external registry.
function add_sidecar_registry() {
cp ${1} ${TMPF}.read

cat ${TMPF}.read | python3 -c 'import yaml;f=open(0, encoding="utf-8"); data=yaml.load(f.read(), Loader=yaml.FullLoader);data["spec"]["sidecars"]=[{"image":"registry", "name": "registry"}];print(yaml.dump(data, default_flow_style=False));' > ${TMPF}
cat ${TMPF}.read | python3 $(dirname $0)/utils.py add_sidecar_to_yaml_file > ${TMPF}
rm -f ${TMPF}.read
}

Expand All @@ -43,7 +42,7 @@ function install_pipeline_crd() {
if [[ -n ${RELEASE_YAML} ]];then
latestreleaseyaml=${RELEASE_YAML}
else
latestreleaseyaml=$(curl -s https://api.github.com/repos/tektoncd/pipeline/releases|python -c "import sys, json;x=json.load(sys.stdin);ass=x[0]['assets'];print([ x['browser_download_url'] for x in ass if x['name'] == 'release.yaml'][0])")
latestreleaseyaml="https://storage.googleapis.com/tekton-releases/latest/release.yaml,"
fi
[[ -z ${latestreleaseyaml} ]] && fail_test "Could not get latest released release.yaml"
kubectl apply -f ${latestreleaseyaml} ||
Expand Down
2 changes: 1 addition & 1 deletion test/e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ TEST_YAML_IGNORES=${TEST_YAML_IGNORES:-""}

# Allow ignoring some yaml tests, space separated, should be the basename of the
# test for example "s2i"
TEST_TASKRUN_IGNORES=${TEST_TASKRUN_IGNORES:-"docker-build"}
TEST_TASKRUN_IGNORES=${TEST_TASKRUN_IGNORES:-""}

set -ex
set -o pipefail
Expand Down
19 changes: 19 additions & 0 deletions test/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys
import yaml
import json

def add_sidecar_to_yaml_file():
# This function is expecting a tekton task from stdin
with sys.stdin as file:
# Load yaml file passed by stdin
payload = yaml.load(file, Loader=yaml.FullLoader)
# If sidecars doesnt have any entries create an array for payload manipulation
if 'sidecars' not in payload['spec']:
payload['spec']['sidecars'] = []
# Append the local image registry to the yaml file
payload['spec']['sidecars'].append({"image": "registry", "name": "registry"})
# Dump the changes to the stdout
print(yaml.dump(payload, default_flow_style=False))

if __name__ == '__main__':
globals()[sys.argv[1]]()

0 comments on commit 1781208

Please sign in to comment.