Skip to content

Replacements: better support for targeting --key=value container args #4080

@marshall007

Description

@marshall007

Is your feature request related to a problem? Please describe.

A huge value-add to using replacements over traditional JSON patches is the ability to use [key=value] selectors in field paths. This makes your patches much more robust since the alternative relies on array field ordering. Unfortunately, this is still true when the field path value is a simple string array... most notably in the case of container args.

Describe the solution you'd like

In situations like the following, it would be ideal if we could reliably replace the value of --leader-election-namespace:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: cert-manager
spec:
  template:
    spec:
      containers:
      - name: cert-manager
        image: quay.io/jetstack/cert-manager-controller:v1.2.0
        args:
        - --v=2
        - --default-issuer-kind=ClusterIssuer
        - --leader-election-namespace=kube-system
# ...
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: cert-manager-cainjector
spec:
  template:
    spec:
      containers:
      - name: cert-manager
        image: quay.io/jetstack/cert-manager-cainjector:v1.2.0
        args:
        - --v=2
        - --leader-election-namespace=kube-system
# ...

I'm not sure how we would represent this in the replacements API, but it could look something like:

replacements:
- source:
    kind: Role
    name: cert-manager-cainjector:leaderelection
    fieldPath: metadata.namespace
  targets:
  - select:
      kind: Deployment
    fieldPaths:
    - spec.template.spec.containers.[name=cert-manager].args
    options:
      prefix: "--leader-election-namespace="

The new rules would be:

  • index and delimiter options can only be specified on scalar values and lists consisting only of string values
  • when prefix and/or suffix options are specified,
    • the value is only replaced if it contains the specified prefix and suffix
    • the matched prefix and/or suffix is preserved in the resulting value
    • when used in conjunction with delimiter, only the unprefixed/suffixed portion of the string is split

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueDenotes an issue ready for a new contributor, according to the "help wanted" guidelines.help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions