CAPI Runtime
Runtime SDK
Runtime Hook
Runtime Extension
Instead, with the growing adoption of Cluster API as a common layer to manage fleets of Kubernetes Clusters, there is now a new category of systems, products and services built on top of Cluster API that require strict interactions with the lifecycle of Clusters, but at the same
time they do not want to replace any “low-level” components in Cluster API, because they happily benefit from all the features available in the existing providers (built on top vs plug-in/swap).
CAPI follows extensibility model
A common approach for this problem has been to watch for Cluster API resources; another approach has been to implement API Server admission webhooks to alter CAPI resources, but both approaches are limited by the fact that the system built on top of Cluster API is forced to treat it as a opaque system and thus with limited visibility and almost total lack of control, e.g. you can watch a Machine being provisioned, but not block the provisioning to start if a quota management systems signals you have exhausted all the resources assigned to you.
Example implemented and used by CCD is machine deletion webhook.
Runtime Hooks are inspired by Kubernetes admission webhooks, but there is one key difference
that splits them aparts:
Each Runtime Hook will be defined by one (or more) RESTful APIs implemented as a POST operation ; each operation is going to receive an input parameter as a request body, and return an output value as response body, both application/json encoded and with a schema of arbitrary
complexity that should be considered an integral part of the Runtime Hook definition.
It is also worth noting that more than one version of the same Runtime Hook might be supported at the same time; e.g. in the example above the Cluster.BeforeUpgrade operations exist in version v1alpha1 (old version) and v1alpha2 (current).
As a developer building systems on top of Cluster API, if you want to interact with the Cluster’s lifecycle via a Runtime Extension, you are required to implement an HTTP server handling requests according to the OpenAPI specification for the Runtime Hook you are interested in
By registering a Runtime Extension the Cluster API Runtime became aware of a Runtime Extension implementing a Runtime Hook, and as a consequence the runtime starts calling the extension at well-defined moments of the Workload Cluster’s lifecycle
apiVersion: cluster.x-k8s.io/v1beta1
kind: RuntimeExtensionConfiguration
metadata:
name: "my-amazing-product-runtime-extension"
webhooks:
# Name should be fully qualified and unique in the Cluster,
# thus usage of sub domains, version qualifiers is recommended.
- name: "my-amazing-runtime-extension.v1.5.panda.com"
# List of group/version/hook the RuntimeExtension implements. Required
operations:
- apiVersion: "cluster.runtime.cluster.x-k8s.io/v1alpha2"
hook: "beforeUpgrade"
- apiVersion: "cluster.runtime.cluster.x-k8s.io/v1alpha2"
hook: "afterUpgrade"
#ClientConfig defines how to communicate with the RuntimeExtension. Required
clientConfig:
#`url` gives the location of the RuntimeExtension, in standard URL
# form (`scheme://host:port/path`). Exactly one of `url` or `service` must be specified.
url: "..."
service:
namespace: "example-namespace"
name: "example-service"
# `path` is an optional path prefix path which can be sent in any
# request to this service.
path: "runtime-extensions/"
# If specified, the port on the service that hosts the RuntimeExtension.
# Default to 443. `port` should be a valid port number (1-65535, inclusive)
# or a port name of the referenced service.
port: 8082
caBundle: "..."
# If specified, define the timeout for each RuntimeExtension call t
# complete (Default 5s, Max 10s).
timeoutSeconds: 2
# FailurePolicy defines how errors from RuntimeExtension calls are
# handled - allowed values are Ignore or Fail. Defaults to Fail.
failurePolicy: Fail