kubernetes-sigs / kustomize

Customization of kubernetes YAML configurations
Apache License 2.0
10.96k stars 2.24k forks source link

`replacements` changes string to scientific notation float #5338

Open ozooxo opened 1 year ago

ozooxo commented 1 year ago

What happened?

I have a replacements in my Kustomize setup, to retrieve image version from Deployment and patch it to a metadata label. However, Kustomize changes my version 20230921.12345678 to a scientific notation of 2.023092112345678e+07.

https://github.com/ozooxo/kustomize-replacements-potential-bug is the code to reproduce it. Screenshot 2023-09-21 at 7 40 14 PM

What did you expect to happen?

We should expect

app.kubernetes.io/version: 20230921.12345678

instead of

app.kubernetes.io/version: 2.023092112345678e+07

How can we reproduce it (as minimally and precisely as possible)?

git clone git@github.com:ozooxo/kustomize-replacements-potential-bug.git
cd kustomize-replacements-potential-bug
kustomize build --enable-helm '--load-restrictor=LoadRestrictionsNone' .

Expected output

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/version: FOOBAR
  name: app
spec:
  template:
    spec:
      containers:
      - image: foobar:20230921.12345678
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  labels:
    app.kubernetes.io/version: 20230921.12345678
  name: ingress

Actual output

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/version: FOOBAR
  name: app
spec:
  template:
    spec:
      containers:
      - image: foobar:20230921.12345678
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  labels:
    app.kubernetes.io/version: 2.023092112345678e+07
  name: ingress

Kustomize version

My local environment is with Kustomize 4.5.5, and Helm 3.9.0.

This seems still a problem with Kustomize 5.0.1 and Helm 3.12.3 (tested in docker with the highest version I can find, and got same output).

docker run -v .:/code -it --entrypoint /bin/sh k8s.gcr.io/kustomize/kustomize:v5.0.1

apk add --no-cache curl~=8 curl-dev~=8 tar~=1
curl 'https://get.helm.sh/helm-v3.12.3-linux-amd64.tar.gz' -o 'helm-v3.12.3-linux-amd64.tar.gz'
tar -zxvf helm-v3.12.3-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin

kustomize build --enable-helm '--load-restrictor=LoadRestrictionsNone' /code

Operating system

MacOS

k8s-ci-robot commented 1 year ago

This issue is currently awaiting triage.

SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
DiptoChakrabarty commented 1 year ago

checked up on this and it seems to deliver this issue on certain ranges of integer tags

for such cases it does not work

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/version: FOOBAR
  name: app
spec:
  template:
    spec:
      containers:
      - image: foobar:10.129091212
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  labels:
    app.kubernetes.io/version: 10.129091212
  name: ingress

cases similar to below it displays the issue

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/version: FOOBAR
  name: app
spec:
  template:
    spec:
      containers:
      - image: foobar:1012313123.129091212
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  labels:
    app.kubernetes.io/version: 1.0123131231290913e+09
  name: ingress

for string based values it does not show the issue

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/version: FOOBAR
  name: app
spec:
  template:
    spec:
      containers:
      - image: foobar:appdev
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  labels:
    app.kubernetes.io/version: appdev
  name: ingress
natasha41575 commented 8 months ago

/triage accepted

I think this is a valid issue and kustomize should try not to modify strings in this way. However, I have a suspicion that the root cause of this issue is in a yaml library that kustomize is consuming, so I am not sure how much we can actually control in kustomize.

If anyone is interested in fixing this, please feel free to find the root cause. If it is an issue with the yaml library, you can submit a fix upstream and see if they accept it.

k8s-ci-robot commented 8 months ago

@natasha41575: The label(s) triage/accept cannot be applied, because the repository doesn't have them.

In response to [this](https://github.com/kubernetes-sigs/kustomize/issues/5338#issuecomment-1896287777): >/triage accept > >I think this is a valid issue and kustomize should try not to modify strings in this way. However, I have a suspicion that the root cause of this issue is in a yaml library that kustomize is consuming, so I am not sure how much we can actually control in kustomize. > >If anyone is interested in fixing this, please feel free to find the root cause. If it is an issue with the yaml library, you can submit a fix upstream and see if they accept it. Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.