Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patching a string with a number "converts" the number into a string #3424

Closed
emas80 opened this issue Jan 6, 2021 · 5 comments
Closed

Patching a string with a number "converts" the number into a string #3424

emas80 opened this issue Jan 6, 2021 · 5 comments

Comments

@emas80
Copy link

emas80 commented Jan 6, 2021

Describe the bug

I want to apply a patch by using patches to a field which value is a string. The patch is meant to change the value to be an integer.
The patch succeeds, but the final value is not an integer, it is a string with the value of the integer.

kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- path: pdb-patch.yaml
  target:
    kind: PodDisruptionBudget
    labelSelector: faceit-pdb=default

resources:
- my_file.yaml

pdb-patch.yaml

apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: generic-pdb
spec:
  maxUnavailable: 1

my_file.yaml

apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: championships-api
  labels:
    faceit-pdb: default
spec:
  maxUnavailable: 100%
---
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: championships-api-2
  labels:
    faceit-pdb: default
spec:
  maxUnavailable: 100%

Expected output

apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  labels:
    faceit-pdb: default
  name: championships-api
spec:
  maxUnavailable: 1
---
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  labels:
    faceit-pdb: default
  name: championships-api-2
spec:
  maxUnavailable: 1

Actual output

apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  labels:
    faceit-pdb: default
  name: championships-api
spec:
  maxUnavailable: "1"
---
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  labels:
    faceit-pdb: default
  name: championships-api-2
spec:
  maxUnavailable: "1"

Kustomize version

The problem is present in

{Version:kustomize/v3.8.4 GitCommit:8285af8cf11c0b202be533e02b88e114ad61c1a9 BuildDate:2020-09-19T15:39:21Z GoOs:linux GoArch:amd64}

and also in

{Version:kustomize/v3.9.1 GitCommit:7439f1809e5ccd4677ed52be7f98f2ad75122a93 BuildDate:2020-12-29T19:25:35Z GoOs:linux GoArch:amd64}

Platform

Linux

Additional context

Usually this is not a problem, probably, but it is a big issue with the PodDisruptionBudget which values must be integers or strings with the percentage (%).

I can't use the patchesStrategicMerge because I want to apply the same patch to multiple resources. You have to imagine that the my_file.yaml contains many PodDistruptionBudget.
I am open to any suggestions to achieve the same result in a different way.

@emas80
Copy link
Author

emas80 commented Jan 6, 2021

I forgot to mention that, probably, it was working as expected in the version 3.7.0.

We use flux and kustomize to handle the kubertetes updates, and the problem appeared when we upgraded from flux-1.20.1 to flux-1.21.

As it can be seen from https://github.com/fluxcd/flux/pull/3309/files, they went from kustomize 3.7.0 to kustomize 3.8.4

@monopole
Copy link
Contributor

monopole commented Jan 6, 2021

Thanks for the report. Likely the same underlying problem as #3412

@Shell32-Natsu
Copy link
Contributor

Close this. Please use #3412 for string quotes issue in 3.9.x.

@monopole
Copy link
Contributor

Turns out these aren't the same issues.

@monopole
Copy link
Contributor

Closed by #3438

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants