What happened?
Using replacements on the final kustomization.yaml will correctly replace given occurrences.
Using replacements on the component that expects a resource without having it will only replace specific occurrences.
What did you expect to happen?
I would expect replacements to work even when used from the "abstract" components.
How can we reproduce it (as minimally and precisely as possible)?
#base/httproute.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: route
spec:
rules:
- backendRefs:
- name: to-be-kustomized
matches:
- path:
type: PathPrefix
value: /
#base/ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress
spec:
rules:
- http:
paths:
- backend:
service:
name: to-be-kustomized
pathType: Prefix
path: /
#base/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
resources:
- httproute.yaml
- ingress.yaml
#test/service.yaml
apiVersion: v1
kind: Service
metadata:
name: service
#test/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: prefix-
resources:
- service.yaml
components:
- ../base
Adding this code in each kustomization.yaml will produce different results
replacements:
- source:
kind: Service
fieldPath: metadata.name
targets:
- select:
kind: Ingress
fieldPaths:
- spec.rules.0.http.paths.0.backend.service.name
- select:
kind: Ingress
fieldPaths:
- spec.rules.0.http.paths.0.pathType
- select:
kind: HTTPRoute
fieldPaths:
- spec.rules.0.backendRefs.0.name
- select:
kind: HTTPRoute
fieldPaths:
- spec.rules.0.matches.0.path.type
Expected output
apiVersion: v1
kind: Service
metadata:
name: prefix-service
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: prefix-route
spec:
rules:
- backendRefs:
- name: prefix-service
matches:
- path:
type: prefix-service
value: /
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: prefix-ingress
spec:
rules:
- http:
paths:
- backend:
service:
name: prefix-service
path: /
pathType: prefix-service
All 4 occurrences of the service are correctly prefixed.
Actual output
apiVersion: v1
kind: Service
metadata:
name: prefix-service
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: prefix-route
spec:
rules:
- backendRefs:
- name: service
matches:
- path:
type: service
value: /
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: prefix-ingress
spec:
rules:
- http:
paths:
- backend:
service:
name: prefix-service
path: /
pathType: service
When the replacements section is placed inside the component file, only 1 occurence of the service is correctly prefixed.
Kustomize version
5.8.1
Operating system
Linux
What happened?
Using replacements on the final kustomization.yaml will correctly replace given occurrences.
Using replacements on the component that expects a resource without having it will only replace specific occurrences.
What did you expect to happen?
I would expect replacements to work even when used from the "abstract" components.
How can we reproduce it (as minimally and precisely as possible)?
Adding this code in each
kustomization.yamlwill produce different resultsExpected output
All 4 occurrences of the service are correctly prefixed.
Actual output
When the replacements section is placed inside the component file, only 1 occurence of the service is correctly prefixed.
Kustomize version
5.8.1
Operating system
Linux