Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any examples for how to use transformer configuration for variable and namespace? #629

Closed
soorena776 opened this issue Dec 14, 2018 · 7 comments
Labels
kind/documentation Categorizes issue or PR as related to documentation.

Comments

@soorena776
Copy link

Hi,

In transfomerconfigs README you have mentioned that it's possible to use a transformer to inject variables and namespaces. Any examples?

Thank you

@soorena776 soorena776 changed the title Any examples for how to using transformer configuration for variable and namespace? Any examples for how to use transformer configuration for variable and namespace? Dec 14, 2018
@Liujingfang1 Liujingfang1 added the kind/documentation Categorizes issue or PR as related to documentation. label Dec 18, 2018
@Liujingfang1
Copy link
Contributor

Please take a look at the example in https://github.com/kubernetes-sigs/kustomize/tree/master/examples/transformerconfigs

@PacoDu
Copy link

PacoDu commented Apr 30, 2020

Hi, I think the documentation about the namespace transformer configuration is missing: https://kubectl.docs.kubernetes.io/pages/reference/kustomize.html.

I couldn't find any mention of this feature in the documentation but it is possible to add the namespace option to kustomize configuration:

namespace:
  - kind: MyKind
    path: spec/my/crd/path/namespace

I found the solution looking at this builtin transformer configuration: https://github.com/kubernetes-sigs/kustomize/blob/master/api/konfig/builtinpluginconsts/namespace.go.

@ghost
Copy link

ghost commented Oct 16, 2021

hate to reopen this, but I am hitting gaps in documentation regularly.
Maybe simple is not better, if not documented.

@DmitriGekhtman
Copy link

The namespace transformer is still undocumented.

@chobostar
Copy link

I spend a time to get working example, here the result:

$ cat default-input.yaml 
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: manager-rolebinding
subjects:
- kind: ServiceAccount
  name: default
  namespace: system
- kind: ServiceAccount
  name: service-account
  namespace: system
- kind: ServiceAccount
  name: another
  namespace: random
- kind: ServiceAccount
  name: without-namespace
- kind: Unrecognized
  name: no-namespace
- apiGroup: rbac.authorization.k8s.io
  kind: User
  name: alice@example.com
- apiGroup: rbac.authorization.k8s.io
  kind: Group
  name: frontend-admins
- apiGroup: rbac.authorization.k8s.io
  kind: Group
  name: system:serviceaccounts:qa

$ cat kustomization.yaml 
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- default-input.yaml

transformers:
- |-
  apiVersion: builtin
  kind: NamespaceTransformer
  metadata:
    name: notImportantHere
    namespace: test
  setRoleBindingSubjects: allServiceAccounts
  fieldSpecs:
  - path: metadata/namespace
    create: true
$ kustomize version
{Version:kustomize/v4.5.7 GitCommit:56d82a8378dfc8dc3b3b1085e5a6e67b82966bd7 BuildDate:2022-08-02T16:35:54Z GoOs:linux GoArch:amd64}

$ kustomize build .
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: manager-rolebinding
subjects:
- kind: ServiceAccount
  name: default
  namespace: test
- kind: ServiceAccount
  name: service-account
  namespace: test
- kind: ServiceAccount
  name: another
  namespace: test
- kind: ServiceAccount
  name: without-namespace
  namespace: test
- kind: Unrecognized
  name: no-namespace
- apiGroup: rbac.authorization.k8s.io
  kind: User
  name: alice@example.com
- apiGroup: rbac.authorization.k8s.io
  kind: Group
  name: frontend-admins
- apiGroup: rbac.authorization.k8s.io
  kind: Group
  name: system:serviceaccounts:qa

I hope it will help you.

@revero-doug
Copy link

The namespace transformer is still undocumented.

still

larsks added a commit to larsks/kustomize that referenced this issue Dec 5, 2022
Add a short description of the namespace transformer and example
usage to examples/transformerconfigs/README.md.

Closes: kubernetes-sigs#629
larsks added a commit to larsks/kustomize that referenced this issue Dec 5, 2022
Add a short description of the namespace transformer and example
usage to examples/transformerconfigs/README.md.

Closes: kubernetes-sigs#629
Signed-off-by: Lars Kellogg-Stedman <lars@oddbit.com>
@larsks
Copy link
Contributor

larsks commented Dec 5, 2022

I'm not sure why this was closed but I've just created a PR (#4906) that adds the missing documentation.

larsks added a commit to larsks/kustomize that referenced this issue Dec 5, 2022
Add a short description of the namespace transformer and example
usage to examples/transformerconfigs/README.md.

Closes: kubernetes-sigs#629
Signed-off-by: Lars Kellogg-Stedman <lars@oddbit.com>
larsks added a commit to larsks/kustomize that referenced this issue Dec 5, 2022
Add a short description of the namespace transformer and example
usage to examples/transformerconfigs/README.md.

References: kubernetes-sigs#629
Signed-off-by: Lars Kellogg-Stedman <lars@oddbit.com>
larsks added a commit to larsks/kustomize that referenced this issue Dec 8, 2022
Add a short description of the namespace transformer and example
usage to examples/transformerconfigs/README.md.

References: kubernetes-sigs#629
Signed-off-by: Lars Kellogg-Stedman <lars@oddbit.com>
larsks added a commit to larsks/kustomize that referenced this issue Dec 9, 2022
Add a short description of the namespace transformer and example
usage to examples/transformerconfigs/README.md.

References: kubernetes-sigs#629
Signed-off-by: Lars Kellogg-Stedman <lars@oddbit.com>
kishorerj pushed a commit to kishorerj/kustomize that referenced this issue Jan 8, 2023
Add a short description of the namespace transformer and example
usage to examples/transformerconfigs/README.md.

References: kubernetes-sigs#629
Signed-off-by: Lars Kellogg-Stedman <lars@oddbit.com>
k8s-ci-robot pushed a commit that referenced this issue Jan 9, 2023
* initial changes to rename OrgRepo to RepoPath

* changes to rename Path to KustRootPath

* addressed review comments

* addressed review comments

* docs: Add documentation for namespace transformer

Add a short description of the namespace transformer and example
usage to examples/transformerconfigs/README.md.

References: #629
Signed-off-by: Lars Kellogg-Stedman <lars@oddbit.com>

* Localize patchesJson6902, patchesStrategicMerge, replacements (#4904)

* Localize patchesJson6902, patchesStrategicMerge, replacements

* Address code review feedback

* Improve readability
* Remove deprecation warning check

* Load legacy kustomization fields for `localize` (#4918)

* Load legacy kustomization

* Expose loadKustFile in kusttarget

* remove FixKustomizationPreUnmarshalling

* remove deprecated cfg and fn commands (#4930)

* remove deprecated cfg and fn commands

* fix lint error

* run gofmt

* Localize PatchTransformer, PatchJson6902Transformer (#4920)

* Localize patches, patchesJson6902 custom transformers

* Improve readability

* Localize fields: openapi, configurations, crds (#4907)

* Localize openapi, configurations, crds

* Add integration test

* Move krusty test

* Address code review feedback

* Implement locRootPath (#4909)

* Implement locRootPath, and include userinfo, port in locFilePath

* Strip userinfo, port

* Improve readability

* Localize legacy fields

* Localize resources (#4912)

* Localize resources

* Improve readability

* Add integration tests

* Group test helper functions

* Remove Functionality that Pulls Env Variables from Empty Keys

* Update api/kv/kv.go

Co-authored-by: Katrina Verey <kn.verey@gmail.com>

* refactor Unmarshal Kustomization struct code

* improve error messages

* Run go mod tidy on all modules before update

* Update sigs.k8s.io/yaml to 1.3.0

* fixed test failure because of latest commits

Signed-off-by: Lars Kellogg-Stedman <lars@oddbit.com>
Co-authored-by: Lars Kellogg-Stedman <lars@oddbit.com>
Co-authored-by: Anna Song <annasong@google.com>
Co-authored-by: yugo kobayashi <kobdotsh@gmail.com>
Co-authored-by: Natasha Sarkar <natashasarkar@google.com>
Co-authored-by: Cailyn Edwards <cailyn.edwards@shopify.com>
Co-authored-by: Cailyn <cailyn.s.e@gmail.com>
Co-authored-by: Katrina Verey <kn.verey@gmail.com>
Co-authored-by: Katrina Verey <katrina.verey@shopify.com>
cailyn-codes pushed a commit to cailyn-codes/kustomize that referenced this issue Jan 12, 2023
Add a short description of the namespace transformer and example
usage to examples/transformerconfigs/README.md.

References: kubernetes-sigs#629
Signed-off-by: Lars Kellogg-Stedman <lars@oddbit.com>
cailyn-codes added a commit to cailyn-codes/kustomize that referenced this issue Jan 12, 2023
* initial changes to rename OrgRepo to RepoPath

* changes to rename Path to KustRootPath

* addressed review comments

* addressed review comments

* docs: Add documentation for namespace transformer

Add a short description of the namespace transformer and example
usage to examples/transformerconfigs/README.md.

References: kubernetes-sigs#629
Signed-off-by: Lars Kellogg-Stedman <lars@oddbit.com>

* Localize patchesJson6902, patchesStrategicMerge, replacements (kubernetes-sigs#4904)

* Localize patchesJson6902, patchesStrategicMerge, replacements

* Address code review feedback

* Improve readability
* Remove deprecation warning check

* Load legacy kustomization fields for `localize` (kubernetes-sigs#4918)

* Load legacy kustomization

* Expose loadKustFile in kusttarget

* remove FixKustomizationPreUnmarshalling

* remove deprecated cfg and fn commands (kubernetes-sigs#4930)

* remove deprecated cfg and fn commands

* fix lint error

* run gofmt

* Localize PatchTransformer, PatchJson6902Transformer (kubernetes-sigs#4920)

* Localize patches, patchesJson6902 custom transformers

* Improve readability

* Localize fields: openapi, configurations, crds (kubernetes-sigs#4907)

* Localize openapi, configurations, crds

* Add integration test

* Move krusty test

* Address code review feedback

* Implement locRootPath (kubernetes-sigs#4909)

* Implement locRootPath, and include userinfo, port in locFilePath

* Strip userinfo, port

* Improve readability

* Localize legacy fields

* Localize resources (kubernetes-sigs#4912)

* Localize resources

* Improve readability

* Add integration tests

* Group test helper functions

* Remove Functionality that Pulls Env Variables from Empty Keys

* Update api/kv/kv.go

Co-authored-by: Katrina Verey <kn.verey@gmail.com>

* refactor Unmarshal Kustomization struct code

* improve error messages

* Run go mod tidy on all modules before update

* Update sigs.k8s.io/yaml to 1.3.0

* fixed test failure because of latest commits

Signed-off-by: Lars Kellogg-Stedman <lars@oddbit.com>
Co-authored-by: Lars Kellogg-Stedman <lars@oddbit.com>
Co-authored-by: Anna Song <annasong@google.com>
Co-authored-by: yugo kobayashi <kobdotsh@gmail.com>
Co-authored-by: Natasha Sarkar <natashasarkar@google.com>
Co-authored-by: Cailyn Edwards <cailyn.edwards@shopify.com>
Co-authored-by: Cailyn <cailyn.s.e@gmail.com>
Co-authored-by: Katrina Verey <kn.verey@gmail.com>
Co-authored-by: Katrina Verey <katrina.verey@shopify.com>
annasong20 added a commit to annasong20/kustomize that referenced this issue Jan 12, 2023
* initial changes to rename OrgRepo to RepoPath

* changes to rename Path to KustRootPath

* addressed review comments

* addressed review comments

* docs: Add documentation for namespace transformer

Add a short description of the namespace transformer and example
usage to examples/transformerconfigs/README.md.

References: kubernetes-sigs#629
Signed-off-by: Lars Kellogg-Stedman <lars@oddbit.com>

* Localize patchesJson6902, patchesStrategicMerge, replacements (kubernetes-sigs#4904)

* Localize patchesJson6902, patchesStrategicMerge, replacements

* Address code review feedback

* Improve readability
* Remove deprecation warning check

* Load legacy kustomization fields for `localize` (kubernetes-sigs#4918)

* Load legacy kustomization

* Expose loadKustFile in kusttarget

* remove FixKustomizationPreUnmarshalling

* remove deprecated cfg and fn commands (kubernetes-sigs#4930)

* remove deprecated cfg and fn commands

* fix lint error

* run gofmt

* Localize PatchTransformer, PatchJson6902Transformer (kubernetes-sigs#4920)

* Localize patches, patchesJson6902 custom transformers

* Improve readability

* Localize fields: openapi, configurations, crds (kubernetes-sigs#4907)

* Localize openapi, configurations, crds

* Add integration test

* Move krusty test

* Address code review feedback

* Implement locRootPath (kubernetes-sigs#4909)

* Implement locRootPath, and include userinfo, port in locFilePath

* Strip userinfo, port

* Improve readability

* Localize legacy fields

* Localize resources (kubernetes-sigs#4912)

* Localize resources

* Improve readability

* Add integration tests

* Group test helper functions

* Remove Functionality that Pulls Env Variables from Empty Keys

* Update api/kv/kv.go

Co-authored-by: Katrina Verey <kn.verey@gmail.com>

* refactor Unmarshal Kustomization struct code

* improve error messages

* Run go mod tidy on all modules before update

* Update sigs.k8s.io/yaml to 1.3.0

* fixed test failure because of latest commits

Signed-off-by: Lars Kellogg-Stedman <lars@oddbit.com>
Co-authored-by: Lars Kellogg-Stedman <lars@oddbit.com>
Co-authored-by: Anna Song <annasong@google.com>
Co-authored-by: yugo kobayashi <kobdotsh@gmail.com>
Co-authored-by: Natasha Sarkar <natashasarkar@google.com>
Co-authored-by: Cailyn Edwards <cailyn.edwards@shopify.com>
Co-authored-by: Cailyn <cailyn.s.e@gmail.com>
Co-authored-by: Katrina Verey <kn.verey@gmail.com>
Co-authored-by: Katrina Verey <katrina.verey@shopify.com>
larsks added a commit to larsks/nerc-ocp-config that referenced this issue Oct 22, 2024
Configure consistent RBAC in all project-robbie namespaces:

- project-robbie-6f75ac
- project-robbie-8dd79e
- project-robbie-b4784c

These changes included custom configuration for the Kustomize namespace
transformer so that it will update the namespace for all subjects listed in
the RoleBindings. See [1] for an example configuration, and [2] for what
passes for documentation.

[1]: kubernetes-sigs/kustomize#629 (comment)
[2]: kubernetes-sigs/kustomize#4704
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/documentation Categorizes issue or PR as related to documentation.
Projects
None yet
Development

No branches or pull requests

7 participants