kustomize: Configuration-Value nameSuffix is ignored

Whatever pathes are set for the ConfigurationValue nameSuffix are ignored. Only the Pathes from namePrefix are used for the Name-Transformer.

The Module api/internal/target/kusttarget_configplugin.go will just pass the ConfigurationParameter nameSuffix to FieldSpecs of PrefixSuffixTransformer (because the plugin/buildin/prefixsuffixtransformer/PrefixSuffixTransformer.go only supports one fieldSpecs-Array)

This means, that it is not possible to declare some pathes to only receive a Prefix OR a suffix, if both are configured.

I’m trying to expose the namePrefix and nameSuffix values automatically into a ArgoCD-Application Description. When I generate the Application with kustomize, I want to mirror the name-changes into spec/source/kustomize/{namePrefix|nameSuffix}

config.yaml

namePrefix:
- path: metadata/labels/prefix

nameSuffix:
- path: metadata/labels/suffix

test.yaml

kind: Test
metadata:
  name: test
  labels:
    prefix: ""
    suffix: ""

kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
configurations:
- config.yaml
resources:
- test.yaml

namePrefix: "pre-"
nameSuffix: "-suf"

Expected output

kind: Test
metadata:
  labels:
    prefix: pre-
    suffix: -suf
  name: pre-test-suf

Actual output

kind: Test
metadata:
  labels:
    prefix: pre--suf
    suffix: ""
  name: pre-test-suf

Kustomize version

3.9.4…4.3.0

Platform

Windows (3.9.4), Linux (4.3.0)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 15 (14 by maintainers)

Commits related to this issue

Most upvoted comments

@KnVerey, coincidentally I was just working on trying out your approach. It didn’t work out-of-the-box by removing th.PrepBuiltin("PrefixSuffixTransformer") as the loading option was still types.BploLoadFromFileSys.

=== RUN   TestMatchesCurrentID                                                                                                                                                                 
    harnessenhanced.go:179: Err: expected` file with Go object code at: /home/jvdberkmortel/Ark/kubernetes-sigs/kustomize/plugin/builtin/prefixsuffixtransformer/PrefixSuffixTransformer.so     
--- FAIL: TestMatchesCurrentID (0.00s) 

I added the below line in addition to removing th.PrepBuiltin("PrefixSuffixTransformer") and (as far I as can tell) it works like you said. Thank you!

th.GetPluginConfig().BpLoadingOptions = types.BploUseStaticallyLinked

Please let me know if you have any other feedback in regards to the above, otherwise I will create a PR 👍🏼

Thank you for the detailed and in-depth feedback @natasha41575, it helped a lot! I made a really rough “prototype” ( https://github.com/Serializator/kustomize/commit/65f6443289f3369d9d8e7847f924f7445c048041) in which I refactored the PrefixSuffixTransformer into separate transformers. I ran all tests and they all succeeded.

I will start working on refactoring some of the TODOs into the filters, make sure the tests are written for the PrefixTransformer and SuffixTransformer and fine-tune everything necessary before making a PR.