Skip to content

Commit

Permalink
Migrated tasks to v1,added release.sh and docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Senjuti256 committed Jan 11, 2024
1 parent 6500222 commit b32445a
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# task-openshift

This repository provides various task related to OpenShift and OpenShift Pipelines.
- [openshift-client](docs/task-openshift-client.md)
- [tkn](docs/task-tkn.md)
57 changes: 57 additions & 0 deletions docs/task-openshift-client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
`OpenShift-Cient` Tekton Task
-----------------------

# Abstract

The `openshift-client` Task is the binary for OpenShift CLI that complements kubectl for simplifying deployment and configuration applications on OpenShift.

# Usage

Please, consider the usage example below:

```yaml
---
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata: {}
spec:
pipelineRef:
name: task-openshift-client
params:
- name: SCRIPT
value: openShift-CLI-arguments
- name: VERSION
value: oc-version

```
You'll need to replace `openShift-CLI-arguments` with OpenShift CLI arguments that you want to run and replace `oc-version` with the version of OpenShift you want to use.
In case the Container Registry requires authentication, please consider the [Tekton Pipelines documentation][tektonPipelineAuth]. In a nutshell, you need to create a Kubernetes Secret describing the following attributes:

```bash
kubectl create secret docker-registry imagestreams \
--docker-server="image-registry.openshift-image-registry.svc:5000" \
--docker-username="${REGISTRY_USERNAME}" \
--docker-password="${REGISTRY_TOKEN}"
```

Then make sure the Secret is linked with the Service-Account running the `TaskRun`/`PipelineRun`.

## Workspace

| Name | Optional | Description |
| :------------ | :------------------------: | :--------------------------- |
| `manifest_dir` | `true` | The workspace which contains kubernetes manifests which we want to apply on the cluster. |
| `kubeconfig_dir` | `true` | The workspace which contains the the kubeconfig file if in case we want to run the oc command on another cluster. |


## Params

| Param | Type | Default | Description |
| :------------ | :------------------------: | :--------------------------- | :------------------------- |
| `SCRIPT` | `string` | (required) | The OpenShift CLI arguments to run |
| `VERSION` | `string` | (required) | The OpenShift version to use |



[tektonPipelineAuth]: https://tekton.dev/docs/pipelines/auth/#configuring-docker-authentication-for-docker

56 changes: 56 additions & 0 deletions docs/task-tkn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
`Tkn` Tekton Task
-----------------------

# Abstract

The `tkn` Task is a binary to perform operations on Tekton resources using tkn.

# Usage

Please, consider the usage example below:

```yaml
---
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata: {}
spec:
pipelineRef:
name: task-tkn
params:
- name: SCRIPT
value: "tkn $@"
- name: ARGS
value: tkn-command-you-want-to-execute

```
You'll need to replace `tkn-command-you-want-to-execute` with tkn CLI arguments based on what operation you want to perform on the Tekton resources.
In case the Container Registry requires authentication, please consider the [Tekton Pipelines documentation][tektonPipelineAuth]. In a nutshell, you need to create a Kubernetes Secret describing the following attributes:

```bash
kubectl create secret docker-registry imagestreams \
--docker-server="image-registry.openshift-image-registry.svc:5000" \
--docker-username="${REGISTRY_USERNAME}" \
--docker-password="${REGISTRY_TOKEN}"
```

Then make sure the Secret is linked with the Service-Account running the `TaskRun`/`PipelineRun`.

## Workspace

| Name | Optional | Description |
| :------------ | :------------------------: | :--------------------------- |
| `kubeconfig_dir` | `true` | An optional workspace that allows you to provide a .kube/config file for tkn to access the cluster. |


## Params

| Param | Type | Default | Description |
| :------------ | :------------------------: | :--------------------------- | :------------------------- |
| `SCRIPT` | `string` | (required) | tkn CLI script to execute |
| `ARGS` | `array` | (required) | tkn CLI arguments to run |



[tektonPipelineAuth]: https://tekton.dev/docs/pipelines/auth/#configuring-docker-authentication-for-docker

70 changes: 70 additions & 0 deletions hack/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
#
# Renders and copies documentation files into the informed RELEASE_DIR, the script search for
# task templates on a specific glob expression. The templates are rendered using the actual
# task name and documentation is searched for and copied over to the task release directory.
#

shopt -s inherit_errexit
set -eu -o pipefail

readonly RELEASE_DIR="${1:-}"

# Print error message and exit non-successfully.
panic() {
echo "# ERROR: ${*}"
exit 1
}

# Extracts the filename only, without path or extension.
extract_name() {
declare filename=$(basename -- "${1}")
declare extension="${filename##*.}"
echo "${filename%.*}"
}

# Finds the respective documentation for the task name
find_doc() {
declare task_name="${1}"
find docs/ -name "${task_name}*.md"
}

#
# Main
#

release() {
# making sure the release directory exists, this script should only create releative
# directories using it as root
[[ ! -d "${RELEASE_DIR}" ]] &&
panic "Release dir is not found '${RELEASE_DIR}'!"

# releasing all task templates using the following glob expression
for t in $(ls -1 templates/task-*.yaml); do
declare task_name=$(extract_name ${t})
[[ -z "${task_name}" ]] &&
panic "Unable to extract Task name from '${t}'!"

declare task_doc="$(find_doc ${task_name})"
[[ -z "${task_doc}" ]] &&
panic "Unable to find documentation file for '${task_name}'!"

declare task_dir="${RELEASE_DIR}/tasks/${task_name}"
[[ ! -d "${task_dir}" ]] &&
mkdir -p "${task_dir}"

# rendering the helm template for the specific file, using the resource name for the
# filename respectively
echo "# Rendering '${task_name}' at '${task_dir}'..."
helm template --show-only=${t} . >${task_dir}/${task_name}.yaml ||
panic "Unable to render '${t}'!"

# finds the respective documentation file copying as "README.md", on the same
# directory where the respective task is located
echo "# Copying '${task_name}' documentation file '${task_doc}'..."
cp -v -f ${task_doc} "${task_dir}/README.md" ||
panic "Unable to copy '${task_doc}' into '${task_dir}'"
done
}

release
3 changes: 1 addition & 2 deletions templates/task-openshift-client.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: openshift-client
Expand Down Expand Up @@ -70,4 +70,3 @@ spec:
volumes:
- name: scripts-dir
emptyDir: {}

4 changes: 2 additions & 2 deletions templates/task-tkn.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: tkn
Expand Down Expand Up @@ -60,4 +60,4 @@ spec:

volumes:
- name: scripts-dir
emptyDir: {}
emptyDir: {}
2 changes: 1 addition & 1 deletion test/e2e/resources/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
labels:
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/resources/tkn-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
labels:
Expand Down

0 comments on commit b32445a

Please sign in to comment.