kustomize edit fix deletes trailing comments
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
/triage accepted
@ramessesii2: The label triage/accepted cannot be applied. Only GitHub organization members can add the label.
In response to this:
/triage accepted
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
I'd like to work on it if somebody could please assign it to me. cc @exocode
/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.
/assign
Thanks @natasha41575, those are good pointers.
@ramessesii2 I've a hack code to tackle the issue at #5180. It would be great if you have any suggestions. :)
Thanks @wingyplus for the PR, I've been rather busy with my work.
/assign
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.
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
/assign
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.
This issue has not been updated in over 1 year, and should be re-triaged.
You can:
- Confirm that this issue is still relevant with
/triage accepted(org members only) - Close this issue with
/close
For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/
/remove-triage accepted
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closed
You can:
- Mark this issue as fresh with
/remove-lifecycle stale - Close this issue with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closed
You can:
- Mark this issue as fresh with
/remove-lifecycle rotten - Close this issue with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closed
You can:
- Reopen this issue with
/reopen - Mark this issue as fresh with
/remove-lifecycle rotten - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/close not-planned
@k8s-triage-robot: Closing this issue, marking it as "Not Planned".
In response to this:
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied- After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied- After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closedYou can:
- Reopen this issue with
/reopen- Mark this issue as fresh with
/remove-lifecycle rotten- Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/close not-planned
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.