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

gcr.io/kpt-fn/set-namespace deletes comments in file #1815

Closed
howardjohn opened this issue Apr 25, 2021 · 14 comments
Closed

gcr.io/kpt-fn/set-namespace deletes comments in file #1815

howardjohn opened this issue Apr 25, 2021 · 14 comments
Assignees
Labels
area/fn-catalog Functions Catalog bug Something isn't working customer deep engagement p1 size/M 2 day triaged Issue has been triaged by adding an `area/` label

Comments

@howardjohn
Copy link
Contributor

Start with file:

# This object and its stored inventory is subsequently
# used to calculate the set of objects to automatically
# delete (prune), when an object is omitted from further
# applies. When applied, this "inventory object" is also
# used to identify the entire set of objects to delete.
#
# NOTE: The name of this inventory template file
# does NOT have any impact on group-related functionality
# such as deletion or pruning.
#
apiVersion: v1 # NOTE: auto-generated. Some fields should NOT be modified.
kind: ConfigMap
metadata:
  # DANGER: Do not change the inventory object namespace.
  # Changing the namespace will cause a loss of continuity
  # with previously applied grouped objects. Set deletion
  # and pruning functionality will be impaired.
  namespace: metallb-system
  # NOTE: The name of the inventory object does NOT have
  # any impact on group-related functionality such as
  # deletion or pruning.
  name: inventory-82029660
  labels:
    # DANGER: Do not change the value of this label.
    # Changing this value will cause a loss of continuity
    # with previously applied grouped objects. Set deletion
    # and pruning functionality will be impaired.
    cli-utils.sigs.k8s.io/inventory-id: e947bb0e-56f3-450c-96ed-8c5ecff10017

Run:
kpt fn run --image gcr.io/kpt-functions/set-namespace .

Results:

diff --git a/inventory-template.yaml b/inventory-template.yaml
index f40ca14..398c152 100644
--- a/inventory-template.yaml
+++ b/inventory-template.yaml
@@ -1,5 +1,3 @@
-# This object and its stored inventory is subsequently
-# used to calculate the set of objects to automatically
 # delete (prune), when an object is omitted from further
 # applies. When applied, this "inventory object" is also
 # used to identify the entire set of objects to delete.

Run again:

diff --git a/inventory-template.yaml b/inventory-template.yaml
index f40ca14..28e9ded 100644
--- a/inventory-template.yaml
+++ b/inventory-template.yaml
@@ -1,7 +1,3 @@
-# This object and its stored inventory is subsequently
-# used to calculate the set of objects to automatically
-# delete (prune), when an object is omitted from further
-# applies. When applied, this "inventory object" is also
 # used to identify the entire set of objects to delete.
 #
 # NOTE: The name of this inventory template file

kpt version is 0.39.2`.

I am not sure if this is a bug with set-namespaces or kpt in general.

@mikebz mikebz added this to To do in kpt kanban board via automation Apr 26, 2021
@mikebz mikebz added the area/fn-catalog Functions Catalog label Apr 26, 2021
@mikebz mikebz added bug Something isn't working customer deep engagement triaged Issue has been triaged by adding an `area/` label labels Apr 26, 2021
@mikebz
Copy link
Contributor

mikebz commented Apr 26, 2021

@mengqiy can you please take a look?

@Shell32-Natsu
Copy link
Contributor

Looks like function gcr.io/kpt-functions/set-namespace is old set-namespace function.

@howardjohn
Copy link
Contributor Author

I am not 100% sure but with some brief testing it seems like it may happen with any function, or at least another function (https://github.com/mgoltzsche/khelm) has the same issue.

@mikebz mikebz moved this from To do to In progress in kpt kanban board Apr 26, 2021
@mengqiy
Copy link
Contributor

mengqiy commented Apr 26, 2021

I think this has been fixed in GoogleContainerTools/kpt-functions-catalog#222.
@howardjohn Can you please try to use image gcr.io/kpt-fn/set-namespace:v0.1 which is our latest image

@howardjohn
Copy link
Contributor Author

gcr.io/kpt-fn/set-namespace:v0.1 seems to have an even more critical issue - it deletes all my files with config.kubernetes.io/local-config: "true" configs (including the file actually declaratively configuring set-namespace to run!).

It also seems a lot more destructive, completely re-ordering the YAML which has the side effect of massive diffs and some removed comments (when the comment is on the same line as yaml, like a: b # comment)

@mengqiy
Copy link
Contributor

mengqiy commented Apr 28, 2021

it deletes all my files with config.kubernetes.io/local-config: "true" configs (including the file actually declaratively configuring set-namespace to run!).

A work around is separate the sources and fn configs by directories. And then use kpt fn run --fn-path fn-config/ resources/.

The docs related to config.kubernetes.io/local-config:

It's not very clear to me what is the desired behavior for kpt fn and functions when dealing with config.kubernetes.io/local-config: "true". @droot @frankfarzan @Shell32-Natsu Can you someone clarify it?

If the function config object is in items of the input resourceList, gcr.io/kpt-fn/set-namespace:v0.1 currently will NOT output it in items in the output resourceList.
Current behavior is not a problem for the new kpt fn UX, but it can be a problem for existing kpt (v0.39.x) when the resources and fn configs are not separated by directories.

@frankfarzan We should standardize if functions should drop its fn config from resourceList.items. WDYT?

completely re-ordering the YAML which has the side effect of massive diffs and some removed comments (when the comment is on the same line as yaml, like a: b # comment)

This formatting issue may happen. We are working on a "format" function in GoogleContainerTools/kpt-functions-catalog#242. We will recommend our users to always use it as the last one in the mutators.

some removed comments (when the comment is on the same line as yaml, like a: b # comment)

@howardjohn Can you please provide steps to reproduce this? e.g. example resources.

@mikebz
Copy link
Contributor

mikebz commented May 4, 2021

pipeline-validate example is a good repro of disappearing files:

~/kpt/package-examples/pipeline-validate » kpt fn render .

@mengqiy
Copy link
Contributor

mengqiy commented May 10, 2021

We have found the root cause of why pipeline-validate package is not working as expected:
#1933

@mengqiy mengqiy moved this from In progress to To do in kpt kanban board May 11, 2021
@mengqiy mengqiy changed the title gcr.io/kpt-functions/set-namespace deletes comments in file gcr.io/kpt-fn/set-namespace deletes comments in file May 25, 2021
@mikebz mikebz added the p1 label May 25, 2021
@mikebz mikebz added this to the v1.0 m3 milestone May 25, 2021
@mengqiy mengqiy added the size/M 2 day label May 26, 2021
@mengqiy
Copy link
Contributor

mengqiy commented May 27, 2021

I didn't find any existing functions deleting comments in the catalog. I created some test cases to ensure that in GoogleContainerTools/kpt-functions-catalog#324

@mikebz
Copy link
Contributor

mikebz commented May 27, 2021

thanks for taking a look and adding tests to make sure we don't have these problems in the future!

@mengqiy
Copy link
Contributor

mengqiy commented May 27, 2021

Currently all of our mutator functions are written in golang. They works fine.
But it appears there is an issue when a mutator function is written with the TS SDK. It is tracked in #2069

@mengqiy
Copy link
Contributor

mengqiy commented May 27, 2021

The work about functions should not drop resources with local-config is tracked in #1933

@mengqiy
Copy link
Contributor

mengqiy commented Jun 4, 2021

kpt copies comments from input to output after running the functions. However, we found some bugs and they are being fixed in PR kubernetes-sigs/kustomize#3965.
We will need to upgrade kpt's kyaml dependency to pick up the fix.

@mengqiy mengqiy moved this from In Review to In progress in kpt kanban board Jun 8, 2021
@mengqiy
Copy link
Contributor

mengqiy commented Jun 10, 2021

With #2169 merged, we can close this.

@mengqiy mengqiy closed this as completed Jun 10, 2021
kpt kanban board automation moved this from In progress to Done Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/fn-catalog Functions Catalog bug Something isn't working customer deep engagement p1 size/M 2 day triaged Issue has been triaged by adding an `area/` label
Projects
Development

Successfully merging a pull request may close this issue.

4 participants