Skip to content

Commit

Permalink
feat: make collectors pipeline more generic (#635)
Browse files Browse the repository at this point in the history
The new implementation allows to pass either a ReleasePlan
or a ReleasePlanAdmission.

Signed-off-by: David Moreno García <damoreno@redhat.com>
  • Loading branch information
davidmogar authored Oct 30, 2024
1 parent 7baa615 commit a1aabe7
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 574 deletions.
19 changes: 11 additions & 8 deletions pipelines/run-collectors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ save the required resources to the workspace, execute the collectors, then updat

## Parameters

| Name | Description | Optional | Default value |
|----------------------|-------------------------------------------------------------------------------------------------------------------|----------|-----------------------------------------------------------|
| release | The namespaced name (namespace/name) of the Release custom resource initiating this pipeline execution | No | - |
| previousRelease | The namespaced name (namespace/name) of the previous successful Release prior to the one passed as params.release | No | - |
| releasePlan | The namespaced name (namespace/name) of the releasePlan | No | - |
| releasePlanAdmission | The namespaced name (namespace/name) of the releasePlanAdmission | No | - |
| 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 | - |
| Name | Description | Optional | Default value |
|------------------------|-------------------------------------------------------------------------------------------------------------------|----------|-----------------------------------------------------------|
| release | The namespaced name (namespace/name) of the Release custom resource initiating this pipeline execution | No | - |
| previousRelease | The namespaced name (namespace/name) of the previous successful Release prior to the one passed as params.release | No | - |
| collectorsResourceType | The type of resource that contains the collectors | No | - |
| collectorsResource | The namespaced name of the resource that contains the collectors | No | - |
| 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.2.0
* Stop passing releasePlan and releasePlanAdmission and pass instead a reference to a resource
28 changes: 15 additions & 13 deletions pipelines/run-collectors/run-collectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Pipeline
metadata:
name: run-collectors
labels:
app.kubernetes.io/version: "0.1.0"
app.kubernetes.io/version: "0.2.0"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: release
Expand All @@ -23,12 +23,14 @@ spec:
description: >-
The namespaced name (namespace/name) of the previous successful Release prior to the one
passed as params.release
- name: releasePlan
- name: collectorsResourceType
description: The type of resource that contains the collectors
type: string
description: The namespaced name (namespace/name) of the releasePlan
- name: releasePlanAdmission
default: releaseplan
- name: collectorsResource
description: |
The namespaced name of the resource that contains the collectors
type: string
description: The namespaced name (namespace/name) of the releasePlanAdmission
- name: taskGitUrl
type: string
description: The url to the git repo where the release-service-catalog tasks to be used are stored
Expand All @@ -54,10 +56,10 @@ spec:
value: $(params.previousRelease)
- name: release
value: $(params.release)
- name: releasePlan
value: $(params.releasePlan)
- name: releasePlanAdmission
value: $(params.releasePlanAdmission)
- name: collectorsResourceType
value: $(params.collectorsResourceType)
- name: collectorsResource
value: $(params.collectorsResource)
- name: subdirectory
value: $(context.pipelineRun.uid)
workspaces:
Expand All @@ -74,10 +76,10 @@ spec:
- name: pathInRepo
value: tasks/run-collectors/run-collectors.yaml
params:
- name: releasePlan
value: $(tasks.collect-collectors-resources.results.releasePlan)
- name: releasePlanAdmission
value: $(tasks.collect-collectors-resources.results.releasePlanAdmission)
- name: collectorsPath
value: $(tasks.collect-collectors-resources.results.collectorsResource)
- name: collectorsResourceType
value: $(params.collectorsResourceType)
- name: resultsDir
value: $(tasks.collect-collectors-resources.results.resultsDir)
workspaces:
Expand Down
17 changes: 10 additions & 7 deletions tasks/collect-collectors-resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ A task result is returned for each resource with the relative path to the stored

## Parameters

| Name | Description | Optional | Default value |
|----------------------|----------------------------------------------|----------|---------------|
| previousRelease | Namespaced name of the previous Release | No | - |
| release | Namespaced name of the Release | No | - |
| releasePlan | Namespaced name of the ReleasePlan | No | - |
| releasePlanAdmission | Namespaced name of the ReleasePlanAdmission | No | - |
| subdirectory | Subdirectory inside the workspace to be used | Yes | "" |
| Name | Description | Optional | Default value |
|------------------------|------------------------------------------------------------------|----------|---------------|
| previousRelease | Namespaced name of the previous Release | No | - |
| release | Namespaced name of the Release | No | - |
| collectorsResourceType | The type of resource that contains the collectors | No | - |
| collectorsResource | The namespaced name of the resource that contains the collectors | No | - |
| subdirectory | Subdirectory inside the workspace to be used | Yes | "" |

## Changes in 0.2.0
* Stop passing releasePlan and releasePlanAdmission and pass instead a reference to a resource
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Task
metadata:
name: collect-collectors-resources
labels:
app.kubernetes.io/version: "0.1.0"
app.kubernetes.io/version: "0.2.0"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: release
Expand All @@ -17,12 +17,14 @@ spec:
- name: release
type: string
description: The namespaced name of the Release
- name: releasePlan
- name: collectorsResourceType
description: The type of resource that contains the collectors
type: string
description: The namespaced name of the ReleasePlan
- name: releasePlanAdmission
default: releaseplan
- name: collectorsResource
description: |
The namespaced name of the resource that contains the collectors
type: string
description: The namespaced name of the ReleasePlanAdmission
- name: subdirectory
description: Subdirectory inside the workspace to be used
type: string
Expand All @@ -37,12 +39,9 @@ spec:
- name: release
type: string
description: The relative path in the workspace to the stored release json
- name: releasePlan
- name: collectorsResource
type: string
description: The relative path in the workspace to the stored releasePlan json
- name: releasePlanAdmission
type: string
description: The relative path in the workspace to the stored releasePlanAdmission json
description: The relative path in the workspace to the stored collectors resource json
- name: resultsDir
type: string
description: The relative path in the workspace to the results directory
Expand All @@ -54,10 +53,10 @@ spec:
value: '$(params.previousRelease)'
- name: "RELEASE"
value: '$(params.release)'
- name: "RELEASE_PLAN"
value: '$(params.releasePlan)'
- name: "RELEASE_PLAN_ADMISSION"
value: '$(params.releasePlanAdmission)'
- name: "COLLECTORS_RESOURCE_TYPE"
value: '$(params.collectorsResourceType)'
- name: "COLLECTORS_RESOURCE"
value: '$(params.collectorsResource)'
script: |
#!/usr/bin/env bash
set -exo pipefail
Expand All @@ -79,11 +78,7 @@ spec:
echo -n "$RELEASE_PATH" > "$(results.release.path)"
get-resource "release" "${RELEASE}" | tee "$(workspaces.data.path)/$RELEASE_PATH"
RELEASE_PLAN_PATH="$(params.subdirectory)/release_plan.json"
echo -n "$RELEASE_PLAN_PATH" > "$(results.releasePlan.path)"
get-resource "releaseplan" "${RELEASE_PLAN}" | tee "$(workspaces.data.path)/$RELEASE_PLAN_PATH"
RELEASE_PLAN_ADMISSION_PATH="$(params.subdirectory)/release_plan_admission.json"
echo -n "$RELEASE_PLAN_ADMISSION_PATH" > "$(results.releasePlanAdmission.path)"
get-resource "releaseplanadmission" "${RELEASE_PLAN_ADMISSION}" \
| tee "$(workspaces.data.path)/$RELEASE_PLAN_ADMISSION_PATH"
COLLECTORS_RESOURCE_PATH="$(params.subdirectory)/collectors_resource.json"
echo -n "$COLLECTORS_RESOURCE_PATH" > "$(results.collectorsResource.path)"
get-resource "${COLLECTORS_RESOURCE_TYPE}" "${COLLECTORS_RESOURCE}" | \
tee "$(workspaces.data.path)/$COLLECTORS_RESOURCE_PATH"
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
test/assert-task-failure: "run-task"
spec:
description: |
Run the collect-collectors-resources task without a ReleasePlanAdmission cr and verify that
Run the collect-collectors-resources task without a PreviousRelease cr and verify that
the task fails as expected.
workspaces:
- name: tests-workspace
Expand All @@ -20,18 +20,6 @@ spec:
script: |
#!/usr/bin/env bash
set -eux
cat > previousrelease << EOF
apiVersion: appstudio.redhat.com/v1alpha1
kind: Release
metadata:
name: previous-release-missing-cr-sample
namespace: default
spec:
snapshot: foo
releasePlan: foo
EOF
kubectl apply -f previousrelease
cat > release << EOF
apiVersion: appstudio.redhat.com/v1alpha1
Expand Down Expand Up @@ -64,10 +52,10 @@ spec:
value: default/previous-release-missing-cr-sample
- name: release
value: default/release-missing-cr-sample
- name: releasePlan
- name: collectorsResourceType
value: releaseplan
- name: collectorsResource
value: default/releaseplan-missing-cr-sample
- name: releasePlanAdmission
value: default/releaseplanadmission-missing-cr-sample
- name: subdirectory
value: $(context.pipelineRun.uid)
runAfter:
Expand All @@ -85,6 +73,5 @@ spec:
#!/usr/bin/env bash
set -eux
kubectl delete release previous-release-missing-cr-sample
kubectl delete release release-missing-cr-sample
kubectl delete releaseplan releaseplan-missing-cr-sample
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,6 @@ spec:
target: foo
EOF
kubectl apply -f releaseplan
cat > releaseplanadmission << EOF
apiVersion: appstudio.redhat.com/v1alpha1
kind: ReleasePlanAdmission
metadata:
name: releaseplanadmission-sample
namespace: default
spec:
applications:
- foo
origin: foo
policy: foo
pipeline:
pipelineRef:
resolver: cluster
params:
- name: name
value: release-pipeline
- name: namespace
value: default
- name: kind
value: pipeline
EOF
kubectl apply -f releaseplanadmission
- name: run-task
taskRef:
name: collect-collectors-resources
Expand All @@ -85,10 +61,10 @@ spec:
value: default/previous-release-sample
- name: release
value: default/release-sample
- name: releasePlan
- name: collectorsResourceType
value: releaseplan
- name: collectorsResource
value: default/releaseplan-sample
- name: releasePlanAdmission
value: default/releaseplanadmission-sample
- name: subdirectory
value: $(context.pipelineRun.uid)
runAfter:
Expand All @@ -104,10 +80,8 @@ spec:
value: $(tasks.run-task.results.previousRelease)
- name: release
value: $(tasks.run-task.results.release)
- name: releasePlan
value: $(tasks.run-task.results.releasePlan)
- name: releasePlanAdmission
value: $(tasks.run-task.results.releasePlanAdmission)
- name: collectorsResource
value: $(tasks.run-task.results.collectorsResource)
workspaces:
- name: data
workspace: tests-workspace
Expand All @@ -121,9 +95,7 @@ spec:
type: string
- name: release
type: string
- name: releasePlan
type: string
- name: releasePlanAdmission
- name: collectorsResource
type: string
workspaces:
- name: data
Expand All @@ -144,12 +116,9 @@ spec:
echo Test that Release CR was saved to workspace
test "$(jq -r '.metadata.name' < "$(workspaces.data.path)/$(params.release)")" == release-sample
echo Test that ReleasePlan CR was saved to workspace
test "$(jq -r '.metadata.name' < "$(workspaces.data.path)/$(params.releasePlan)")" == releaseplan-sample
echo Test that ReleasePlanAdmission CR was saved to workspace
test "$(jq -r '.metadata.name' < "$(workspaces.data.path)/$(params.releasePlanAdmission)")" == \
releaseplanadmission-sample
echo Test that the collectors resource was saved to workspace
test "$(jq -r '.metadata.name' < "$(workspaces.data.path)/$(params.collectorsResource)")" == \
releaseplan-sample
finally:
- name: cleanup
taskSpec:
Expand All @@ -163,4 +132,3 @@ spec:
kubectl delete release previous-release-sample
kubectl delete release release-sample
kubectl delete releaseplan releaseplan-sample
kubectl delete releaseplanadmission releaseplanadmission-sample
15 changes: 9 additions & 6 deletions tasks/run-collectors/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# run-collectors

Tekton task to run the collectors defined in the ReleasePlan and ReleasePlanAdmission. The results are saved in the resultsDir,
Tekton task to run the collectors defined in a resource passed as parameter. The results are saved in the resultsDir,
one file per collector.

## Parameters

| Name | Description | Optional | Default value |
|--------------------------|---------------------------------------------------------------------------|----------|---------------|
| releasePlanAdmissionPath | Path to the JSON string of the ReleasePlanAdmission in the data workspace | No | - |
| releasePlanPath | Path to the JSON string of the ReleasePlan in the data workspace | No | - |
| resultsDir | The relative path in the workspace to save the collector results to | No | - |
| Name | Description | Optional | Default value |
|------------------------|-----------------------------------------------------------------------------------------|----------|---------------|
| collectorsPath | Path to the JSON string of the resource containing the collectors in the data workspace | No | - |
| collectorsResourceType | The type of resource that contains the collectors | No | - |
| resultsDir | The relative path in the workspace to save the collector results to | No | - |

## Changes in 0.2.0
* Pass reference to the collectors path and to the resource type
Loading

0 comments on commit a1aabe7

Please sign in to comment.