kptdev / kpt

Automate Kubernetes Configuration Editing
https://kpt.dev
Apache License 2.0
1.7k stars 228 forks source link

create-setters adds incorrect comments #2199

Open mortent opened 3 years ago

mortent commented 3 years ago

The input resources are:

dep.yaml:

apiVersion: v1
kind: MyKind
metadata:
  name: foo
environments:
  - dev
  - stage

cm.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
  name: create-setters-fn-config
data:
  name: foo
  env: |
    - dev
    - stage
    - foo

Running the following command:

kpt fn eval --image gcr.io/kpt-fn/create-setters:v0.1 --fn-config ./cm.yaml

The result is:

cm.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: create-setters-fn-config
data:
  name: foo # kpt-set: ${name}
  env: | # kpt-set: - dev
    # - stage
    # - ${name}
    - dev
    - stage
    - foo

dep.yaml:

apiVersion: v1
kind: MyKind
metadata:
  name: foo # kpt-set: ${name}
environments:
  - dev
  - stage

The comments added to the env list does not look correct.

phanimarupaka commented 3 years ago

I think this surfaces 2 separate issues.

  1. kpt fn eval --image foo --fn-config fn-config.yaml should not modify fn-config.yaml file even if it is within the package. @droot @Shell32-Natsu fn-config file should not be modified correct ?

  2. create-setters doesn't work well with parameterizing wrapped strings. I think we should not support parameterizing wrapped strings in general as dealing with multiline comments is difficult.