Skip to content

Commit

Permalink
fix(RELEASE-993): resolve substitution and incrementer logic issues (#…
Browse files Browse the repository at this point in the history
…709)

Fixes an issue with substitution logic that could
result in incomplete tag replacement

Signed-off-by: Happy Bhati <hbhati@redhat.com>
  • Loading branch information
happybhati authored Nov 25, 2024
1 parent eda4e79 commit aec8790
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
3 changes: 3 additions & 0 deletions tasks/apply-mapping/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ You can also expand image labels, e.g. "{{ labels.mylabel }}" -> The value of im
| dataPath | Path to the JSON string of the merged data to use in the data workspace | No | - |
| failOnEmptyResult | Fail the task if the resulting snapshot contains zero components | Yes | false |

## Changes in 1.8.1
* Fixed substitution logic to prevent incomplete replacements in `translate_tags`.

## Changes in 1.8.0
* Enhanced tag generation by adding support for the {{ incrementer }} variable:
* The {{ incrementer }} variable automatically finds the highest existing incremented tag
Expand Down
21 changes: 9 additions & 12 deletions tasks/apply-mapping/apply-mapping.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Task
metadata:
name: apply-mapping
labels:
app.kubernetes.io/version: "1.8.0"
app.kubernetes.io/version: "1.8.1"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: release
Expand Down Expand Up @@ -143,18 +143,15 @@ spec:
tag=$(increment_tag "$tag" "$repo")
else
replacement=$(substitute "$var_name" "$substitute_map" "$labels_map")
tag="${tag//"{{ *$var_name *}}"/$replacement}"
if [ -z "$replacement" ]; then
echo Error: Substitution variable unknown or empty: "$var_name" >&2
exit 1
fi
# Shellcheck suggests ${var//find/replace}, but
# that won't work here - we need to match arbitrary amount of spaces
# shellcheck disable=SC2001
tag="$(sed "s/{{ *$var_name *}}/$replacement/" <<< "$tag")"
fi
if [ -z "$replacement" ]; then
echo Error: Substitution variable unknown or empty: "$var_name" >&2
exit 1
fi
# Shellcheck suggests ${var//find/replace}, but
# that won't work here - we need to match arbitrary amount of spaces
# shellcheck disable=SC2001
tag="$(sed "s/{{ *$var_name *}}/$replacement/" <<< "$tag")"
done
# Sanity check of the resulting tag value
Expand Down

0 comments on commit aec8790

Please sign in to comment.