kubernetes-sigs / kustomize

Customization of kubernetes YAML configurations
Apache License 2.0
11.09k stars 2.26k forks source link

kustomize edit fix deletes trailing comments #5158

Open exocode opened 1 year ago

exocode commented 1 year ago

What happened?

running command kustomize edit fix changes

---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: demo
bases:
  - ../../base
patchesStrategicMerge:
  - ./deployment.yaml
# resources:
# - ./ingress-t2.yaml
# - ./middleware-frontend-t2.yaml
# - ./middleware-backend-t2.yaml

to

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: demo
resources:
- ../../base
patches:
- path: ./deployment.yaml

What did you expect to happen?

it should keep comments untouched

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

# kustomization.yaml
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: demo
bases:
  - ../../base
patchesStrategicMerge:
  - ./deployment.yaml
# resources:
# - ./ingress-t2.yaml
# - ./middleware-frontend-t2.yaml
# - ./middleware-backend-t2.yaml

run

kustomize edit fix

Expected output

# kustomization.yaml
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: demo
resources:
- ../../base
patches:
- path: ./deployment.yaml
# resources:
# - ./ingress-t2.yaml
# - ./middleware-frontend-t2.yaml
# - ./middleware-backend-t2.yaml

Actual output

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: demo
resources:
- ../../base
patches:
- path: ./deployment.yaml

Kustomize version

v5.0.1

Operating system

MacOS

ramessesii2 commented 1 year ago

/triage accepted

k8s-ci-robot commented 1 year ago

@ramessesii2: The label triage/accepted cannot be applied. Only GitHub organization members can add the label.

In response to [this](https://github.com/kubernetes-sigs/kustomize/issues/5158#issuecomment-1539409395): >/triage accepted 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.
ramessesii2 commented 1 year ago

I'd like to work on it if somebody could please assign it to me. cc @exocode

natasha41575 commented 1 year ago

/triage accepted /kind bug

@ramessesii2 There is some comment-preservation related code in kyaml that you might find useful while you are trying to fix this. I believe there is literally a function you can use called CopyComments somewhere. Please feel free to reach out if you need more help. You can also assign yourself the issue by leaving a comment /assign.

ramessesii2 commented 1 year ago

/assign

Thanks @natasha41575, those are good pointers.

wingyplus commented 1 year ago

@ramessesii2 I've a hack code to tackle the issue at #5180. It would be great if you have any suggestions. :)

ramessesii2 commented 1 year ago

Thanks @wingyplus for the PR, I've been rather busy with my work.

wingyplus commented 1 year ago

/assign

annasong20 commented 1 year ago

Renamed the issue to clarify that kustomize edit fix does currently preserve comments, as demonstrated by tests in kustomize/commands/internal/kustfile. The command just doesn't preserve trailing comments.

cdenneen commented 1 year ago

This also happens when you have comments at the end of a line:

images:
- name: imageone
  newName: registry.jfrog.io/docker/imageone # {"$imagepolicy": "platform-flux-tenant-config:imageone:name"}
  newTag: craft-4-957db1b2-1689262100 # {"$imagepolicy": "platform-flux-tenant-config:imageone:tag"}

->

images:
- name: imageone
  newName: registry.jfrog.io/docker/imageone
  newTag: craft-4-957db1b2-1689262100
adzshaf commented 1 year ago

/assign

wingyplus commented 1 year ago

Hi @adzshaf, if you would like to take over this issue. I have a question that I cannot figure out in https://github.com/kubernetes-sigs/kustomize/pull/5180. Hope this could be help.

k8s-triage-robot commented 3 months ago

This issue has not been updated in over 1 year, and should be re-triaged.

You can:

For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/

/remove-triage accepted

k8s-triage-robot commented 6 days ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale