Skip to content

Commit

Permalink
[kubernetes][minor] Operator garbage collection fix (#13392)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriGekhtman committed Jan 14, 2021
1 parent 9c6d892 commit 2d772a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 30 deletions.
43 changes: 14 additions & 29 deletions python/ray/operator/operator_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import copy
import logging
import os
from typing import Any, Dict, Iterator, List
from typing import Any, Dict, Iterator

from kubernetes.watch import Watch

Expand Down Expand Up @@ -39,15 +39,6 @@

root_logger = logging.getLogger("ray")
root_logger.setLevel(logging.getLevelName("DEBUG"))
"""
ownerReferences:
- apiVersion: apps/v1
controller: true
blockOwnerDeletion: true
kind: ReplicaSet
name: my-repset
uid: d9607e19-f88f-11e6-a518-42010a800195
"""


def config_path(cluster_name: str) -> str:
Expand All @@ -68,23 +59,17 @@ def cluster_cr_stream() -> Iterator:
def cr_to_config(cluster_resource: Dict[str, Any]) -> Dict[str, Any]:
"""Convert RayCluster custom resource to a ray cluster config for use by the
autoscaler."""
cr_spec = cluster_resource["spec"]
cr_meta = cluster_resource["metadata"]
config = translate(cr_spec, dictionary=CONFIG_FIELDS)
pod_types = cr_spec["podTypes"]
config["available_node_types"] = get_node_types(
pod_types, cluster_name=cr_meta["name"], cluster_uid=cr_meta["uid"])
config["cluster_name"] = cr_meta["name"]
config = translate(cluster_resource["spec"], dictionary=CONFIG_FIELDS)
config["available_node_types"] = get_node_types(cluster_resource)
config["cluster_name"] = cluster_resource["metadata"]["name"]
config["provider"] = PROVIDER_CONFIG
return config


def get_node_types(pod_types: List[Dict[str, Any]], cluster_name: str,
cluster_uid: str) -> Dict[str, Any]:
cluster_owner_reference = get_cluster_owner_reference(
cluster_name, cluster_uid)
def get_node_types(cluster_resource: Dict[str, Any]) -> Dict[str, Any]:
cluster_owner_reference = get_cluster_owner_reference(cluster_resource)
node_types = {}
for pod_type in pod_types:
for pod_type in cluster_resource["spec"]["podTypes"]:
name = pod_type["name"]
pod_type_copy = copy.deepcopy(pod_type)
pod_type_copy.pop("name")
Expand All @@ -97,15 +82,15 @@ def get_node_types(pod_types: List[Dict[str, Any]], cluster_name: str,
return node_types


def get_cluster_owner_reference(cluster_name: str,
cluster_uid: str) -> Dict[str, Any]:
def get_cluster_owner_reference(
cluster_resource: Dict[str, Any]) -> Dict[str, Any]:
return {
"apiVersion": "apps/v1",
"controller": True,
"apiVersion": cluster_resource["apiVersion"],
"kind": cluster_resource["kind"],
"blockOwnerDeletion": True,
"kind": "RayCluster",
"name": cluster_name,
"uid": cluster_uid
"controller": True,
"name": cluster_resource["metadata"]["name"],
"uid": cluster_resource["metadata"]["uid"]
}


Expand Down
5 changes: 4 additions & 1 deletion python/ray/setup-dev.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python
"""This script allows you to develop RLlib without needing to compile Ray."""
"""This script allows you to develop Ray Python code without needing to compile
Ray.
See https://docs.ray.io/en/master/development.html#building-ray-python-only"""

import argparse
import click
Expand Down Expand Up @@ -64,6 +66,7 @@ def do_link(package, force=False, local_path=None):
do_link("rllib", force=args.yes, local_path="../../../rllib")
do_link("tune", force=args.yes)
do_link("autoscaler", force=args.yes)
do_link("operator", force=args.yes)
do_link("cloudpickle", force=args.yes)
do_link("scripts", force=args.yes)
do_link("internal", force=args.yes)
Expand Down

0 comments on commit 2d772a5

Please sign in to comment.