kapp icon indicating copy to clipboard operation
kapp copied to clipboard

request - provide `deleted, changed, noop` values in JSON output

Open paulczar opened this issue 3 years ago • 3 comments

When I'm calling kapp from ansible I need an easy way to determine if the resources have actually changed.

Currently I call kapp with --json and then after validating that the return code is 0 I do the following which is not ideal:

    parsed = json.loads(out)

    # attempt to process if changes happened, this involves some ugly text parsing
    if kapp_command == "delete":
        # check in parse lines to verify it wasn't already deleted
        if "App '%s' (namespace: %s) does not exist" % (
            module.params['name'], module.params['namespace']
            ) not in parsed['Lines']:
                result['changed'] = True

    if kapp_command == "deploy":
        # scan output for changes
        for line in parsed['Lines']:
            if re.match("applying \d+ changes", line):
                result['changed'] = True

I would love the json output to include something like:

{"summary": { "changed": 1,  "noop": "5", "deleted": "3" } }

so I can more easily parse the results.

paulczar avatar Oct 12 '20 19:10 paulczar

is --diff-exit-status (https://github.com/k14s/kapp/blob/develop/docs/diff.md#controlling-diff-via-deploy-flags) useful here?

(do keep in mind that there is a window of time between two successive kapp deploy's during which resources on the server might change.)

cppforlife avatar Oct 12 '20 21:10 cppforlife

also, could you describe how kapp fits into your flow? specifically why do you need to parse this info out (who looks at result['changed'] = True)?

cppforlife avatar Oct 12 '20 21:10 cppforlife

Oh cool, I'll experiment with some of those diff flags. --diff-exit-status=bool might be super useful for me.

Ansible uses result['changed'] to show that the task caused a change, and may call a handler or other task based on changed/not-changed.

paulczar avatar Oct 14 '20 17:10 paulczar