codeflare_sdk.common.utils package
Submodules
codeflare_sdk.common.utils.constants module
- codeflare_sdk.common.utils.constants.RAY_VERSION = '2.47.1'
The below are used to define the default runtime image for the Ray Cluster. * For python 3.11:ray:2.47.1-py311-cu121 * For python 3.12:ray:2.47.1-py312-cu128
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.
codeflare_sdk.common.utils.utils module
- codeflare_sdk.common.utils.utils.get_ray_image_for_python_version(python_version=None, warn_on_unsupported=True)[source]
Get the appropriate Ray image for a given Python version. If no version is provided, uses the current runtime Python version. This prevents us needing to hard code image versions for tests.
- Args:
python_version: Python version string (e.g. “3.11”). If None, detects current version. warn_on_unsupported: If True, warns and returns None for unsupported versions.
If False, silently falls back to Python 3.12 image.