codeflare_sdk.common.utils package

Submodules

codeflare_sdk.common.utils.demos module

codeflare_sdk.common.utils.demos.copy_demo_nbs(dir: str = './demo-notebooks', overwrite: bool = False)[source]

Copy the demo notebooks from the package to the current working directory

overwrite=True will overwrite any files that exactly match files written by copy_demo_nbs in the target directory. Any files that exist in the directory that don’t match these values will remain untouched.

Args:
dir (str):

The directory to copy the demo notebooks to. Defaults to “./demo-notebooks”.

overwrite (bool):

Whether to overwrite files in the directory if it already exists. Defaults to False.

Raises:
FileExistsError:

If the directory already exists.

codeflare_sdk.common.utils.generate_cert module

codeflare_sdk.common.utils.generate_cert.export_env(cluster_name, namespace)[source]

Sets environment variables to configure TLS for a Ray cluster.

Args:
cluster_name (str):

The name of the Ray cluster.

namespace (str):

The Kubernetes namespace where the Ray cluster is located.

Environment Variables Set:
  • RAY_USE_TLS: Enables TLS for Ray.

  • RAY_TLS_SERVER_CERT: Path to the TLS server certificate.

  • RAY_TLS_SERVER_KEY: Path to the TLS server private key.

  • RAY_TLS_CA_CERT: Path to the CA certificate.

codeflare_sdk.common.utils.generate_cert.generate_ca_cert(days: int = 30)[source]

Generates a self-signed CA certificate and private key, encoded in base64 format.

Similar to:

openssl req -x509 -nodes -newkey rsa:2048 -keyout ca.key -days 1826 -out ca.crt -subj ‘/CN=root-ca’

Args:
days (int):

The number of days for which the CA certificate will be valid. Default is 30.

Returns:
Tuple[str, str]:

A tuple containing the base64-encoded private key and CA certificate.

codeflare_sdk.common.utils.generate_cert.generate_tls_cert(cluster_name, namespace, days=30)[source]

Generates a TLS certificate and key for a Ray cluster, saving them locally along with the CA certificate.

Args:
cluster_name (str):

The name of the Ray cluster.

namespace (str):

The Kubernetes namespace where the Ray cluster is located.

days (int):

The number of days for which the TLS certificate will be valid. Default is 30.

Files Created:
  • ca.crt: The CA certificate.

  • tls.crt: The TLS certificate signed by the CA.

  • tls.key: The private key for the TLS certificate.

Raises:
Exception:

If an error occurs while retrieving the CA secret.

codeflare_sdk.common.utils.generate_cert.get_secret_name(cluster_name, namespace, api_instance)[source]

Retrieves the name of the Kubernetes secret containing the CA certificate for the given Ray cluster.

Args:
cluster_name (str):

The name of the Ray cluster.

namespace (str):

The Kubernetes namespace where the Ray cluster is located.

api_instance (client.CoreV1Api):

An instance of the Kubernetes CoreV1Api.

Returns:
str:

The name of the Kubernetes secret containing the CA certificate.

Raises:
KeyError:

If no secret matching the cluster name is found.

Module contents