Send kubectl

This section describes the MQTT messages and topics the Management Service handles to perform the "send-kubectl" action. When using AnythingDB in Studio all of this is taken care of within the product.

Sending a Message to the Management Service

The MQTT topic the Management Service subscribes to, for running kubectl commands is:
status/<space>/categories/cluster/things/<thing-id>/actions/send-kubectl

The message format for publishing is as follows:

{
  "send-kubectl": {
    "input": {
      "correlationId": "{create-a-unique-id-for-each-message}",
      "command": "kubectl",
      "arguments": [
        "{each}",
        "{new}",
        "{argument}",
        "{needs}",
        "{its}",
        "{own}",
        "{array}",
        "{entry}"
      ]
    },
    "status": "pending",
    "timeRequested": "<datetime>",
    "href": "/spaces/<space>/categories/cluster/things/<thing-id>/actions/send-kubectl/<action-id>"
  }
}

For example:

{
  "send-kubectl": {
    "input": {
      "correlationId": "666",
      "command": "kubectl",
      "arguments": [
        "get",
        "nodes",
        "-o",
        "wide"
      ]
    },
    "status": "pending",
    "timeRequested": "2020-05-26 15:37:46+0000",
    "href": "/spaces/my-space/categories/cluster/things/my-thing-id/actions/send-kubectl/1234"
  }
}

It is important that each argument is put in a new array entry. If there is a space in the complete command then that means a new argument.

Status Update After Receiving Action Request

MQTT topic the message is sent to:
spaces/<space>/categories/cluster/things/<thing-id>/actions

Message:

{
  "send-kubectl": {
    "href": "/spaces/<space>/categories/cluster/things/<thing-id>/actions/send-kubectl/<action-id>",
    "status": "received"
  }
}

Event Publish After Running Action

MQTT topic the message is sent to:
/spaces/<space>/categories/cluster/things/<thing-id>/events

Message:

{
    "kubectl-logs": {
        "data": {
            "correlationId": "{the-unique-id-from-the-request}",
            "statusCode": "{an-http-status-code}",
            "statusMessage": "{optional descriptive message}",
            "response": "{the output in plain text format}"
        }
    }
}

Example:

{
    "kubectl-logs": {
        "data": {
            "correlationId": "666",
            "statusCode": 200,
            "statusMessage": "Command executed successfully",
            "response": "NAME           STATUS   ROLES    AGE   VERSION        INTERNAL-IP    EXTERNAL-IP   OS-IMAGE           KERNEL-VERSION     CONTAINER-RUNTIME\nmartin-ag150   Ready    master   50d   v1.18.2+k3s1   10.10.10.100   \u003cnone\u003e        Ubuntu 20.04 LTS   5.4.0-40-generic   containerd://1.3.3-k3s2\n"
        }
    }
}

You need to use the correlationId to match the response to the request.

Status Update After Completing Action

MQTT topic the message is sent to:
spaces/<space>/categories/cluster/things/<thing-id>/actions

Message:

{
  "send-kubectl": {
    "href": "/spaces/<space>/categories/cluster/things/<thing-id>/actions/send-kubectl/<action-id>",
    "status": "completed"
  }
}