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

Use replacement syntax for patch #5063

Closed
2 tasks done
b1zzu opened this issue Feb 24, 2023 · 7 comments
Closed
2 tasks done

Use replacement syntax for patch #5063

b1zzu opened this issue Feb 24, 2023 · 7 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. triage/needs-information Indicates an issue needs more information in order to work on it.

Comments

@b1zzu
Copy link

b1zzu commented Feb 24, 2023

Eschewed features

  • This issue is not requesting templating, unstuctured edits, build-time side-effects from args or env vars, or any other eschewed feature.

What would you like to have added?

I want to use the replacement syntax which is more powerful than the patchesJson6902 but without using another resource as the source.

I would like to rewrite this:

replacements:
  - source:
      version: v1
      kind: ConfigMap
      name: cluster
      namespace: default
      fieldPath: data.HOSTNAME
    targets:
      - &ingress
        select:
          group: networking.k8s.io
          version: v1
          kind: Ingress
          name: cluster-prometheus-oauth2-proxy
          namespace: default
        options:
          delimiter: .
          index: 1
      - <<: *ingress
        select:
          name: cluster-grafana-oauth2-proxy
      - &deployment
        select:
          group: apps
          version: v1
          kind: Deployment
          name: cluster-prometheus-oauth2-proxy
          namespace: default
        fieldPaths:
          - spec.template.spec.containers.[name=oauth2-proxy].env.[name=REDIRECT_HOST].value
        options:
          delimiter: .
          index: 1
      - <<: *deployment
        select:
          name: cluster-grafana-oauth2-proxy

like this:

patches:
  - target:
      group: networking.k8s.io
      version: v1
      kind: Ingress
      labelSelector: component=internal-ingress
      fieldPaths:
        - spec.tls.*.hosts.*
        - spec.rules.*.host
      options:
        delimiter: .
        index: 1
    patch: example.com
  - target:
      group: apps
      version: v1
      kind: Deployment
      labelSelector: component=oauth2-proxy-deployment
      fieldPaths:
        - spec.template.spec.containers.[name=oauth2-proxy].env.[name=REDIRECT_HOST].value
      options:
        delimiter: .
        index: 1
      patch: example.com

Why is this needed?

Keep the configuration cleaner, and leverage the labelSelector to patch multiple resources at the same time.

Can you accomplish the motivating task without this feature, and if so, how?

I can achieve the same final result using replacement and ConfigMap

What other solutions have you considered?

Post kustomize variables substitution like Flux does [1]

  1. https://fluxcd.io/flux/components/kustomize/kustomization/#variable-substitution

Anything else we should know?

No response

Feature ownership

  • I am interested in contributing this feature myself! 🎉
@b1zzu b1zzu added the kind/feature Categorizes issue or PR as related to a new feature. label Feb 24, 2023
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Feb 24, 2023
@KnVerey
Copy link
Contributor

KnVerey commented Mar 15, 2023

cc @natasha41575 as the main author of replacements, but I believe we would prefer to address any shortcomings in Replacements rather than transferring the more complex syntax to the simpler patches transformer. If I understand correctly from the following:

Keep the configuration cleaner, and leverage the labelSelector to patch multiple resources at the same time.

part of the problem you have with using replacements is label selector support in targets. The good news is that already exists! Although it seems to be missing from the docs for some reason, it was introduced in #4229 and this test case is an example of how to use it:

replacements:
- source:
    kind: Deployment
    name: deploy-1
    fieldPath: spec.template.spec.containers.0.image
  targets:
  - select:
      labelSelector: foo=bar-1
    fieldPaths:
    - spec.template.spec.containers.1.image

The other shortcoming seems to be the need to source the replacement value from a resource:

I want to use the replacement syntax which is more powerful than the patchesJson6902 but without using another resource as the source.

One thing that is already possible is to put the config.kubernetes.io/local-config: "true" annotation on your ConfigMap so that it will not appear in the kustomize build output. Would you be happy with that solution in conjunction with the labelSelector field? Alternatively, what if Replacements supported an inline value as a source?

/triage needs-information

@k8s-ci-robot k8s-ci-robot added triage/needs-information Indicates an issue needs more information in order to work on it. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Mar 15, 2023
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 13, 2023
@b1zzu
Copy link
Author

b1zzu commented Jun 20, 2023

Thanks, @KnVerey , both of your suggestions are perfect for my use case

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jul 20, 2023
@ElSamhaa
Copy link

Although the local-config should work with this scenario, I'd like to have the option to define an inline value. In some situations, a complete dedicated local-config would be a little overkill.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

@k8s-ci-robot k8s-ci-robot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 20, 2024
@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. triage/needs-information Indicates an issue needs more information in order to work on it.
Projects
None yet
Development

No branches or pull requests

5 participants