Thread
#prefect-community
    thebuleon29

    thebuleon29

    1 year ago
    Hi, I have the following code:
    import prefect
    from prefect import Flow, task
    from prefect.tasks.kubernetes.job import RunNamespacedJob
    
    
    start_body = {
        "apiVersion": "batch/v1",
        "kind": "Job",
        "metadata": {
            "name": "start"
        },
        "spec": {
            "template": {
                "spec": {
                    "containers": [
                        {
                            "name": "start",
                            "image": "alpine",
                            "command": [
                                "echo",
                                "start"
                            ]
                        }
                    ],
                    "restartPolicy": "Never"
                }
            },
            "backoffLimit": 4
        }
    }
    
    @task
    def print_kube_res(x):
        print(str(x))
    
    with Flow("Kubernetes Job") as flow:
        start = RunNamespacedJob(body=start_body, kubernetes_api_key_secret=None)
        p = print_kube_res(start)
        start.set_downstream(p)
    But here the print task prints 'None'. How do i get the result from a Kubernetes job ?
    Kevin Kho

    Kevin Kho

    1 year ago
    Hi @thebuleon29, in this case, do you want to retrieve the “start”? I don’t think this task is meant for that. You would probably need to persist the output somewhere and retrieve it by downstream tasks.