carvel-dev / kapp

kapp is a simple deployment tool focused on the concept of "Kubernetes application" — a set of resources with the same label
https://carvel.dev/kapp
Apache License 2.0
907 stars 108 forks source link

Better warning message when kapp things you gave it empty input. #249

Closed GrahamDumpleton closed 3 years ago

GrahamDumpleton commented 3 years ago

Describe the problem/challenge you have

Run:

cat resources.yaml | kapp deploy -a website -y

One will get an error message saying:

kapp: Error: Trying to apply empty set of resources will result in deletion of resources on cluster. Refusing to continue unless --dangerous-allow-empty-list-of-resources is specified.

This isn't useful in understanding the obvious mistake you likely made.

Describe the solution you'd like

Reword the message to something like:

kapp: Error: Trying to apply empty set of resources will result in deletion of resources on cluster. Did you forget to supply the -f/--file option? Refusing to continue unless --dangerous-allow-empty-list-of-resources is specified.

In other words suggest maybe the issue is they forgot to provide the -f or --file option.

In this case what was actually required was -f - and if it can detect that stdin wasn't closed but something was being piped to kapp then maybe it can be even more specific and ask if -f - was forgotten.

Anything else you would like to add:

I get confused by this message every time when I forget the -f option. :-(


Vote on this request

This is an invitation to the community to vote on issues, to help us prioritize our backlog. Use the "smiley face" up to the right of this comment to vote.

👍 "I would like to see this addressed as soon as possible" 👎 "There are other more important things to focus on right now"

We are also happy to receive and review Pull Requests if you want to help working on this issue.

cc @jorgemoralespou

GrahamDumpleton commented 3 years ago

BTW, when would -f not be a mandatory option with kapp deploy. So why shouldn't it just outright error when it is missing based on that?

cppforlife commented 3 years ago

BTW, when would -f not be a mandatory option with kapp deploy. So why shouldn't it just outright error when it is missing based on that?

that's a good point. ill have to think why isnt the case right now...

GrahamDumpleton commented 3 years ago

Another example to take into consideration when changing this.

When piping from ytt and the error is in ytt you will get:

$ ytt -f templates-v2 --data-values-file override-values.yaml | kapp deploy -a website -f - -y
ytt: Error: 
- string has no .hostname field or method
    in <toplevel>
      ingress.yaml:3 | #@ if data.values.website.ingress.hostname and data.values.website.ingress.domain:
Target cluster 'https://10.96.0.1:443'

kapp: Error: Trying to apply empty set of resources will result in deletion of resources on cluster. Refusing to continue unless --dangerous-allow-empty-list-of-resources is specified.

You aren't going to avoid the cascading errors in this case, so just need to be mindful of how changes in the message will appear in this sort of situation.

renuy commented 3 years ago

Things we are planning to do as part of this issue:

  1. Improve the warning message
  2. make atleast one -f mandatory
renuy commented 3 years ago

@cppforlife , Is the file option not mandatory, because we want to support --dangerous-allow-empty-list-of-resources?

cppforlife commented 3 years ago

because we want to support --dangerous-allow-empty-list-of-resources?

nah, that flag just indicates that its ok if given file(s) has 0 resources inside. i think i just never added a validation check for -f for no good reason.