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
?
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