Application Hooks
This chapter describes details about the “kubehooks” resource. This resource represents commands and scripts that can be run during Kubernetes backup and restore.
Defining a Hooks Resource
POST /api/v1/kubehooks
{
"name": "test-pre-hooks-av",
"hook_type": "PRE_BACKUP",
"hook": [
{
"labels":{
"app":"csi-app"
},
"target": [
{
"command": "/bin/uname -a",
"container": "my-frontend"
}
]
}
]
}
201 CREATED
{
"_id": "6130b2032a814d7d1c9e06b4",
"name": "test-pre-hooks-av",
"hook": [
{
"labels": {
"app": "csi-app"
},
"target": [
{
"command": "uname -a",
"container": "my-frontend"
}
]
}
],
"hook_type": "PRE_BACKUP",
"_updated": "Thu, 02 Sep 2021 11:14:11 GMT",
"_created": "Thu, 02 Sep 2021 11:14:11 GMT",
"_etag": "0271940f0bb2508964b48f5d73f9310710fbe5e5",
"_links": {
"self": {
"title": "Kubehook",
"href": "/v1/kubehooks/6130b2032a814d7d1c9e06b4"
}
}
}
Schema
- hook_type
Type of the hook. Possible values: PRE_BACKUP, POST_BACKUP, POST_RESTORE, COMMON. Note that it is the client’s responsibility to select right type to match the intent of the script. The type value will be used in some validations.
“COMMON” indicates that the script can be used in PRE, POST as well as for BACKUP and RESTORE. These should be rare and typically are used for informational or debugging purposes.
- labels
Labels selectors. Required.
A map of key and value:
"labels": { "app": "nginx" }
A map with key and “,” separated values. (OR logic for one key and multiple values):
"labels": { "app": "nginx,wordpress" }
A map with multiple key and value pairs, Will be AND-ED together:
"labels": { "tier": "frontend", "app": "nginx,wordpress" }
- target
Target is the container in the pod where the hook command needs to run.
Target schema
- Command
Required. Command to be run.
- container
container name. Optional. If set with name then given commands will run on given container,else first container from pod will be selected.
Associating a POST with PRE script
It is possible to associate a POST hook with a PRE hook so that when a PRE hook is selected, the client can automatically add POST hook. To achieve this, set the field “post_hook” either while creating a PRE hook or by updating it later.
Here is a sample request:
{
"name": "test-pre-hook",
...,
"post_hook": "6130b2032a814d7d1c9e06a3",
...,
}
Get/List
To list and get user defined hooks:
GET /api/v1/kubehooks
GET /api/v1/kubehooks/<ID>
To list system hooks (templates):
GET /api/v1/kubehooks/builtin
This API accepts all the usual pagination, filtering, and sorting parameters. Note that there is no API to do a GET on a single system hook. One workaround is to use a filter, like so:
GET /api/v1/kubehooks/builtin?where={"_id": "614ae995ff1f535f5e60688c"}
Delete a hook
DELETE /api/v1/kubehooks/<ID>
Note
Delete will fail if there is a running job corresponding to the kubehook resource.
Clone a hook
- name
String. Required.
This API works for both user as well as system hooks.