-
Notifications
You must be signed in to change notification settings - Fork 300
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
Make MatchableResources configurable through flyte-cli #118
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
import flytekit.plugins | ||
|
||
__version__ = '0.9.0b0' | ||
__version__ = '0.9.0b1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
from flyteidl.admin import matchable_resource_pb2 as _matchable_resource | ||
from flytekit.models import common as _common | ||
|
||
|
||
class ClusterResourceAttributes(_common.FlyteIdlEntity): | ||
|
||
def __init__(self, attributes): | ||
""" | ||
Custom resource attributes which will be applied in cluster resource creation (e.g. quotas). | ||
Dict keys are the *case-sensitive* names of variables in templatized resource files. | ||
Dict values should be the custom values which get substituted during resource creation. | ||
|
||
:param dict[Text, Text] attributes: Applied in cluster resource creation (e.g. quotas). | ||
""" | ||
self._attributes = attributes | ||
|
||
@property | ||
def attributes(self): | ||
""" | ||
Custom resource attributes which will be applied in cluster resource management | ||
:rtype: dict[Text, Text] | ||
""" | ||
return self._attributes | ||
|
||
def to_flyte_idl(self): | ||
""" | ||
:rtype: flyteidl.admin.matchable_resource_pb2.ClusterResourceAttributes | ||
""" | ||
return _matchable_resource.ClusterResourceAttributes( | ||
attributes=self.attributes, | ||
) | ||
|
||
@classmethod | ||
def from_flyte_idl(cls, pb2_object): | ||
""" | ||
:param flyteidl.admin.matchable_resource_pb2.ClusterResourceAttributes pb2_object: | ||
:rtype: ClusterResourceAttributes | ||
""" | ||
return cls( | ||
attributes=pb2_object.attributes, | ||
) | ||
|
||
|
||
class ExecutionQueueAttributes(_common.FlyteIdlEntity): | ||
|
||
def __init__(self, tags): | ||
""" | ||
Tags used for assigning execution queues for tasks matching a project, domain and optionally, workflow. | ||
|
||
:param list[Text] tags: | ||
""" | ||
self._tags = tags | ||
|
||
@property | ||
def tags(self): | ||
""" | ||
:rtype: list[Text] | ||
""" | ||
return self._tags | ||
|
||
def to_flyte_idl(self): | ||
""" | ||
:rtype: flyteidl.admin.matchable_resource_pb2.ExecutionQueueAttributes | ||
""" | ||
return _matchable_resource.ExecutionQueueAttributes( | ||
tags=self.tags, | ||
) | ||
|
||
@classmethod | ||
def from_flyte_idl(cls, pb2_object): | ||
""" | ||
:param flyteidl.admin.matchable_resource_pb2.ExecutionQueueAttributes pb2_object: | ||
:rtype: ExecutionQueueAttributes | ||
""" | ||
return cls( | ||
tags=pb2_object.tags, | ||
) | ||
|
||
|
||
class MatchingAttributes(_common.FlyteIdlEntity): | ||
def __init__(self, cluster_resource_attributes=None, execution_queue_attributes=None): | ||
""" | ||
At most one target from cluster_resource_attributes or execution_queue_attributes can be set. | ||
:param ClusterResourceAttributes cluster_resource_attributes: | ||
:param ExecutionQueueAttributes execution_queue_attributes: | ||
""" | ||
if cluster_resource_attributes and execution_queue_attributes: | ||
raise ValueError("Only one of cluster_resource_attributes or execution_queue_attributes can be set") | ||
self._cluster_resource_attributes = cluster_resource_attributes | ||
self._execution_queue_attributes = execution_queue_attributes | ||
|
||
@property | ||
def cluster_resource_attributes(self): | ||
""" | ||
Custom resource attributes which will be applied in cluster resource creation (e.g. quotas). | ||
:rtype: ClusterResourceAttributes | ||
""" | ||
return self._cluster_resource_attributes | ||
|
||
@property | ||
def execution_queue_attributes(self): | ||
""" | ||
Tags used for assigning execution queues for tasks. | ||
:rtype: ExecutionQueueAttributes | ||
""" | ||
return self._execution_queue_attributes | ||
|
||
def to_flyte_idl(self): | ||
""" | ||
:rtype: flyteidl.admin.matchable_resource_pb2.MatchingAttributes | ||
""" | ||
return _matchable_resource.MatchingAttributes( | ||
cluster_resource_attributes=self.cluster_resource_attributes.to_flyte_idl() if | ||
self.cluster_resource_attributes else None, | ||
execution_queue_attributes=self.execution_queue_attributes.to_flyte_idl() if self.execution_queue_attributes | ||
else None, | ||
) | ||
|
||
@classmethod | ||
def from_flyte_idl(cls, pb2_object): | ||
""" | ||
:param flyteidl.admin.matchable_resource_pb2.MatchingAttributes pb2_object: | ||
:rtype: MatchingAttributes | ||
""" | ||
return cls( | ||
cluster_resource_attributes=ClusterResourceAttributes.from_flyte_idl( | ||
pb2_object.cluster_resource_attributes) if pb2_object.HasField("cluster_resource_attributes") else None, | ||
execution_queue_attributes=ExecutionQueueAttributes.from_flyte_idl(pb2_object.execution_queue_attributes) if | ||
pb2_object.HasField("execution_queue_attributes") else None, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from __future__ import absolute_import | ||
|
||
from flytekit.models import matchable_resource | ||
|
||
|
||
def test_cluster_resource_attributes(): | ||
obj = matchable_resource.ClusterResourceAttributes({"cpu": "one million", "gpu": "just one"}) | ||
assert obj.attributes == {"cpu": "one million", "gpu": "just one"} | ||
assert obj == matchable_resource.ClusterResourceAttributes.from_flyte_idl(obj.to_flyte_idl()) | ||
|
||
|
||
def test_execution_queue_attributes(): | ||
obj = matchable_resource.ExecutionQueueAttributes(["foo", "bar", "baz"]) | ||
assert obj.tags == ["foo", "bar", "baz"] | ||
assert obj == matchable_resource.ExecutionQueueAttributes.from_flyte_idl(obj.to_flyte_idl()) | ||
|
||
|
||
def test_matchable_resource(): | ||
cluster_resource_attrs = matchable_resource.ClusterResourceAttributes({"cpu": "one million", "gpu": "just one"}) | ||
obj = matchable_resource.MatchingAttributes(cluster_resource_attributes=cluster_resource_attrs) | ||
assert obj.cluster_resource_attributes == cluster_resource_attrs | ||
assert obj == matchable_resource.MatchingAttributes.from_flyte_idl(obj.to_flyte_idl()) | ||
|
||
execution_queue_attributes = matchable_resource.ExecutionQueueAttributes(["foo", "bar", "baz"]) | ||
obj2 = matchable_resource.MatchingAttributes(execution_queue_attributes=execution_queue_attributes) | ||
assert obj2.execution_queue_attributes == execution_queue_attributes | ||
assert obj2 == matchable_resource.MatchingAttributes.from_flyte_idl(obj2.to_flyte_idl()) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy paste?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep thanks for catching