Skip to content

Add annotations parameter #785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/sphinx/user-docs/cluster-configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ requirements for creating the Ray Cluster.
worker_memory_limits=2, # Default 2
# image="", # Optional Field
labels={"exampleLabel": "example", "secondLabel": "example"},
annotations={"key1":"value1", "key2":"value2"},
))

.. note::
Expand Down
1 change: 1 addition & 0 deletions src/codeflare_sdk/common/utils/unit_test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,5 +442,6 @@ def create_cluster_all_config_params(mocker, cluster_name, is_appwrapper) -> Clu
extended_resource_mapping={"example.com/gpu": "GPU", "intel.com/gpu": "TPU"},
overwrite_default_resource_mapping=True,
local_queue="local-queue-default",
annotations={"key1": "value1", "key2": "value2"},
)
return Cluster(config)
7 changes: 3 additions & 4 deletions src/codeflare_sdk/ray/cluster/build_ray_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def get_metadata(cluster: "codeflare_sdk.ray.cluster.Cluster"):
)

# Get the NB annotation if it exists - could be useful in future for a "annotations" parameter.
annotations = get_nb_annotations()
annotations = with_nb_annotations(cluster.config.annotations)
if annotations != {}:
object_meta.annotations = annotations # As annotations are not a guarantee they are appended to the metadata after creation.
return object_meta
Expand All @@ -213,11 +213,10 @@ def get_labels(cluster: "codeflare_sdk.ray.cluster.Cluster"):
return labels


def get_nb_annotations():
def with_nb_annotations(annotations: dict):
"""
The get_nb_annotations() function generates the annotation for NB Prefix if the SDK is running in a notebook
The with_nb_annotations() function generates the annotation for NB Prefix if the SDK is running in a notebook and appends any user set annotations
"""
annotations = {}

# Notebook annotation
nb_prefix = os.environ.get("NB_PREFIX")
Expand Down
3 changes: 3 additions & 0 deletions src/codeflare_sdk/ray/cluster/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class ClusterConfiguration:
A dictionary of custom resource mappings to map extended resource requests to RayCluster resource names
overwrite_default_resource_mapping:
A boolean indicating whether to overwrite the default resource mapping.
annotations:
A dictionary of annotations to apply to the cluster.
"""

name: str
Expand Down Expand Up @@ -126,6 +128,7 @@ class ClusterConfiguration:
extended_resource_mapping: Dict[str, str] = field(default_factory=dict)
overwrite_default_resource_mapping: bool = False
local_queue: Optional[str] = None
annotations: Dict[str, str] = field(default_factory=dict)

def __post_init__(self):
if not self.verify_tls:
Expand Down
5 changes: 5 additions & 0 deletions src/codeflare_sdk/ray/cluster/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ def test_config_creation_all_parameters(mocker):
)
assert cluster.config.overwrite_default_resource_mapping == True
assert cluster.config.local_queue == "local-queue-default"
assert cluster.config.annotations == {
"app.kubernetes.io/managed-by": "test-prefix",
"key1": "value1",
"key2": "value2",
}

assert filecmp.cmp(
f"{aw_dir}test-all-params.yaml",
Expand Down
2 changes: 2 additions & 0 deletions tests/test_cluster_yamls/appwrapper/unit-test-all-params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ spec:
metadata:
annotations:
app.kubernetes.io/managed-by: test-prefix
key1: value1
key2: value2
labels:
controller-tools.k8s.io: '1.0'
key1: value1
Expand Down
2 changes: 2 additions & 0 deletions tests/test_cluster_yamls/ray/unit-test-all-params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: RayCluster
metadata:
annotations:
app.kubernetes.io/managed-by: test-prefix
key1: value1
key2: value2
labels:
controller-tools.k8s.io: '1.0'
key1: value1
Expand Down
Loading