crate.operator.utils.kubeapi module

async crate.operator.utils.kubeapi.call_kubeapi(method, logger, *, continue_on_absence=False, continue_on_conflict=False, namespace=None, body=None, **kwargs)

Await a Kubernetes API method and return its result.

If the API fails with an HTTP 404 NOT FOUND error and continue_on_absence is set to True a warning is raised and call_kubeapi returns None.

If the API fails with an HTTP 409 CONFLICT error and continue_on_conflict is set to True a warning is raised and call_kubeapi returns None.

In case of any other error or when either option is set to False (default) the kubernetes_asyncio.client.exceptions.ApiException is re-raised.

Parameters
  • method (Callable[..., Awaitable]) – A Kubernetes API function which will be called with namespace and body, if provided, and all other kwargs. The function will also be awaited and the response returned.

  • logger (Logger) –

  • continue_on_absence – When True, emit a warning instead of an error on HTTP 404 responses.

  • continue_on_conflict – When True, emit a warning instead of an error on HTTP 409 responses.

  • namespace (Optional[str]) – The namespace passed to namespaced K8s API endpoints.

  • body (Optional[TypeVar(K8sModel, V1CronJob, V1ConfigMap, V1Deployment, V1PersistentVolume, V1PersistentVolumeClaim, V1Secret, V1Service, V1StatefulSet)]) – The body passed to the K8s API endpoints.

Return type

Optional[Awaitable[TypeVar(K8sModel, V1CronJob, V1ConfigMap, V1Deployment, V1PersistentVolume, V1PersistentVolumeClaim, V1Secret, V1Service, V1StatefulSet)]]

async crate.operator.utils.kubeapi.ensure_user_password_label(core, namespace, secret_name)

Add the LABEL_USER_PASSWORD label to a namespaced secret.

Parameters
  • core (CoreV1Api) – An instance of the Kubernetes Core V1 API.

  • namespace (str) – The namespace where the Kubernetes Secret is deployed.

  • secret_name (str) – The name of the Kubernetes Secret.

async crate.operator.utils.kubeapi.get_host(core, namespace, name)

Return the hostname to the CrateDB cluster within the Kubernetes cluster. This uses the “discovery” service for internal access, since the public-facing “crate” service can be IP-restricted.

During testing, the function returns the public IP address, because the operator doesn’t run inside Kubernetes during tests but outside. And the only way to connect to the CrateDB cluster is to go through the public interface.

Parameters
  • core (CoreV1Api) – An instance of the Kubernetes Core V1 API.

  • namespace (str) – The namespace where the CrateDB cluster is deployed.

  • name (str) – The name of the CrateDB cluster.

Return type

str

async crate.operator.utils.kubeapi.get_service_public_hostname(core, namespace, name)

Query the given CrateDB Kubernetes Service fo it’s public IP address / hostname.

Parameters
  • core (CoreV1Api) – An instance of the Kubernetes Core V1 API.

  • namespace (str) – The namespace where the CrateDB cluster is deployed.

  • name (str) – The name of the CrateDB cluster.

Return type

str

async crate.operator.utils.kubeapi.get_system_user_password(core, namespace, name)

Return the password for the system user of cluster name in namespace.

Parameters
  • core (CoreV1Api) – An instance of the Kubernetes Core V1 API.

  • namespace (str) – The namespace where the CrateDB cluster is deployed.

  • name (str) – The name of the CrateDB cluster.

Return type

str

async crate.operator.utils.kubeapi.resolve_secret_key_ref(core, namespace, secret_key_ref)

Lookup the secret value defined by secret_key_ref in namespace.

Parameters
  • core (CoreV1Api) – An instance of the Kubernetes Core V1 API.

  • namespace (str) – The namespace where to lookup a secret and its value.

  • secret_key_ref (SecretKeyRef) – a secretKeyRef containing the secret name and key within that holds the desired value.

Return type

str