kapp icon indicating copy to clipboard operation
kapp copied to clipboard

Improve --json behaviour with interactive prompts

Open GrahamDumpleton opened this issue 3 years ago • 3 comments

What steps did you take:

Create an example.yaml file containing:

apiVersion: v1
kind: ConfigMap
metadata:
  name: xxx
data:
  xyz: abc

Run:

kapp deploy -a website -f example.yaml --json

What happened:

It appeared to crash and generate a Golang stack trace.

{
    "Tables": [
        {
            "Content": "",
            "Header": {
                "age": "Age",
                "conditions": "Conds.",
                "kind": "Kind",
                "name": "Name",
                "namespace": "Namespace",
                "op": "Op",
                "op_strategy": "Op st.",
                "reconcile_info": "Ri",
                "reconcile_state": "Rs",
                "wait_to": "Wait to"
            },
            "Rows": [
                {
                    "age": "",
                    "conditions": "",
                    "kind": "ConfigMap",
                    "name": "xxx",
                    "namespace": "lab-carvel-ytt-01-w01-s002",
                    "op": "create",
                    "op_strategy": "",
                    "reconcile_info": "",
                    "reconcile_state": "",
                    "wait_to": "reconcile"
                }
            ],
            "Notes": [
                "Op:      1 create, 0 delete, 0 update, 0 noop",
                "Wait to: 1 reconcile, 0 delete, 0 noop"
            ]
        }
    ],
    "Blocks": null,
    "Lines": [
        "Target cluster 'https://10.96.0.1:443'"
    ]
}panic: Cannot ask for confirmation in JSON UI

goroutine 1 [running]:
github.com/cppforlife/go-cli-ui/ui.(*JSONUI).AskForConfirmation(0xc0003daa00, 0x1535358, 0xc000cad1d0)
        github.com/cppforlife/[email protected]/ui/json_ui.go:114 +0x39
github.com/cppforlife/go-cli-ui/ui.(*ConfUI).AskForConfirmation(0xc0003ebd80, 0xc0001be140, 0xc0000791a0)
        github.com/cppforlife/[email protected]/ui/conf_ui.go:105 +0x33
github.com/k14s/kapp/pkg/kapp/cmd/app.(*DeployOptions).Run(0xc00012cc80, 0x0, 0x0)
        github.com/k14s/kapp/pkg/kapp/cmd/app/deploy.go:171 +0xc8f
github.com/k14s/kapp/pkg/kapp/cmd/app.NewDeployCmd.func1(0xc00013f340, 0xc00007df90, 0x0, 0x5, 0xc000374580, 0x1527ef0)
        github.com/k14s/kapp/pkg/kapp/cmd/app/deploy.go:54 +0x2a
github.com/k14s/kapp/pkg/kapp/cmd.NewKappCmd.func1.1(0xc00013f340, 0xc00007df90, 0x0, 0x5, 0x0, 0x0)
        github.com/k14s/kapp/pkg/kapp/cmd/kapp.go:126 +0xb8
github.com/cppforlife/cobrautil.WrapRunEForCmd.func1.1(0xc00013f340, 0xc00007df90, 0x0, 0x5, 0x0, 0x0)
        github.com/cppforlife/[email protected]/misc.go:45 +0xb2
github.com/cppforlife/cobrautil.WrapRunEForCmd.func1.1(0xc00013f340, 0xc00007df90, 0x0, 0x5, 0x0, 0x0)
        github.com/cppforlife/[email protected]/misc.go:45 +0xb2
github.com/cppforlife/cobrautil.WrapRunEForCmd.func1.1(0xc00013f340, 0xc00007df90, 0x0, 0x5, 0x0, 0x0)
        github.com/cppforlife/[email protected]/misc.go:45 +0xb2
github.com/spf13/cobra.(*Command).execute(0xc00013f340, 0xc00007df40, 0x5, 0x5, 0xc00013f340, 0xc00007df40)
        github.com/spf13/[email protected]/command.go:850 +0x472
github.com/spf13/cobra.(*Command).ExecuteC(0xc00013e580, 0xc00013e580, 0xc0003ebd80, 0x7f73f8ce0108)
        github.com/spf13/[email protected]/command.go:958 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/[email protected]/command.go:895
main.nonExitingMain(0x0, 0x0)
        github.com/k14s/kapp/cmd/kapp/kapp.go:42 +0x167
main.main()
        github.com/k14s/kapp/cmd/kapp/kapp.go:21 +0x26

What did you expect:

Am not sure. I was trying to work out what the --json option actually did when it occurred, so not sure if this is expected and normal, but it sort of looks wrong.

Anything else you would like to add:

Nope.

Environment:

$ kapp --version
kapp version 0.37.0

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 avatar Jul 15 '21 01:07 GrahamDumpleton

--json is incompatible with interactive UI (that's what this error is trying to message panic: Cannot ask for confirmation in JSON UI). you either have to use -y for the full deploy or --diff-run since it ends before confirmation prompt pops in.

cppforlife avatar Jul 15 '21 23:07 cppforlife

If the flags are incompatible, or -y is required, the correct thing to do is to show that message and not a json rendered output and a panic.

Cannot ask for confirmation in JSON UI. Either use `-y` flag or remove `--json` format

This should be the only output. It should not even try to deploy and fail.

jorgemoralespou avatar Jul 16 '21 14:07 jorgemoralespou

We may have look at making changes generically in the library used: https://github.com/cppforlife/go-cli-ui

renuy avatar Jul 28 '21 14:07 renuy