The UX around Juju Actions has undergone a fairly radical re-design to address some long standing issues and deliver some nice usability improvements.
An early version of this was delivered in Juju 2.7. Coming in Juju 2.8 is a more polished iteration.
Key points:
- terminology changes
- running an action defaults to synchronous (block until done)
- running actions can be cancelled
- new ability to display progress log messages
- cleaner plain text output option
- stdout and stderr included in output
- numeric ids instead of UUIDs
- ability to list pending, running, completed actions
- ability to watch progress of a running action
New commands
juju run <action>
juju operations [filter options]
juju show-operation <ID>
juju show-task <ID>
juju cancel-task <ID>
Getting Started
To use the new UX, the only thing youāll need to do is enable the actions-v2
feature on the client. The backend controller infrastructure is compatible with both the old and new UX.
export JUJU_FEATURES=actions-v2
Terminology changes
The terminology around this feature changes as follows:
- enqueued actions on individual units are called tasks
- running an action run across one or more units is an operation
- an operation comprises 1 or more tasks
-
juju run-action
becomesjuju run
-
juju run
becomesjuju exec
-
juju show-action-output
becomesjuju show-operation
/juju show-task
Charm developer changes
As a charm developer, thereās a new hook command (and corresponding charm helpers API) to log action progress messages.
$ action-log --help
Usage: action-log <message>
Summary:
record a progress message for the current action
Package charmhelpers.core
def action_log(message):
"""Write an action progress message"""
Feature walk through
Weāll deploy a charm with a sample action hacked together to try out some of the new features. It happens to be a k8s charm, to help show that actions now also work on k8s.
$ cat actions/hello
#!/bin/bash
action-set result-map.message="Hello $(action-get who)!"
action-set outcome="maybe"
echo Goodbye cruel world
echo This message goes to stderr >&2
echo Foo bar
for i in {1..5}
do
action-log "Welcome $i times"
sleep 1
done
exit 3
$ juju deploy mycharms/mariadb-k8s -n 2
$ juju actions mariadb-k8s
Function Description
hello Hello World.
$ juju show-action mariadb-k8s hello
Hello World.
Arguments
who:
type: string
description: The person to say hello to.
Running actions
Weāll run the action with default behaviour - synchronous and plain text output.
$ juju run mariadb-k8s/0 hello who=world
Running operation 1 with 1 task
- task 2 on mariadb-k8s/0
09:39:43 Welcome 1 times
09:39:44 Welcome 2 times
09:39:45 Welcome 3 times
09:39:46 Welcome 4 times
09:39:47 Welcome 5 times
info:
host: mariadb-k8s-0
message: Hello world!
outcome: maybe
Goodbye cruel world
Foo bar
This message goes to stderr
Note that the plain text output omits tasks metadata like enqueue time etc and just shows progress logs, structured output data, and stdout/stderr.
YAML output shows everything. We can also choose to display timestamps in UTC.
$ juju run mariadb-k8s/0 hello who=world --format yaml --utc
Running operation 3 with 1 task
- task 4 on mariadb-k8s/0
Waiting for task 4...
03:20:48 hello sailor
03:20:48 Welcome 1 times
03:20:49 Welcome 2 times
03:20:50 Welcome 3 times
03:20:51 Welcome 4 times
03:20:52 Welcome 5 times
mariadb-k8s/0:
id: "4"
log:
- 2020-02-25 03:20:48 +0000 UTC hello sailor
- 2020-02-25 03:20:48 +0000 UTC Welcome 1 times
- 2020-02-25 03:20:49 +0000 UTC Welcome 2 times
- 2020-02-25 03:20:50 +0000 UTC Welcome 3 times
- 2020-02-25 03:20:51 +0000 UTC Welcome 4 times
- 2020-02-25 03:20:52 +0000 UTC Welcome 5 times
message: command terminated with exit code 3
results:
info:
host: mariadb-k8s-0
message: Hello world!
return-code: 3
stderr: |
This message goes to stderr
stdout: |
Goodbye cruel world
Foo bar
status: failed
timing:
completed: 2020-02-25 03:20:59 +0000 UTC
enqueued: 2020-02-25 03:20:45 +0000 UTC
started: 2020-02-25 03:20:48 +0000 UTC
unit: mariadb-k8s/0
To see a particular operation or task (whether completed or not), use the show-operation
or show-task
command. The command will return immediately with the current state of the operation or task, unless --watch
is used which will block and report the progress of a running operation or task until it completes. The --wait X
option is also supported, to allow an upper bound on how long to wait for the operation or task to complete.
show-operation
produces a detailed YAML (or JSON) record of the operation and all associated actions.
show-task
by default produces a plain text output that is quite concise, and omits any progress log messages. Use YAML (or JSON) to see full output. As with other related commands, --utc
can be used if desired.
Note: weāve been running an action on one unit - the distinction between operations and tasks becomes more apparent when an action is run across multiple units.
$ juju run mariadb-k8s/0 mariadb-k8s/1 hello who=world
Running operation 5 with 2 tasks
- task 6 on mariadb-k8s/0
- task 7 on mariadb-k8s/1
Waiting for task 6...
Waiting for task 7...
mariadb-k8s/0:
id: "6"
output: |
info:
host: mariadb-k8s-0
message: Hello world!
mariadb-k8s/1:
id: "7"
output: |
info:
host: mariadb-k8s-1
message: Hello world!
$ juju show-operation 5
summary: hello run on unit-mariadb-k8s-0,unit-mariadb-k8s-1
status: failed
action:
name: hello
parameters:
who: world
timing:
enqueued: 2020-02-25 13:25:29 +1000 AEST
started: 2020-02-25 13:25:33 +1000 AEST
completed: 2020-02-25 13:25:57 +1000 AEST
tasks:
"6":
host: mariadb-k8s/0
status: failed
timing:
enqueued: 2020-02-25 13:25:29 +1000 AEST
started: 2020-02-25 13:25:46 +1000 AEST
completed: 2020-02-25 13:25:57 +1000 AEST
log:
- 2020-02-25 13:25:46 +1000 AEST hello sailor
- 2020-02-25 13:25:46 +1000 AEST Welcome 1 times
- 2020-02-25 13:25:47 +1000 AEST Welcome 2 times
- 2020-02-25 13:25:48 +1000 AEST Welcome 3 times
- 2020-02-25 13:25:49 +1000 AEST Welcome 4 times
- 2020-02-25 13:25:50 +1000 AEST Welcome 5 times
message: command terminated with exit code 3
results:
info:
host: mariadb-k8s-0
message: Hello world!
return-code: 3
stderr: |
This message goes to stderr
stdout: |
Goodbye cruel world
Foo bar
"7":
host: mariadb-k8s/1
status: failed
timing:
enqueued: 2020-02-25 13:25:29 +1000 AEST
started: 2020-02-25 13:25:33 +1000 AEST
completed: 2020-02-25 13:25:45 +1000 AEST
log:
- 2020-02-25 13:25:33 +1000 AEST hello sailor
- 2020-02-25 13:25:33 +1000 AEST Welcome 1 times
- 2020-02-25 13:25:35 +1000 AEST Welcome 2 times
- 2020-02-25 13:25:36 +1000 AEST Welcome 3 times
- 2020-02-25 13:25:37 +1000 AEST Welcome 4 times
- 2020-02-25 13:25:38 +1000 AEST Welcome 5 times
message: command terminated with exit code 3
results:
info:
host: mariadb-k8s-1
message: Hello world!
return-code: 3
stderr: |
This message goes to stderr
stdout: |
Goodbye cruel world
Foo bar
$ juju show-task 6
info:
host: mariadb-k8s-0
message: Hello world!
Goodbye cruel world
Foo bar
This message goes to stderr
The YAML output again shows everything, including log messages.
$ juju show-task 6 --format yaml
id: "6"
log:
- 2020-02-25 13:25:46 +1000 AEST hello sailor
- 2020-02-25 13:25:46 +1000 AEST Welcome 1 times
- 2020-02-25 13:25:47 +1000 AEST Welcome 2 times
- 2020-02-25 13:25:48 +1000 AEST Welcome 3 times
- 2020-02-25 13:25:49 +1000 AEST Welcome 4 times
- 2020-02-25 13:25:50 +1000 AEST Welcome 5 times
message: command terminated with exit code 3
results:
info:
host: mariadb-k8s-0
message: Hello world!
return-code: 3
stderr: |
This message goes to stderr
stdout: |
Goodbye cruel world
Foo bar
status: failed
timing:
completed: 2020-02-25 13:25:57 +1000 AEST
enqueued: 2020-02-25 13:25:29 +1000 AEST
started: 2020-02-25 13:25:46 +1000 AEST
unit: mariadb-k8s/0
You can run an action and have it run in the background.
$juju run mariadb-k8s/0 hello who=world --background
Scheduled operation 8 with task 9
Check operation status with 'juju show-operation 8'
Check task status with 'juju show-task 9
To see progress of a running operation or task:
$ juju show-task 9 --watch
13:32:40 hello sailor
13:32:40 Welcome 1 times
13:32:41 Welcome 2 times
13:32:42 Welcome 3 times
13:32:43 Welcome 4 times
13:32:44 Welcome 5 times
info:
host: mariadb-k8s-0
message: Hello world!
Goodbye cruel world
Foo bar
This message goes to stderr
juju show-operation 8 --watch
would also work here.
To cancel a running task:
juju cancel-task 9
Cancelled tasks when viewed have a status of Aborting
while waiting to be stopped, and then Aborted
.
Listing operations
Actions which have been run are enqueued as a task on the unit; all tasks queued via a given run command are an operation. Enqueued tasks stay pending until they are executed, and then complete (successfully or not). The new operations
(list-operations
) command can be used to see what operations exist, optionally filtered by:
- unit
- application
- action name
- status (pending, running, completed, failed, aborting, aborted)
show-operation
or show-task
can then be used to inspect a particular operation in more detail.
When both unit(s) and application(s) are specified, operations for any of the individual units and any unit of the applications are included.
$ juju operations --status=running,completed,failed --actions=hello --apps=mariadb-k8s
Id Status Started Finished Task IDs Summary
1 failed 2020-02-25T13:17:03 2020-02-25T13:17:19 2 hello run on unit-mariadb-k8s-0
3 failed 2020-02-25T13:20:48 2020-02-25T13:20:59 4 hello run on unit-mariadb-k8s-0
5 failed 2020-02-25T13:25:33 2020-02-25T13:25:57 6,7 hello run on unit-mariadb-k8s-0,unit-mariadb-k8s-1
8 failed 2020-02-25T13:31:45 2020-02-25T13:31:56 9 hello run on unit-mariadb-k8s-0
Use YAML to see more information about each task. --utc
works as well.
$ juju operations --status=running,completed,failed --actions=hello --apps=mariadb-k8s --format yaml --utc
"1":
summary: hello run on unit-mariadb-k8s-0
status: failed
action:
name: hello
parameters:
who: world
timing:
enqueued: 2020-02-25 03:16:59 +0000 UTC
started: 2020-02-25 03:17:03 +0000 UTC
completed: 2020-02-25 03:17:19 +0000 UTC
tasks:
"2":
host: mariadb-k8s/0
status: failed
timing:
enqueued: 2020-02-25 03:16:59 +0000 UTC
started: 2020-02-25 03:17:03 +0000 UTC
completed: 2020-02-25 03:17:19 +0000 UTC
message: command terminated with exit code 3
"3":
summary: hello run on unit-mariadb-k8s-0
status: failed
action:
name: hello
parameters:
who: world
timing:
enqueued: 2020-02-25 03:20:45 +0000 UTC
started: 2020-02-25 03:20:48 +0000 UTC
completed: 2020-02-25 03:20:59 +0000 UTC
tasks:
"4":
host: mariadb-k8s/0
status: failed
timing:
enqueued: 2020-02-25 03:20:45 +0000 UTC
started: 2020-02-25 03:20:48 +0000 UTC
completed: 2020-02-25 03:20:59 +0000 UTC
message: command terminated with exit code 3
...