kubernetes-sigs / kubernetes-sigs/kustomize
In `replacements`, the type of source value is not retained when the target fieldPath is not existent an configured with `option.create: true`
- Dominant language
- Go
- Stars
- 12.2k
- Forks
- 2.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 25
Description
### What happened?
I'm trying to override an environment variable that might or might not exist in the base. I'm using a local config as a source with the numeric value as a string.
When the base happens to have that overridden environment variable defined, it retains the type right. However, whenever the base is missing the environment variable, the env is created with the numeric value as an integer; not as a string like in the source field.
### What did you expect to happen?
The type of the source value should be retained under all conditions.
### How can we reproduce it (as minimally and precisely as possible)?
```yaml
# resources.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: local-config
annotations:
config.kubernetes.io/local-config: "true"
data:
ENV_TEST: "10"
---
apiVersion: v1
kind: Pod
metadata:
name: test
spec:
containers:
- image: alpine
name: test
```
```yaml
# kustomization.yaml
resources:
- resources.yaml
replacements:
- source:
kind: ConfigMap
name: local-config
fieldPath: data.ENV_TEST
targets:
- select:
kind: Pod
options:
create: true
fieldPaths:
- spec.containers.[name=test].env.[name=TEST].value
```
### Expected output
```yaml
apiVersion: v1
kind: Pod
metadata:
name: test
spec:
containers:
- env:
- name: TEST
value: "10"
image: alpine
name: test
```
### Actual output
```yaml
apiVersion: v1
kind: Pod
metadata:
name: test
spec:
containers:
- env:
- name: TEST
value: 10 # the value type is integer; does not match the type in the source (string)
image: alpine
name: test
```
### Kustomize version
v5.3.0
### Operating system
MacOS
Contributor guide
Research direction
Run the reproduction using resources.yaml and kustomization.yaml, focusing on replacements with options.create: true when the target fieldPath is absent. Trace how the source value is copied into the newly created field and verify that the generated Pod preserves ENV_TEST as the string "10" rather than the integer 10.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100