Exemple #1
0
def test_task_template__k8s_pod_target():
    int_type = types.LiteralType(types.SimpleType.INTEGER)
    obj = task.TaskTemplate(
        identifier.Identifier(identifier.ResourceType.TASK, "project",
                              "domain", "name", "version"),
        "python",
        task.TaskMetadata(
            False,
            task.RuntimeMetadata(1, "v", "f"),
            timedelta(days=1),
            literal_models.RetryStrategy(5),
            False,
            "1.0",
            "deprecated",
            False,
        ),
        interface_models.TypedInterface(
            # inputs
            {"a": interface_models.Variable(int_type, "description1")},
            # outputs
            {
                "b": interface_models.Variable(int_type, "description2"),
                "c": interface_models.Variable(int_type, "description3"),
            },
        ),
        {
            "a": 1,
            "b": {
                "c": 2,
                "d": 3
            }
        },
        config={"a": "b"},
        k8s_pod=task.K8sPod(
            metadata=task.K8sObjectMetadata(labels={"label": "foo"},
                                            annotations={"anno": "bar"}),
            pod_spec={
                "str": "val",
                "int": 1
            },
        ),
    )
    assert obj.id.resource_type == identifier.ResourceType.TASK
    assert obj.id.project == "project"
    assert obj.id.domain == "domain"
    assert obj.id.name == "name"
    assert obj.id.version == "version"
    assert obj.type == "python"
    assert obj.custom == {"a": 1, "b": {"c": 2, "d": 3}}
    assert obj.k8s_pod.metadata == task.K8sObjectMetadata(
        labels={"label": "foo"}, annotations={"anno": "bar"})
    assert obj.k8s_pod.pod_spec == {"str": "val", "int": 1}
    assert text_format.MessageToString(
        obj.to_flyte_idl()) == text_format.MessageToString(
            task.TaskTemplate.from_flyte_idl(
                obj.to_flyte_idl()).to_flyte_idl())
    assert obj.config == {"a": "b"}
Exemple #2
0
 def get_k8s_pod(self, settings: SerializationSettings) -> _task_models.K8sPod:
     return _task_models.K8sPod(
         pod_spec=self._serialize_pod_spec(settings),
         metadata=_task_models.K8sObjectMetadata(
             labels=self.task_config.labels,
             annotations=self.task_config.annotations,
         ),
     )
Exemple #3
0
def test_k8s_pod():
    obj = task.K8sPod(metadata=task.K8sObjectMetadata(labels={"label": "foo"}), pod_spec={"pod_spec": "bar"})
    assert obj.metadata.labels == {"label": "foo"}
    assert obj.pod_spec == {"pod_spec": "bar"}
    assert obj == task.K8sPod.from_flyte_idl(obj.to_flyte_idl())
Exemple #4
0
def test_k8s_metadata():
    obj = task.K8sObjectMetadata(labels={"label": "foo"}, annotations={"anno": "bar"})
    assert obj.labels == {"label": "foo"}
    assert obj.annotations == {"anno": "bar"}
    assert obj == task.K8sObjectMetadata.from_flyte_idl(obj.to_flyte_idl())