Skip to content

karmafun

karmafun is a kustomize plugin and a kustomize build wrapper providing a set of KRM Functions that perform in-place transformations on Kubernetes resource files.

Why karmafun?

kustomize fn run enables in-place transformation of KRM resources — perfect for making structural changes to a GitOps repository without adding extra nesting layers. Unfortunately, kustomize's built-in transformers and generators are not available to kustomize fn run, which requires an external container or exec binary.

karmafun fills that gap by providing:

  • All kustomize builtin transformers and generators as KRM functions.
  • Additional generators: GitConfigMapGenerator, KustomizationGenerator, SopsGenerator, KCLGenerator.
  • Additional transformers: RemoveTransformer, KCLTransformer, and an extended ReplacementTransformer with structured-content support.
  • A karmafun build command extending kustomize build with Go template rendering and SOPS-encrypted secrets.

Quick start

1. Install

curl -sLS https://raw.githubusercontent.com/karmafun/karmafun/main/get.sh | /bin/sh

See Installation for other methods.

2. Write a function config

# functions/fn-change-repo.yaml
apiVersion: builtin
kind: PatchTransformer
metadata:
  name: fn-change-repo
  annotations:
    config.karmafun.dev/cleanup: "true"
    config.kubernetes.io/function: |
      exec:
        path: karmafun
patch: |-
  - op: replace
    path: /spec/source/repoURL
    value: https://github.com/myname/autocloud.git
  - op: replace
    path: /spec/source/targetRevision
    value: feature/experiment
target:
  group: argoproj.io
  version: v1alpha1
  kind: Application
  annotationSelector: "autocloud/local-application=true"

3. Run

kustomize fn run --enable-exec --fn-path functions applications

The config.karmafun.dev/cleanup: "true" annotation removes kustomize's internal tracking annotations from the output (see Annotations).

  • kpt — takes in-place transformation further with package versioning.
  • krmfnsops — the SOPS integration used by SopsGenerator.