kustomize-action

Run kustomize build in parallel in GitHub Action

APACHE-2.0 License

Stars
13
Committers
2

kustomize-action ts

This is an action to run kustomize build in parallel.

Problem to solve

If kustomization.yaml depends on an external resource such as HTTPS, kustomize build takes a long time. For GitOps, a manifest repository contains many kustomization.yaml and it would be take a very long time to build all. This action builds them in parallel to reduce time.

Getting Started

To build manifests, create a workflow as follows:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: int128/kustomize-action@v1
        id: kustomize
        with:
          kustomization: overlays/*/kustomization.yaml
      - run: find ${{ steps.kustomize.outputs.directory }}

If the following files are matched,

overlays/development/kustomization.yaml
overlays/production/kustomization.yaml

this action writes the manifests to a temporary directory. You can get the paths from outputs.files, for example,

/tmp/kustomize-action-xyz/overlays/development/generated.yaml
/tmp/kustomize-action-xyz/overlays/production/generated.yaml

You can get the base directory from outputs.directory, for example,

/tmp/kustomize-action-xyz

Errors

If kustomize build command returned an error, you can see it from GitHub Actions summary page or pull request review comment.

As well as you can set error-comment input to post a comment to a pull request.

You can set ignore-kustomize-error input to suppress kustomize errors. If it is set to true,

  • It exits successfully even if kustomize exited with non-zero code
  • It does not add a pull request review comment
  • It dows not add an error annotation

Write individual files

You can set write-individual-files to write individual files (see kustomize#960).

- uses: int128/kustomize-action@v1
  with:
    kustomization: overlays/*/kustomization.yaml
    write-individual-files: true

This action writes the individual manifests as follows:

/tmp/kustomize-action-xyz/overlays/development/apps_v1_deployment_echoserver.yaml
/tmp/kustomize-action-xyz/overlays/development/v1_service_echoserver.yaml
/tmp/kustomize-action-xyz/overlays/production/apps_v1_deployment_echoserver.yaml
/tmp/kustomize-action-xyz/overlays/production/v1_service_echoserver.yaml

Copy extra files

You can set extra-files to copy the extra files with the results of kustomize build.

- uses: int128/kustomize-action@v1
  with:
    kustomization: overlays/*/kustomization.yaml
    extra-files: overlays/*/metadata.yaml

This action writes the generated manifests with the extra files as follows:

/tmp/kustomize-action-xyz/overlays/development/generated.yaml
/tmp/kustomize-action-xyz/overlays/development/metadata.yaml
/tmp/kustomize-action-xyz/overlays/production/generated.yaml

Add extra args

You can add extra args to kustomize build command.

- uses: int128/kustomize-action@v1
  with:
    kustomization: overlays/*/kustomization.yaml
    kustomize-build-args: |
      --load-restrictor=LoadRestrictionsNone

Diff between head and base ref of pull request

When you open or update a pull request, you can see the diff of generated manifests between head and base ref.

See https://github.com/int128/kubebuilder-workflows/blob/v1/.github/workflows/manifest.yaml for example.

Inputs

Name Default Description
kustomization (required) Glob patterns to kustomization.yaml
kustomize-build-args - Extra args to kustomize build command (multiline)
extra-files - Glob patterns to extra files to copy
base-directory (workspace) Base directory to compute a relative path to kustomization.yaml
retry-max-attempts 2 Max attempts of retry to run kustomize (0 = no retry)
retry-wait-ms 2,000 (2s) Wait before retry kustomize in milliseconds
max-process 5 Max number of kustomize processes
write-individual-files false If true, write individual files
ignore-kustomize-error false If true, ignore kustomize errors
error-comment false Post a comment on error
error-comment-header - Header in a comment to post on error
error-comment-footer - Footer in a comment to post on error
token github.token GitHub token to post a comment on error

Retry options

Eventually kustomize command fails due to a temporary error such as network error. This action retries if kustomize command returned non-zero exit status.

You can turn off the retry by retry-max-attempts option.

Outputs

Name Description
directory directory to results of kustomize build
files multi-line string of files generated by kustomize build