Skip to content

Replacement with regex support for selectors #5862

Open
@sda399

Description

@sda399

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 would like to add regex support in replacement selectors

Update 2025-03-01:
We should be able to select or reject multiple objects, in a single selector block.
Source selection should not be affected, no regex support.
The options' block behaviour is unchanged:
- if multiple targets are found with regex, same options should apply to all matching targets. As declared in the target block.
- regex does not apply for source object selection, thus options behaviour remains the same.

Why is this needed?

Supporting regex in replacement selectors would:

  • reduce redundancy of replacement blocks, by targeting multiple objects with regex
  • harmonize replacement selectors with the patch selectors that already support regex
  • make it possible to migrate from patches to replacements

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

example: replace image tag using deploy1 into depoly2, st1 and st2:

apiVersion: v1
kind: Deployment
metadata:
  name: deploy1
spec:
  template:
    spec:
      containers:
      - image: nginx:1.27.4
        name: nginx-tagged
---
apiVersion: v1
kind: Deployment
metadata:
  name: deploy2
spec:
  template:
    spec:
      containers:
      - image: nginx:1.5
        name: nginx-tagged
---
apiVersion: v1
kind: Statefulset
metadata:
  name: st1
spec:
  template:
    spec:
      containers:
      - image: nginx:1.5
        name: nginx-tagged
---
apiVersion: v1
kind: Statefulset
metadata:
  name: st2
spec:
  template:
    spec:
      containers:
      - image: nginx:1.5
        name: nginx-tagged

current solution:

replacements:
- source:
    kind: Deployment
    name: deploy1
    fieldPath: spec.template.spec.containers.0.image
  targets:
  - select:
      kind: Deployment
      name: deploy2
    fieldPaths:
    - spec.template.spec.containers.0.image
  - select:
      kind: StatefulSet
      name: st1
    fieldPaths:
    - spec.template.spec.containers.0.image
 - select:
      kind: StatefulSet
      name: st2
    fieldPaths:
    - spec.template.spec.containers.0.image

What other solutions have you considered?

proposed solution:

replacements:
- source:
    kind: Deployment
    name: deploy1
    fieldPath: spec.template.spec.containers.0.image
  targets:
  - select:
      kind: Deployment|StatefulSet
      name: deploy2|st.*
    fieldPaths:
    - spec.template.spec.containers.0.image

Anything else we should know?

No response

Feature ownership

  • I am interested in contributing this feature myself! 🎉

Metadata

Metadata

Assignees

Labels

kind/featureCategorizes issue or PR as related to a new feature.lifecycle/frozenIndicates that an issue or PR should not be auto-closed due to staleness.triage/under-consideration

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions