Skip to content
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

Move k8s resource string parsing to a utility method #57

Open
terrytangyuan opened this issue Sep 22, 2020 · 1 comment
Open

Move k8s resource string parsing to a utility method #57

terrytangyuan opened this issue Sep 22, 2020 · 1 comment
Labels
good first issue Good for newcomers

Comments

@terrytangyuan
Copy link
Member

See below. This should be removed to a utility method that can be reused across different steps.

if resources is not None:
# User-defined resource, should be formatted like
# "cpu=1,memory=1024,disk=2048,gpu=1,gpu_type=p100,shared_memory=20480"
try:
kvs = resources.split(",")
print(kvs)
limits = {}
for kv in kvs:
k, v = kv.split("=")
if k in ["gpu", "memory", "disk", "shared_memory"]:
v = int(v)
elif k == "cpu":
v = float(v)
limits[k] = v
resource_limits = {"limits": limits}
container["resources"] = resource_limits
except Exception:
raise Exception("Unrecognized resource type %s" % resources)

@terrytangyuan terrytangyuan added the good first issue Good for newcomers label Sep 22, 2020
@terrytangyuan
Copy link
Member Author

Actually the resources in APIs like couler.run_container() are specified as a dictionary instead of a string currently. For pre-defined Couler steps, should we be consistent? A string that represents the resources does not seem necessary since we are not building a CLI here and Python dictionary would be more intuitive to users. What do you think? @merlintang @ywskycn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant