crate.operator.webhooks module

class crate.operator.webhooks.WebhookAction(value)

Bases: str, Enum

An enumeration.

ALLOWED_CIDR_UPDATE = 'allowed_cidr_update'
BACKUP_SCHEDULE_UPDATE = 'backup_schedule_update'
CHANGE_COMPUTE = 'change_compute'
CREATE = 'create'
EXPAND_STORAGE = 'expand_storage'
PASSWORD_UPDATE = 'password_update'
RESTORE_SNAPSHOT = 'restore_snapshot'
SCALE = 'scale'
SUSPEND = 'suspend'
UNKNOWN = 'unknown'
UPGRADE = 'upgrade'
classmethod for_diff(diff)

Returns the performed type of operation based on the kopf.Diff of the current change.

Parameters

diff (Diff) – The diff between the old and new resource body.

class crate.operator.webhooks.WebhookAdminUsernameChangedPayload

Bases: dict

admin_username: Optional[str]
class crate.operator.webhooks.WebhookBackupScheduleUpdatePayload

Bases: dict

backup_schedule: str
class crate.operator.webhooks.WebhookChangeComputePayload

Bases: dict

new_cpu_limit: int
new_cpu_request: int
new_heap_ratio: float
new_memory_limit: str
new_memory_request: str
new_nodepool: str
old_cpu_limit: int
old_cpu_request: int
old_heap_ratio: float
old_memory_limit: str
old_memory_request: str
old_nodepool: str
class crate.operator.webhooks.WebhookClient

Bases: object

A client to send HTTP POST requests to an API endpoint if configured.

The WebhookClient is a wrapper around aiohttp, providing a specific API that allows sending webhook notifications to an external service.

By default, an instance is not configured. One needs to call configure() to enable notification sending. otherwise, sending will be ignored and a log message written instead.

The webhooks section in the cepepts part of the documentation elaborates on the payload.

configure(url, username, password)

Configure and enable the client.

Parameters
  • url (str) – The full URL (scheme, domain, port, path) where to POST requests to.

  • username (str) – All requests will include HTTP Basic Auth credentials. This is the username for that.

  • password (str) – All requests will include HTTP Basic Auth credentials. This is the password for that.

Return type

None

property configured: bool

Return if the client is configured. If not, all notification sending should be skipped.

async send_notification(namespace, name, event, sub_payload, status, logger, *, unsafe=False)

Send a webhook notification to the configured webhook URL. Will do nothing if no webhooks are configured.

Webhooks are normally fire-and-forget FYI information that must not block kopf from continuing with the handler chain. In some cases however, the webhook is the whole point (i.e. IP address acquired), so we want to fail if an error happens so that the operation could be retried.

Parameters
  • name (str) – Name of the cluster this notification is about

  • namespace (str) – Namespaces where this event happened

  • event (WebhookEvent) – The event type

  • sub_payload (WebhookSubPayload) – The specific payload for the event type

  • status (WebhookStatus) – The status of the event

  • logger (Logger) – The logger to use

  • unsafe (Optional[bool]) – Whether to throw exceptions if any happen. Defaults to False - exceptions will be logged but not propagated.

class crate.operator.webhooks.WebhookClusterHealthPayload

Bases: dict

status: str
class crate.operator.webhooks.WebhookEvent(value)

Bases: str, Enum

An enumeration.

ADMIN_USERNAME_CHANGED = 'admin_username_changed'
BACKUP_SCHEDULE_UPDATE = 'backup_schedule_update'
COMPUTE_CHANGED = 'compute_changed'
DELAY = 'delay'
FEEDBACK = 'feedback'
HEALTH = 'health'
INFO_CHANGED = 'info_changed'
SCALE = 'scale'
SNAPSHOT = 'snapshot'
UPGRADE = 'upgrade'
class crate.operator.webhooks.WebhookFeedbackPayload

Bases: dict

action: WebhookAction
message: str
operation: WebhookOperation
class crate.operator.webhooks.WebhookInfoChangedPayload

Bases: dict

external_ip: str
class crate.operator.webhooks.WebhookOperation(value)

Bases: str, Enum

An enumeration.

CREATE = 'create'
UPDATE = 'update'
class crate.operator.webhooks.WebhookPayload

Bases: TypedDict

admin_username_changed_data: Optional[WebhookAdminUsernameChangedPayload]
backup_schedule_data: Optional[WebhookBackupScheduleUpdatePayload]
cluster: str
compute_changed_data: Optional[WebhookChangeComputePayload]
event: WebhookEvent
feedback_data: Optional[WebhookFeedbackPayload]
health_data: Optional[WebhookClusterHealthPayload]
info_data: Optional[WebhookInfoChangedPayload]
namespace: str
scale_data: Optional[WebhookScalePayload]
status: WebhookStatus
temporary_failure_data: Optional[WebhookTemporaryFailurePayload]
upgrade_data: Optional[WebhookUpgradePayload]
class crate.operator.webhooks.WebhookScaleNodePayload

Bases: TypedDict

name: str
replicas: str
class crate.operator.webhooks.WebhookScalePayload

Bases: dict

new_data_replicas: List[WebhookScaleNodePayload]
new_master_replicas: Optional[int]
old_data_replicas: List[WebhookScaleNodePayload]
old_master_replicas: Optional[int]
class crate.operator.webhooks.WebhookStatus(value)

Bases: str, Enum

An enumeration.

FAILURE = 'failure'
IN_PROGRESS = 'in_progress'
SUCCESS = 'success'
TEMPORARY_FAILURE = 'temporary_failure'
class crate.operator.webhooks.WebhookSubPayload

Bases: TypedDict

class crate.operator.webhooks.WebhookTemporaryFailurePayload

Bases: dict

reason: str
class crate.operator.webhooks.WebhookUpgradePayload

Bases: dict

new_registry: str
new_version: str
old_registry: str
old_version: str