Skip to content

Commit

Permalink
fix(RELEASE-916): apply-mapping uses data file, not rpa (#416)
Browse files Browse the repository at this point in the history
This commit updates the apply-mapping task to read the mapping from the
data json file instead of from the ReleasePlanAdmission json file.

Signed-off-by: Johnny Bieren <[email protected]>
  • Loading branch information
johnbieren authored May 20, 2024
1 parent 4b37100 commit 7683e35
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 364 deletions.
3 changes: 3 additions & 0 deletions pipelines/push-to-external-registry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Tekton pipeline to release Snapshots to an external registry.
| taskGitUrl | The url to the git repo where the release-service-catalog tasks to be used are stored | Yes | https://github.com/konflux-ci/release-service-catalog.git |
| taskGitRevision | The revision in the taskGitUrl repo to be used | No | - |

## Changes in 4.4.0
- The apply-mapping task now gets the dataPath parameter instead of releasePlanAdmissionPath

## Changes in 4.3.0
- `enterpriseContractExtraRuleData` added as a pipeline parameter, which is
then passed to EC. Allows for easier runtime changes to rule data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Pipeline
metadata:
name: push-to-external-registry
labels:
app.kubernetes.io/version: "4.3.0"
app.kubernetes.io/version: "4.4.0"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: release
Expand Down Expand Up @@ -158,8 +158,8 @@ spec:
params:
- name: failOnEmptyResult
value: "true"
- name: releasePlanAdmissionPath
value: "$(tasks.collect-data.results.releasePlanAdmission)"
- name: dataPath
value: "$(tasks.collect-data.results.data)"
- name: snapshotPath
value: "$(tasks.collect-data.results.snapshotSpec)"
workspaces:
Expand Down
5 changes: 4 additions & 1 deletion pipelines/rh-advisories/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ the rh-push-to-registry-redhat-io pipeline.
| taskGitUrl | The url to the git repo where the release-service-catalog tasks to be used are stored | Yes | https://github.com/konflux-ci/release-service-catalog.git |
| taskGitRevision | The revision in the taskGitUrl repo to be used | No | - |

## Changes in 0.7.0
- The apply-mapping task now gets the dataPath parameter instead of releasePlanAdmissionPath

## Changes in 0.6.0
* - `enterpriseContractExtraRuleData` added as a pipeline parameter, which is
- `enterpriseContractExtraRuleData` added as a pipeline parameter, which is
then passed to EC. Allows for easier runtime changes to rule data.

## Changes in 0.5.1
Expand Down
6 changes: 3 additions & 3 deletions pipelines/rh-advisories/rh-advisories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Pipeline
metadata:
name: rh-advisories
labels:
app.kubernetes.io/version: "0.6.0"
app.kubernetes.io/version: "0.7.0"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: release
Expand Down Expand Up @@ -189,8 +189,8 @@ spec:
params:
- name: failOnEmptyResult
value: "true"
- name: releasePlanAdmissionPath
value: "$(tasks.collect-data.results.releasePlanAdmission)"
- name: dataPath
value: "$(tasks.collect-data.results.data)"
- name: snapshotPath
value: "$(tasks.collect-data.results.snapshotSpec)"
workspaces:
Expand Down
5 changes: 4 additions & 1 deletion pipelines/rh-push-to-external-registry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ Tekton pipeline to release Red Hat Snapshots to an external registry. This pipel
| taskGitUrl | The url to the git repo where the release-service-catalog tasks to be used are stored | Yes | https://github.com/konflux-ci/release-service-catalog.git |
| taskGitRevision | The revision in the taskGitUrl repo to be used | No | - |

## Changes in 4.5.0
- The apply-mapping task now gets the dataPath parameter instead of releasePlanAdmissionPath

## Changes in 4.4.0
* - `enterpriseContractExtraRuleData` added as a pipeline parameter, which is
- `enterpriseContractExtraRuleData` added as a pipeline parameter, which is
then passed to EC. Allows for easier runtime changes to rule data.

## Changes in 4.3.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Pipeline
metadata:
name: rh-push-to-external-registry
labels:
app.kubernetes.io/version: "4.4.0"
app.kubernetes.io/version: "4.5.0"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: release
Expand Down Expand Up @@ -158,8 +158,8 @@ spec:
params:
- name: failOnEmptyResult
value: "true"
- name: releasePlanAdmissionPath
value: "$(tasks.collect-data.results.releasePlanAdmission)"
- name: dataPath
value: "$(tasks.collect-data.results.data)"
- name: snapshotPath
value: "$(tasks.collect-data.results.snapshotSpec)"
workspaces:
Expand Down
5 changes: 4 additions & 1 deletion pipelines/rh-push-to-registry-redhat-io/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ Tekton pipeline to release content to registry.redhat.io registry.
| taskGitUrl | The url to the git repo where the release-service-catalog tasks to be used are stored | Yes | https://github.com/konflux-ci/release-service-catalog.git |
| taskGitRevision | The revision in the taskGitUrl repo to be used | No | - |

## Changes in 3.5.0
* The apply-mapping task now gets the dataPath parameter instead of releasePlanAdmissionPath

## Changes in 3.4.0
* - `enterpriseContractExtraRuleData` added as a pipeline parameter, which is
* `enterpriseContractExtraRuleData` added as a pipeline parameter, which is
then passed to EC. Allows for easier runtime changes to rule data.

## Changes in 3.3.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Pipeline
metadata:
name: rh-push-to-registry-redhat-io
labels:
app.kubernetes.io/version: "3.4.0"
app.kubernetes.io/version: "3.5.0"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: release
Expand Down Expand Up @@ -185,8 +185,8 @@ spec:
params:
- name: failOnEmptyResult
value: "true"
- name: releasePlanAdmissionPath
value: "$(tasks.collect-data.results.releasePlanAdmission)"
- name: dataPath
value: "$(tasks.collect-data.results.data)"
- name: snapshotPath
value: "$(tasks.collect-data.results.snapshotSpec)"
workspaces:
Expand Down
5 changes: 4 additions & 1 deletion pipelines/rhtap-service-push/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
| taskGitUrl | The url to the git repo where the release-service-catalog tasks to be used are stored | Yes | https://github.com/konflux-ci/release-service-catalog.git |
| taskGitRevision | The revision in the taskGitUrl repo to be used | No | - |

## Changes in 3.5.0
- The apply-mapping task now gets the dataPath parameter instead of releasePlanAdmissionPath

## Changes in 3.4.0
* - `enterpriseContractExtraRuleData` added as a pipeline parameter, which is
- `enterpriseContractExtraRuleData` added as a pipeline parameter, which is
then passed to EC. Allows for easier runtime changes to rule data.

## Changes in 3.3.0
Expand Down
6 changes: 3 additions & 3 deletions pipelines/rhtap-service-push/rhtap-service-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Pipeline
metadata:
name: rhtap-service-push
labels:
app.kubernetes.io/version: "3.4.0"
app.kubernetes.io/version: "3.5.0"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: release
Expand Down Expand Up @@ -158,8 +158,8 @@ spec:
params:
- name: failOnEmptyResult
value: "true"
- name: releasePlanAdmissionPath
value: "$(tasks.collect-data.results.releasePlanAdmission)"
- name: dataPath
value: "$(tasks.collect-data.results.data)"
- name: snapshotPath
value: "$(tasks.collect-data.results.snapshotSpec)"
workspaces:
Expand Down
6 changes: 5 additions & 1 deletion tasks/apply-mapping/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ This task supports variable expansion in tag values from the mapping. The curren
| Name | Description | Optional | Default value |
|------|-------------|----------|---------------|
| snapshotPath | Path to the JSON string of the Snapshot spec in the config workspace to apply the mapping to | No | |
| releasePlanAdmissionPath | Path to the JSON string of the ReleasePlanAdmission in the config workspace which contains the mapping to apply | No | |
| 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.0.0
* Use the data json instead of the ReleasePlanAdmission json
* releasePlanAdmissionPath parameter removed in favor of dataPath parameter

## Changes in 0.11.0
* The tags provided in `mapping.defaults.tags` are combined with each components `.tags` entry to form
one set of tags
Expand Down
22 changes: 10 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: "0.11.0"
app.kubernetes.io/version: "1.0.0"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: release
Expand All @@ -15,11 +15,9 @@ spec:
- name: snapshotPath
type: string
description: Path to the JSON string of the Snapshot spec in the config workspace to apply the mapping to
- name: releasePlanAdmissionPath
- name: dataPath
type: string
description: |
Path to the JSON string of the ReleasePlanAdmission in the
config workspace which contains the mapping to apply
description: Path to the JSON string of the merged data to use in the data workspace
- name: failOnEmptyResult
type: string
description: Fail the task if the resulting snapshot contains 0 components
Expand All @@ -40,7 +38,7 @@ spec:
set -eux
SNAPSHOT_SPEC_FILE="$(workspaces.config.path)/$(params.snapshotPath)"
RPA_FILE="$(workspaces.config.path)/$(params.releasePlanAdmissionPath)"
DATA_FILE="$(workspaces.config.path)/$(params.dataPath)"
SNAPSHOT_SPEC_FILE_ORIG="${SNAPSHOT_SPEC_FILE}.orig"
if [ ! -f "${SNAPSHOT_SPEC_FILE}" ] ; then
Expand All @@ -51,16 +49,16 @@ spec:
# Copy the original Snapshot spec file before overriding
cp "${SNAPSHOT_SPEC_FILE}" "${SNAPSHOT_SPEC_FILE_ORIG}"
if [ ! -f "${RPA_FILE}" ] ; then
echo "No ReleasePlanAdmission file was found."
if [ ! -f "${DATA_FILE}" ] ; then
echo "No data JSON file was found."
printf "false" | tee $(results.mapped.path)
exit 0
fi
MAPPING=$(jq '.spec.data.mapping' "${RPA_FILE}")
MAPPING=$(jq '.mapping' "${DATA_FILE}")
if [[ $MAPPING == "null" ]] ; then
echo "ReleasePlanAdmission Data struct contains no mapping key."
echo "Data file contains no mapping key."
printf "false" | tee $(results.mapped.path)
exit 0
fi
Expand Down Expand Up @@ -95,7 +93,7 @@ spec:
echo -n $tags | jq -c
}
# Merge the mapping key contents in the ReleasePlanAdmission data with the components key in the snapshot based
# Merge the mapping key contents in the data json file with the components key in the snapshot based
# on component name. Save the output as a compact json in mapped_snapshot.json file in the workspace
{ echo -n $(cat "${SNAPSHOT_SPEC_FILE_ORIG}"); echo "${MAPPING}"; } | jq -c -s '.[0] as $snapshot
| .[0].components + .[1].components | group_by(.name) | [.[] | select(length > 1)]
Expand All @@ -111,7 +109,7 @@ spec:
exit 1
fi
# Expand the tags in the ReleasePlanAdmission
# Expand the tags in the data file
defaultTags=$(jq '.defaults.tags' <<< $MAPPING)
defaultTimestampFormat=$(jq -r '.defaults.timestampFormat // "%s"' <<< $MAPPING)
currentTimestamp="$(date "+%Y%m%d %T")"
Expand Down
65 changes: 16 additions & 49 deletions tasks/apply-mapping/tests/test-apply-mapping-fail-on-empty.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ metadata:
test/assert-task-failure: "run-task"
spec:
description: |
Run the apply-mapping task with a snapshot.spec json and ReleasePlanAdmission
mapping that results in empty component list. Set task parameter failOnEmptyResult
to true and verify that the task fails as expected.
Run the apply-mapping task with a snapshot.spec json and data json mapping that
results in empty component list. Set task parameter failOnEmptyResult to true
and verify that the task fails as expected.
workspaces:
- name: tests-workspace
tasks:
Expand All @@ -29,52 +29,19 @@ spec:
#!/usr/bin/env sh
set -eux
cat > $(workspaces.config.path)/release_plan_admission.json << EOF
cat > $(workspaces.config.path)/data.json << EOF
{
"apiVersion": "appstudio.redhat.com/v1alpha1",
"kind": "ReleasePlanAdmission",
"metadata": {
"name": "test",
"namespace": "managed"
},
"spec": {
"applications": [
"app"
],
"policy": "policy",
"pipelineRef": {
"resolver": "git",
"params": [
{
"name": "url",
"value": "github.com"
},
{
"name": "revision",
"value": "main"
},
{
"name": "pathInRepo",
"value": "pipeline.yaml"
}
]
},
"serviceAccount": "sa",
"origin": "dev",
"data": {
"mapping": {
"components": [
{
"name": "comp3",
"repository": "repo3"
},
{
"name": "comp4",
"customfield": "repo4"
}
]
"mapping": {
"components": [
{
"name": "comp3",
"repository": "repo3"
},
{
"name": "comp4",
"customfield": "repo4"
}
}
]
}
}
EOF
Expand Down Expand Up @@ -105,8 +72,8 @@ spec:
params:
- name: snapshotPath
value: "snapshot_spec.json"
- name: releasePlanAdmissionPath
value: "release_plan_admission.json"
- name: dataPath
value: "data.json"
- name: failOnEmptyResult
value: "true"
workspaces:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: test-apply-mapping-no-rpa
name: test-apply-mapping-no-data-file
spec:
description: |
Run the apply-mapping with a basic snapshot.spec json without a ReleasePlanAdmission
Run the apply-mapping with a basic snapshot.spec json without a data json file
provided and verify that the returned json is the same as the one in the input.
workspaces:
- name: tests-workspace
Expand Down Expand Up @@ -57,7 +57,7 @@ spec:
params:
- name: snapshotPath
value: snapshot_spec.json
- name: releasePlanAdmissionPath
- name: dataPath
value: ""
workspaces:
- name: config
Expand Down
Loading

0 comments on commit 7683e35

Please sign in to comment.