Skip to content

Commit

Permalink
[OpenShift] Improve Addon Task management
Browse files Browse the repository at this point in the history
Move logic to create 'versioned clustertasks' (clustertasks with version
suffix in names), into operator

Move kind replacement of all tasks into operator

Move tasks from (openshift) pipelines-catalog into operator openshift
kodata

Modify fetch clustertasks script to download tasks only from
tektoncd/catalog repository main branch

Signed-off-by: Nikhil Thomas <nikthoma@redhat.com>
  • Loading branch information
nikhil-thomas committed Mar 7, 2022
1 parent 18bfb46 commit 85445a3
Show file tree
Hide file tree
Showing 21 changed files with 174 additions and 304 deletions.
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ You can edit the script to mention the specific version of the task or to add a
Then all the tasks mentioned in the script can be added to codebase using

```shell
./hack/openshift/update-tasks.sh release-v0.22 cmd/openshift/operator/kodata/tekton-addon/1.4.0 v0.22.0
./hack/openshift/fetch-tektoncd-catalog-tasks.sh cmd/openshift/operator/kodata/tekton-addon/addons/02-clustertasks/source_external
```
## Running Codegen

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# auto generated by script/update-tasks.sh
# DO NOT EDIT: use the script instead
# source: https://raw.githubusercontent.com/openshift/tektoncd-catalog/release-v0.24/task/buildah/0.1/buildah.yaml
#
---
---
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
kind: Task
metadata:
name: buildah
labels:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
kind: Task
metadata:
name: maven
labels:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# auto generated by script/update-tasks.sh
# auto generated by script/fetch-tektoncd-catalog-tasks.sh
# DO NOT EDIT: use the script instead
# source: https://raw.githubusercontent.com/openshift/tektoncd-catalog/release-v0.24/task/openshift-client/0.2/openshift-client.yaml
#
---
---
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
kind: Task
metadata:
name: openshift-client
labels:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# auto generated by script/update-tasks.sh
# DO NOT EDIT: use the script instead
# source: https://raw.githubusercontent.com/openshift/pipelines-catalog/release-v0.28/task/s2i-dotnet/0.1/s2i-dotnet.yaml
#
---
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
kind: Task
metadata:
name: s2i-dotnet
labels:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# auto generated by script/update-tasks.sh
# DO NOT EDIT: use the script instead
# source: https://raw.githubusercontent.com/openshift/pipelines-catalog/release-v0.28/task/s2i-go/0.1/s2i-go.yaml
#
---
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
kind: Task
metadata:
name: s2i-go
labels:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# auto generated by script/update-tasks.sh
# DO NOT EDIT: use the script instead
# source: https://raw.githubusercontent.com/openshift/pipelines-catalog/release-v0.28/task/s2i-java/0.1/s2i-java.yaml
#
---
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
kind: Task
metadata:
name: s2i-java
labels:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# auto generated by script/update-tasks.sh
# DO NOT EDIT: use the script instead
# source: https://raw.githubusercontent.com/openshift/pipelines-catalog/release-v0.28/task/s2i-nodejs/0.1/s2i-nodejs.yaml
#
---
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
kind: Task
metadata:
name: s2i-nodejs
labels:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# auto generated by script/update-tasks.sh
# DO NOT EDIT: use the script instead
# source: https://raw.githubusercontent.com/openshift/pipelines-catalog/release-v0.28/task/s2i-perl/0.1/s2i-perl.yaml
#
---
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
kind: Task
metadata:
name: s2i-perl
labels:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# auto generated by script/update-tasks.sh
# DO NOT EDIT: use the script instead
# source: https://raw.githubusercontent.com/openshift/pipelines-catalog/release-v0.28/task/s2i-php/0.1/s2i-php.yaml
#
---
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
kind: Task
metadata:
name: s2i-php
labels:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# auto generated by script/update-tasks.sh
# DO NOT EDIT: use the script instead
# source: https://raw.githubusercontent.com/openshift/pipelines-catalog/release-v0.28/task/s2i-python/0.1/s2i-python.yaml
#
---
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
kind: Task
metadata:
name: s2i-python
labels:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# auto generated by script/update-tasks.sh
# DO NOT EDIT: use the script instead
# source: https://raw.githubusercontent.com/openshift/pipelines-catalog/release-v0.28/task/s2i-ruby/0.1/s2i-ruby.yaml
#
---
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
kind: Task
metadata:
name: s2i-ruby
labels:
Expand Down
7 changes: 7 additions & 0 deletions hack/fetch-releases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ release_yaml_hub() {
done
}

fetch_openshift_addon_tasks() {
fetch_addon_task_script="${SCRIPT_DIR}/hack/openshift"
local dest_dir="cmd/openshift/operator/kodata/tekton-addon/addons/02-clustertasks/source_external"
${fetch_addon_task_script}/fetch-tektoncd-catalog-tasks.sh ${dest_dir}
}

#Args: <target-platform> <pipelines version> <triggers version> <dashboard version> <results version> <pac version> <hub version> <chain version>
main() {
TARGET=$1
Expand Down Expand Up @@ -188,6 +194,7 @@ main() {
else
pac_version=${6}
release_yaml_pac pipelinesascode release ${pac_version}
fetch_openshift_addon_tasks
fi

hub_version=${7}
Expand Down
122 changes: 122 additions & 0 deletions hack/openshift/fetch-tektoncd-catalog-tasks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/usr/bin/env bash
set -e -u -o pipefail

declare -r SCRIPT_NAME=$(basename "$0")
declare -r SCRIPT_DIR=$(cd $(dirname "$0") && pwd)

log() {
local level=$1; shift
echo -e "$level: $@"
}


err() {
log "ERROR" "$@" >&2
}

info() {
log "INFO" "$@"
}

die() {
local code=$1; shift
local msg="$@"; shift
err $msg
exit $code
}

usage() {
local msg="$1"
cat <<-EOF
Error: $msg
USAGE:
$SCRIPT_NAME DEST_DIR
Example:
$SCRIPT_NAME cmd/openshift/operator/kodata/tekton-addon/addons/02-clustertasks/source_external
EOF
exit 1
}

#declare -r CATALOG_VERSION="release-v0.7"

declare -r TEKTON_CATALOG="https://raw.githubusercontent.com/tektoncd/catalog"
declare -A TEKTON_CATALOG_TASKS=(
# Need to remove version param
["git-clone"]="0.4"
["kn"]="0.1"
["kn-apply"]="0.1"
["skopeo-copy"]="0.1"
["tkn"]="0.2"
# Those tasks are managed directly in the repository
# ["buildah"]="0.1"
# ["openshift-client"]="0.2"
)

download_task() {
local task_path="$1"; shift
local task_url="$1"; shift

info "downloading ... $t from $task_url"
# validate url
curl --output /dev/null --silent --head --fail "$task_url" || return 1


cat <<-EOF > "$task_path"
# auto generated by script/update-tasks.sh
# DO NOT EDIT: use the script instead
# source: $task_url
#
---
$(curl -sLf "$task_url")
EOF

# NOTE: helps when the original and the generated need to compared
# curl -sLf "$task_url" -o "$task_path.orig"

}


get_tasks() {
local dest_dir="$1"; shift
local catalog="$1"; shift
local catalog_version="$1"; shift
local -n tasks=$1

info "Downloading tasks from catalog $catalog to $dest_dir directory"
for t in ${!tasks[@]} ; do
# task filenames do not follow a naming convention,
# some are taskname.yaml while others are taskname-task.yaml
# so, try both before failing
local task_url="$catalog/$catalog_version/task/$t/${tasks[$t]}/${t}.yaml"
echo "$catalog/$catalog_version/task/$t/${tasks[$t]}/${t}.yaml"

mkdir -p "$dest_dir/$t/"
local task_path="$dest_dir/$t/$t-task.yaml"

download_task "$task_path" "$task_url" ||
die 1 "Failed to download $t"
done
}

create_dir_or_die() {
local dest_dir="$1"; shift
mkdir -p "$dest_dir" || die 1 "failed to create ${dest_dir}"
echo $dest_dir created
}

main() {

local dest_dir=${1:-''}
[[ -z "$dest_dir" ]] && usage "missing destination directory"
shift

[[ ! -d "$dest_dir" ]] && create_dir_or_die "$dest_dir" || echo "$dest_dir" exists

get_tasks "$dest_dir" "$TEKTON_CATALOG" "main" TEKTON_CATALOG_TASKS

return $?
}

main "$@"
Loading

0 comments on commit 85445a3

Please # to comment.