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

error when running kpt fns against a package containing kustomization.yaml #2171

Closed
ryane opened this issue Jun 5, 2021 · 4 comments
Closed
Assignees
Labels
area/hydrate bug Something isn't working customer deep engagement triaged Issue has been triaged by adding an `area/` label

Comments

@ryane
Copy link

ryane commented Jun 5, 2021

Expected behavior

Running functions like set-labels, set-annotations, and set-namespace should work correctly in a package that contains a kustomization.yaml.

Actual behavior

The functions fail with an error like:

$ kpt fn render . 
Package "kpt-test":
[RUNNING] "gcr.io/kpt-fn/set-labels:v0.1"
[FAIL] "gcr.io/kpt-fn/set-labels:v0.1"
  Results:
    [ERROR] failed to run function: missing metadata.name in object {map[apiVersion:kustomize.config.k8s.io/v1beta1 kind:Kustomization metadata:map[annotations:map[config.k8s.io/id:2 config.kubernetes.io/index:0 config.kubernetes.io/path:kustomization.yaml]] resources:[deploy.yaml]]}
  Stderr:
    "[error] /// : failed to run function: missing metadata.name in object {map[apiVersion:kustomize.config.k8s.io/v1beta1 kind:Kustomization metadata:map[annotations:map[config.k8s.io/id:2 config.kubernetes.io/index:0 config.kubernetes.io/path:kustomization.yaml]] resources:[deploy.yaml]]}"
  Exit code: 1

Information

$ kpt version
1.0.0-alpha.5
$ kustomize version
{Version:kustomize/v4.1.3 GitCommit:0f614e92f72f1b938a9171b964d90b197ca8fb68 BuildDate:2021-05-20T20:52:40Z GoOs:linux GoArch:amd64}

Steps to reproduce the behavior

In an empty directory:

$ kubectl create deploy nginx --image nginx --dry-run=client -oyaml > deploy.yaml
$ kustomize create
$ kustomize edit add resource deploy.yaml
$ kustomize build | kpt pkg tree
kpt-test-2
├── [deploy.yaml]  Deployment nginx
└── [kustomization.yaml]  Kustomization
$ kpt pkg init .
writing Kptfile
writing README.md
$ kpt fn render .
Package "kpt-test-2":
Successfully executed 0 function(s) in 1 package(s).
$ kpt fn eval . --image gcr.io/kpt-fn/set-namespace:v0.1 -- namespace=nginx                                                                                      [9:51:35]
[RUNNING] "gcr.io/kpt-fn/set-namespace:v0.1"
[FAIL] "gcr.io/kpt-fn/set-namespace:v0.1"
  Results:
    [ERROR] failed to run function: missing metadata.name in object {map[apiVersion:kustomize.config.k8s.io/v1beta1 kind:Kustomization metadata:map[annotations:map[config.k8s.io/id:2 config.kubernetes.io/index:0 config.kubernetes.io/path:kustomization.yaml]] resources:[deploy.yaml]]}
  Stderr:
    "[error] /// : failed to run function: missing metadata.name in object {map[apiVersion:kustomize.config.k8s.io/v1beta1 kind:Kustomization metadata:map[annotations:map[config.k8s.io/id:2 config.kubernetes.io/index:0 config.kubernetes.io/path:kustomization.yaml]] resources:[deploy.yaml]]}"
  Exit code: 1
$ mv kustomization.yaml kustomization.yaml.bak

$ kpt fn eval . --image gcr.io/kpt-fn/set-namespace:v0.1 -- namespace=nginx                                                                                      [9:54:28]
[RUNNING] "gcr.io/kpt-fn/set-namespace:v0.1"
[PASS] "gcr.io/kpt-fn/set-namespace:v0.1"

Same errors if I invoke functions declaratively or use the unstable tag. So far, I get the errors with set-labels, set-annotations, and set-namespace. apply-setters does not seem to be affected. I haven't tried others.

@ryane ryane added the bug Something isn't working label Jun 5, 2021
@droot droot added this to the v1.0 m3 milestone Jun 7, 2021
@droot
Copy link
Contributor

droot commented Jun 7, 2021

@ryane these functions require resources to be a valid KRM resource (must have a valid apiVersion, kind and metadata.name fields). So adding metadata.name will resolve that.

Can you share more what is the scenario here ? how are you planning to use kustomize here ?

@natasha41575 natasha41575 added the customer deep engagement label Jun 7, 2021
@natasha41575
Copy link
Contributor

@ryane If you are able, we are still interested in knowing more about your use case. We have a few ideas for solutions, but in order to properly resolve this issue we'd like to know more about how you are planning to use kustomize here.

@mikebz mikebz added the triaged Issue has been triaged by adding an `area/` label label Jun 10, 2021
@ryane
Copy link
Author

ryane commented Jun 12, 2021

So adding metadata.name will resolve that

This was actually the first thing I tried but it broke the (admittedly old) version of kustomize we are on (unknown field "metadata"). However, this prompted me to double check and I see that more recent versions of kustomize now allow you to set metadata. Thanks!

Although we are not currently using live, our use of kpt + kustomize has a lot of similarities to what is described in #1545. We have built (pre-1.0-alpha) kpt packages that have setters to configure patches, transformers, components, etc. for pre-existing kustomize bases (that we may or may not control).

@natasha41575
Copy link
Contributor

@ryane Thanks for getting back to us! I'm glad setting metadata worked for you. I'm going to close this issue as resolved, but feel free to reopen if you have more to discuss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hydrate bug Something isn't working customer deep engagement triaged Issue has been triaged by adding an `area/` label
Projects
None yet
Development

No branches or pull requests

4 participants