-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for specifying k8s tolerations (#192)
People may want/need more control over which nodes their jobs run on. K8s tolerations is a mechanism many people use to achieve this. If we don't support them, people may not be able to run their Sematic funcs where they want them to go. This adds support for it. It also adds support for enums, because the natural way to support tolerations includes some enum types that are currently serialized/deserialized with Sematic's type stuff. It fails without actual enum support. I've wanted enum support a few times anyway, so I took this opportunity to "bite the bullet."
- Loading branch information
Showing
17 changed files
with
460 additions
and
5 deletions.
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
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,55 @@ | ||
import pytest | ||
|
||
# Sematic | ||
from sematic.resolvers.resource_requirements import ( | ||
KubernetesResourceRequirements, | ||
KubernetesSecretMount, | ||
KubernetesToleration, | ||
KubernetesTolerationEffect, | ||
KubernetesTolerationOperator, | ||
ResourceRequirements, | ||
) | ||
from sematic.types.serialization import ( | ||
value_from_json_encodable, | ||
value_to_json_encodable, | ||
) | ||
|
||
|
||
def test_is_serializable(): | ||
requirements = ResourceRequirements( | ||
kubernetes=KubernetesResourceRequirements( | ||
node_selector={"foo": "bar"}, | ||
requests={"cpu": "500m", "memory": "100Gi"}, | ||
secret_mounts=KubernetesSecretMount( | ||
environment_secrets={"a": "b"}, | ||
file_secret_root_path="/foo/bar", | ||
file_secrets={"c": "d"}, | ||
), | ||
tolerations=[ | ||
KubernetesToleration( | ||
key="k", | ||
value="v", | ||
effect=KubernetesTolerationEffect.NoExecute, | ||
operator=KubernetesTolerationOperator.Equal, | ||
toleration_seconds=42, | ||
) | ||
], | ||
) | ||
) | ||
encoded = value_to_json_encodable(requirements, ResourceRequirements) | ||
decoded = value_from_json_encodable(encoded, ResourceRequirements) | ||
assert decoded == requirements | ||
|
||
|
||
def test_validation(): | ||
with pytest.raises( | ||
ValueError, | ||
match="toleration_seconds should only be specified when the effect is NoExecute.", | ||
): | ||
KubernetesToleration( | ||
key="k", | ||
value="v", | ||
effect=KubernetesTolerationEffect.PreferNoSchedule, | ||
operator=KubernetesTolerationOperator.Equal, | ||
toleration_seconds=42, | ||
) |
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
Oops, something went wrong.