kubernetes-sigs / kustomize

Customization of kubernetes YAML configurations
Apache License 2.0
10.88k stars 2.24k forks source link

Make It Possible for "delimiter" in "replacements.target.options" to Join Array Values by a Delimiter into a Scalar #5043

Closed GuyPaddock closed 6 days ago

GuyPaddock commented 1 year ago

Eschewed features

What would you like to have added?

Given the following custom-resource Yaml:

# allowed-ingress.yaml
apiVersion: k8s.inveniem.com/v1
kind: CidrAddresses
metadata:
  name: allowed-ingress
data:
  addresses:
    - "8.67.53.09/32"
    - "192.168.0.1/32"

... I'd like a way to join all of the values under data.addresses into a comma-delimited string (e.g., for use in an nginx.ingress.kubernetes.io/whitelist-source-range annotation) using a replacement, like this:

"8.67.53.09/32,192.168.0.1/32"

For example:

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

resources:
  - allowed-ingress.yaml

replacements:
  - source:
      kind: CidrAddresses
      name: allowed-ingress
      fieldPath: data.addresses
    targets:
      - select:
          kind: Ingress
        fieldPaths:
          - metadata.annotations.[nginx.ingress.kubernetes.io/whitelist-source-range]
        options:
          create: true
          # Note the delimiter option below: 
          delimiter: ','

  - source:
      kind: CidrAddresses
      name: allowed-ingress
      fieldPath: data.addresses
    targets:
      - select:
          kind: Service
        fieldPaths:
          - spec.loadBalancerSourceRanges
        options:
          create: true

Why is this needed?

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

# allowed-ingress.yaml
apiVersion: k8s.inveniem.com/v1
kind: CidrAddresses
metadata:
  name: allowed-ingress
data:
  addressesString: "8.67.53.09/32,192.168.0.1/32"
  addressesArray:
    - "8.67.53.09/32"
    - "192.168.0.1/32"
# kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - allowed-ingress.yaml

replacements:
  - source:
      kind: CidrAddresses
      name: allowed-ingress
      fieldPath: data.addressesString
    targets:
      - select:
          kind: Ingress
        fieldPaths:
          - metadata.annotations.[nginx.ingress.kubernetes.io/whitelist-source-range]
        options:
          create: true

  - source:
      kind: CidrAddresses
      name: allowed-ingress
      fieldPath: data.addressesArray
    targets:
      - select:
          kind: Service
        fieldPaths:
          - spec.loadBalancerSourceRanges
        options:
          create: true

What other solutions have you considered?

Anything else we should know?

No response

Feature ownership

KnVerey commented 1 year ago

/triage under-consideration

I think this sounds reasonable, but I'd like to get @natasha41575 opinion on it.

jskrzypek commented 1 year ago

A coupld thoughts:

1) As a parallel, it might be useful/elegant to similarly respect a source.options.delimiter when no source.options.index is specified to split a source scalar and then pass it to targets as a slice.

2) A potentially thorny edge-case occurred to me: what do you do when the source array is not an array of scalars or is a mix of scalars and non-scalars? E.g. what happens if your source finds this:

- hello
- world
- key1: val1
  key2: val2
- - itemA
  - itemB

A potential solution could be introducing another option (perhaps coerce?) to coerce the source into a scalar if the target is a scalar, which would also make it possible to join multiple snippets to build up a scalar file when using a '\n' delimiter

buddyledungarees commented 1 year ago

Another use case for a coerce (to string) option would be if the duck typing of the reference field mistakenly treats it as a number:

replacements:
  - source:
      kind: Deployment
      fieldPath: spec.template.spec.containers.[name=mycontainer].image
      options:
        delimiter: ":"
        index: 1
    targets:
      - select:
          kind: Deployment
        fieldPaths:
          - metadata.labels.version
          - spec.template.metadata.labels.version
        options:
          create: true

This causes errors with k8s if the tag convention happens to be X.Y and due to certain metadata fields expected to be map[string]string.

k8s-triage-robot commented 1 year ago

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

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

You can:

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

/lifecycle stale

k8s-triage-robot commented 7 months ago

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:

You can:

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

/lifecycle rotten

k8s-triage-robot commented 6 months ago

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:

You can:

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

/close not-planned

k8s-ci-robot commented 6 months ago

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

In response to [this](https://github.com/kubernetes-sigs/kustomize/issues/5043#issuecomment-1950971710): >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][1] > >Please send feedback to sig-contributor-experience at [kubernetes/community](https://github.com/kubernetes/community). > >/close not-planned > >[1]: https://www.kubernetes.dev/docs/guide/issue-triage/ Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
GuyPaddock commented 6 months ago

/reopen

k8s-ci-robot commented 6 months ago

@GuyPaddock: Reopened this issue.

In response to [this](https://github.com/kubernetes-sigs/kustomize/issues/5043#issuecomment-1958678914): >/reopen Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
GuyPaddock commented 6 months ago

/remove-lifecycle rotten

k8s-triage-robot commented 3 months ago

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

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

You can:

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

/lifecycle stale

k8s-triage-robot commented 2 months ago

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:

You can:

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

/lifecycle rotten

k8s-triage-robot commented 1 month ago

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:

You can:

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

/close not-planned

k8s-ci-robot commented 1 month ago

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

In response to [this](https://github.com/kubernetes-sigs/kustomize/issues/5043#issuecomment-2241471123): >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][1] > >Please send feedback to sig-contributor-experience at [kubernetes/community](https://github.com/kubernetes/community). > >/close not-planned > >[1]: https://www.kubernetes.dev/docs/guide/issue-triage/ Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
GuyPaddock commented 1 month ago

/reopen

k8s-ci-robot commented 1 month ago

@GuyPaddock: Reopened this issue.

In response to [this](https://github.com/kubernetes-sigs/kustomize/issues/5043#issuecomment-2254636988): >/reopen Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
k8s-triage-robot commented 6 days ago

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:

You can:

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

/close not-planned

k8s-ci-robot commented 6 days ago

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

In response to [this](https://github.com/kubernetes-sigs/kustomize/issues/5043#issuecomment-2313500249): >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][1] > >Please send feedback to sig-contributor-experience at [kubernetes/community](https://github.com/kubernetes/community). > >/close not-planned > >[1]: https://www.kubernetes.dev/docs/guide/issue-triage/ Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.