{"id":18548429,"url":"https://github.com/danielfbm/tekton-tasks-kustomize","last_synced_at":"2025-05-15T08:13:04.483Z","repository":{"id":96090647,"uuid":"494951310","full_name":"danielfbm/tekton-tasks-kustomize","owner":"danielfbm","description":"Customizing Tekton tasks with kustomize","archived":false,"fork":false,"pushed_at":"2022-05-22T05:22:01.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-17T09:43:55.456Z","etag":null,"topics":["cloud-native","kubernetes","kustomize","tekton"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielfbm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-22T03:41:11.000Z","updated_at":"2022-05-22T05:26:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"f6f4b8af-072c-4aaa-bed0-30b8401d13c2","html_url":"https://github.com/danielfbm/tekton-tasks-kustomize","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielfbm%2Ftekton-tasks-kustomize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielfbm%2Ftekton-tasks-kustomize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielfbm%2Ftekton-tasks-kustomize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielfbm%2Ftekton-tasks-kustomize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielfbm","download_url":"https://codeload.github.com/danielfbm/tekton-tasks-kustomize/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254301619,"owners_count":22047907,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloud-native","kubernetes","kustomize","tekton"],"created_at":"2024-11-06T20:34:31.865Z","updated_at":"2025-05-15T08:13:04.457Z","avatar_url":"https://github.com/danielfbm.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kustomize + Tekton\n\nHow to hack your [`Tekton`](https://tekton.dev) tasks with [`kustomize`](https://kustomize.io) super powers to reuse parts and customize new tasks\n\nLet's say we want two different tasks `golang-test` and `golangci-lint` need to add a `reviewdog-report` step as seen below\n\n\n![tasks](images/tasks-diagram.drawio.png)\n\n\nThe most  obvious way would be copying and pasting the steps, but for more complex scenarios, where there are `n` tasks, this becomes error prone. Using a template engine like [`helm`](https://helm.sh) could help, but learning another templating engine, plus having to change the contents of said tasks also becomes a burden. Instead, [`kustomize`](https://kustomize.io) has a set of tools to make this job easier, while enjoying reutilizing tasks from the [`tektoncd/catalog`](https://github.com/tektoncd/catalog).\n\n## Folder structure\n\n\n```\n├── overlays\n└── tasks\n```\n\n - *tasks* will host your tasks files\n - *overlays* will host your patches, like adding a shared step\n\n## Tasks\n\nPrepare your tasks, for the example we will use [`golang-test`](https://github.com/tektoncd/catalog/tree/main/task/golang-test/0.2) and [`golangci-lint`](https://github.com/tektoncd/catalog/tree/main/task/golangci-lint/0.2), adjust accordingly.\n\n## Snippet\n\nWith the tasks ready, it is time to prepare a snippet, which should consist of all the necessary additions, like `params`, `workspaces`, `results`, `steps`, etc:\n\n```yaml\nspec:\n  params:\n  # since we are splitting the steps, the previous step needs to save the output to a file\n  - name: report-file\n    default: reportfile\n    description: Report file with errors\n  # format of the report file\n  - name: format\n    default: golint\n    description: Format of error input from the task\n  # reviewdog supports a number of reporter types\n  - name: reporter\n    default: local\n    description: Reporter type for reviewdog https://github.com/reviewdog/reviewdog#reporters\n  # reviewdog needs a diff for precise pull request comments\n  - name: diff\n    default: git diff FETCH_HEAD\n    description: Diff command https://github.com/reviewdog/reviewdog#reporters\n\n  workspaces:\n  - name: token\n    description: |\n      Workspace which contains a token file for Github Pull Request comments. Must have a token file with the Github API access token\n\n  steps:\n  - name: reviewdog-report\n    image: golangci/golangci-lint:v1.31-alpine\n    # both have the same workspace name\n    workingDir: $(workspaces.source.path)\n    script: |\n      #!/bin/sh\n\n      set -ue\n      wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b $(go env GOPATH)/bin\n      export REVIEWDOG_GITHUB_API_TOKEN=$(cat $(workspaces.token.path)/token)\n      cat $(params.reportfile) | reviewdog -f=$(params.format) -diff=\"$(params.diff)\"\n\n\n```\n\n\n## Patch\n\nWith above snippet, it is time to create our patch. I've tried using the snippet directly using `patch` but was not successful, so I decided to create a [`JSON6902 patch`](https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#patchjson6902):\n\n```yaml\n# parameters\n- op: add\n  path: /spec/params/-\n  value:\n    name: report-file\n    default: reportfile\n    description: Report file with errors\n- op: add\n  path: /spec/params/-\n  value:\n    name: format\n    default: golint\n    description: Format of error input from the task\n- op: add\n  path: /spec/params/-\n  value:\n    name: reporter\n    default: local\n    description: Reporter type for reviewdog https://github.com/reviewdog/reviewdog#reporters\n- op: add\n  path: /spec/params/-\n  value:\n    name: diff\n    default: git diff FETCH_HEAD\n    description: Diff command https://github.com/reviewdog/reviewdog#reporters\n\n# workspaces\n- op: add\n  path: /spec/workspaces/-\n  value:\n    name: token\n    description: |\n      Workspace which contains a token file for Github Pull Request comments. Must have a token file with the Github API access token\n\n# steps\n- op: add\n  path: /spec/steps/-\n  value:\n    name: reviewdog-report\n    image: golangci/golangci-lint:v1.31-alpine\n    # both have the same workspace name\n    workingDir: $(workspaces.source.path)\n    script: |\n      #!/bin/sh\n\n      set -ue\n      wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b $(go env GOPATH)/bin\n      export REVIEWDOG_GITHUB_API_TOKEN=$(cat $(workspaces.token.path)/token)\n      cat $(params.reportfile) | reviewdog -f=$(params.format) -diff=\"$(params.diff)\"\n\n```\n\nsave as `reviewdog-step-patch.yaml` and create a `kustomization.yaml` with the following content:\n\n\n```yaml\nbases:\n- ../tasks\n\npatches:\n- path: ./reviewdog-step-patch.yaml\n  target:\n    kind: Task\n```\n\n\n## More patching\n\nMake sure all `kustomization.yaml` files are setup correctly, and try running `kustomize build overlays`. You should see the `params`, `workspaces` and `params` added.\n\n*But wait!*, we still need to connect the dots. Without modifying the imported tasks this would still not work.\n\nFor the `golangci-lint` it is necessary to save the result to a file as given in the parameter `$(params.report-file)`, and change default format for the `$(params.format)` parameter to `golangci-lint`:\n\n### golangci-lint\n\n```yaml\n- op: replace\n  path: /spec/params/11/default\n  value: golangci-lint\n\n- op: replace\n  path: /spec/steps/0/script\n  value: |\n    golangci-lint run $(params.flags) \u003e $(params.report-file)\n```\n\nSave the file as `overlays/golangci-lint-patch.yaml` and add it to the `overlays/kustomization.yaml`\n\n```yaml\n[...]\n- path: ./golangci-lint-patch.yaml\n  target:\n    kind: Task\n    name: golangci-lint\n```\n\n### golang-test\n\nHere is the change for `golang-test`, and actually making it do a `golint`:\n\n```yaml\n- op: replace\n  path: /spec/steps/0/script\n  value: |\n    if [ ! -e $GOPATH/src/$(params.package)/go.mod ];then\n         SRC_PATH=\"$GOPATH/src/$(params.package)\"\n         mkdir -p $SRC_PATH\n         cp -R \"$(workspaces.source.path)/$(params.context)\"/* $SRC_PATH\n         cd $SRC_PATH\n      fi\n      golint $(params.packages) \u003e $(params.report-file)\n```\n\nAdd the entry to `overlays/kustomization.yaml`:\n\n```yaml\n- path: ./golint-patch.yaml\n  target:\n    kind: Task\n    name: golang-test\n```\n\n## Suffix\n\nIf you want to preserve the original tasks and only add new tasks, just change the `overlays/kustomization.yaml` adding a suffix to the files:\n\n\n```yaml\nnameSuffix: -review\n```\n\n## Testing\n\nApply your tasks into your `kubernetes cluster` using `kubectl apply -k overlays` or `kustomize build overlays | kubectl apply -f -`\n\n\n\nThe resulting file tree should be something like:\n\n```\n├── overlays\n│   ├── golangci-lint-patch.yaml\n│   ├── golint-patch.yaml\n│   ├── kustomization.yaml\n│   └── reviewdog-step-patch.yaml\n└── tasks\n    ├── golang-test.yaml\n    ├── golangci-lint.yaml\n    └── kustomization.yaml\n```\n\nEnjoy your new `golang-test-review` and `golangci-lint-review`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielfbm%2Ftekton-tasks-kustomize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielfbm%2Ftekton-tasks-kustomize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielfbm%2Ftekton-tasks-kustomize/lists"}