Skip to content

Current working directory is always the directory of last kustomization #5906

Open
@emil-at-z

Description

@emil-at-z

What happened?

When using transformers defined as KRM's I expect them to be executed in a directory in a consistent and predictable way. Currently it appears to be the last directory which contained a kustomization, which depending on overlays can be very random. Preferably it should always be set to the directory of the transformer resource, or at least the directory of the current customization.

What did you expect to happen?

I would expect each transformer to be run in the directory it was declared (or in the directory where the kustomization is declared).

How can we reproduce it (as minimally and precisely as possible)?

Set up following structure in /tmp/kzbug and try to build it as a kustomization.
(You need to enable exec with '--enable-exec')

$ kustomize build --enable-exec /tmp/kzbug

file: ./config.yaml

apiVersion: apps/v1
kind: Service
metadata:
  name: test
  namespace: test
spec:
  ports:
    - name: test
      port: 443
      targetPort: https

file: ./ppwd

Needs to be executable (chmod a+x ./ppwd)

#!/bin/bash
export CD="$(pwd)"
tee >(yq -P '.functionConfig.metadata.name + " - " + "'${CD}'"' - >> /dev/pts/2)

file: kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - config.yaml

transformers:
  - ./t1.yaml
  - ./t2
  - ./t3.yaml
  - ./t4
  - ./t5.yaml

file: t1.yaml

kind: T1
metadata:
  name: t1
  annotations:
    config.kubernetes.io/function: |
      exec:
        path: /tmp/kzbug/ppwd

file: t3.yaml

kind: T3
metadata:
  name: t3
  annotations:
    config.kubernetes.io/function: |
      exec:
        path: /tmp/kzbug/ppwd

file: t5.yaml

kind: T5
metadata:
  name: t5
  annotations:
    config.kubernetes.io/function: |
      exec:
        path: /tmp/kzbug/ppwd

file: t2/kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

transformers:
  - t.yaml

file: t2/t.yaml

kind: T2
metadata:
  name: t2
  annotations:
    config.kubernetes.io/function: |
      exec:
        path: /tmp/kzbug/ppwd

file: t4/kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

transformers:
  - t.yaml
  - t41

file: t4/t.yaml

kind: T4
metadata:
  name: t4
  annotations:
    config.kubernetes.io/function: |
      exec:
        path: /tmp/kzbug/ppwd

file: t4/t41/kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

transformers:
  - t.yaml

file: t4/t41/t.yaml

kind: T41
metadata:
  name: t41
  annotations:
    config.kubernetes.io/function: |
      exec:
        path: /tmp/kzbug/ppwd

Expected output

$  kustomize build --enable-exec  .
t2 - /tmp/kzbug/t2
t41 - /tmp/kzbug/t4/t41
t4 - /tmp/kzbug/t4
t1 - /tmp/kzbug
t3 - /tmp/kzbug
t5 - /tmp/kzbug

apiVersion: apps/v1
kind: Service
metadata:
  name: test
  namespace: test
spec:
  ports:
  - name: test
    port: 443
    targetPort: https

Actual output

The last directory used as

a kustomization is used.

t2 - /tmp/kzbug/t2
t41 - /tmp/kzbug/t4/t41
t4 - /tmp/kzbug/t4/t41
t1 - /tmp/kzbug/t4/t41
t3 - /tmp/kzbug/t4/t41
t5 - /tmp/kzbug/t4/t41

apiVersion: apps/v1
kind: Service
metadata:
  name: test
  namespace: test
spec:
  ports:
  - name: test
    port: 443
    targetPort: https

Kustomize version

Version:kustomize/v4.5.6 GitCommit:29ca6935bde25565795e1b4e13ca211c4aa56417 BuildDate:2022-07-29T20:42:23Z GoOs:linux GoArch:amd64

Operating system

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions