1

Since vars is deprecated from Kustomize 5.0.0, I start to migrate to replacements by following official recomendation.
But I can't figured out how to replace HTTPRoute/backendRefs.name by using replacements.

My code is following. Those 2 yamls are at same directory.

main.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: foooooooooooooooo
  name: service
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  labels:
    app: WANT_TO_REPLACE_THIS
  name: route
spec:
  hostnames:
    - "*"
  rules:
    - backendRefs:
        - name: WANT_TO_REPLACE_THIS
          port: 3000
      matches:
        - path:
            type: PathPrefix
            value: /path

kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - main.yaml
replacements:
  - source:
      kind: Service
      name: service
      fieldPath: metadata.labels.app
    targets:
      - select:
          kind: HTTPRoute
          name: route
        fieldPaths:
          - metadata.labels.app
          - spec.rules.[backendRefs.name=WANT_TO_REPLACE_THIS].backendRefs.[name=WANT_TO_REPLACE_THIS].name

Then run kustomize build command, and result is following.

apiVersion: v1
kind: Service
metadata:
  labels:
    app: foooooooooooooooo
  name: service
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  labels:
    app: foooooooooooooooo
  name: route
spec:
  hostnames:
  - '*'
  rules:
  - backendRefs:
    - name: WANT_TO_REPLACE_THIS
      port: 3000
    matches:
    - path:
        type: PathPrefix
        value: /path

medtadata.labels.app is replaced but spec.rules.backendRefs.name isn't. Is there any way to replace spec.rules.backendRefs.name?

akrsum
  • 117
  • 7
  • You can check this link[1]. It was shown that you can use patch for this one. [1]https://stackoverflow.com/questions/66568194/kustomize-how-to-replace-only-the-host-in-ingress-configuration – Yvan G. Apr 12 '23 at 17:41
  • Thank you for your answer, It seems very useful! I got an answer from official github issue, so I'm going to post it and mark as resolved. – akrsum Apr 13 '23 at 08:37

1 Answers1

0

From official GitLab issue, I got an answer about it.

To replace it, I have to replace

spec.rules.[backendRefs.name=WANT_TO_REPLACE_THIS].backendRefs.[name=WANT_TO_REPLACE_THIS].name

to

spec.rules.*.backendRefs.[name=WANT_TO_REPLACE_THIS].name
akrsum
  • 117
  • 7