https://prefect.io logo
Title
a

Adam

10/27/2022, 11:08 AM
Hi team, could someone give me some guidance on how we can pass in an
envFrom
section to a
KubernetesJob
block. We want to include this using the Python API:
envFrom:
            - secretRef:
                name: job-secrets
r

redsquare

10/27/2022, 11:13 AM
customizations=[]
infra_overrides=dict()
#Build secret patch for job image
for secret in secrets_list:
item = {    "op": "add",
"path": "/spec/template/spec/containers/0/env/-",
"value": {
"name": secret.upper(),
"valueFrom": {
"secretKeyRef": {
"name": "prefect-flow-secrets",  "key": secret.upper()
}
}
}
}
customizations.append(item)
if len(customizations)>0:
infra_overrides['customizations'] = customizations
then set
infra_overrides = infra_overrides
in the deployment
a

Adam

10/27/2022, 11:15 AM
amazing, you rock. thank you!
could this customization also be used in the
KubernetesJob.customizations
block https://docs.prefect.io/api-ref/prefect/infrastructure/#prefect.infrastructure.kubernetes.KubernetesJob
r

redsquare

10/27/2022, 11:16 AM
not tried as our secrets list are flow specific so need to generate per deploy
a

Adam

10/27/2022, 11:16 AM
gotcha. will give it a try and paste back result for reference
r

redsquare

10/27/2022, 11:16 AM
but yeah that is just the same patch
a

Adam

10/27/2022, 11:22 AM
Ah this is great too.
job=KubernetesJob.job_from_file("modified_run_job.yaml")
Thats more or less how we used to do it in prefect v1
q

Q

10/27/2022, 11:23 AM
I'm not sure adding
envFrom
via
customizations
to default template would work, since
envFrom
is not set in the default template and I think jsonpatches need the array to exist beforehand
a

Adam

10/27/2022, 1:19 PM
I think you’re right. It didn’t work for me. Presumably because
envFrom
was missing
p

Patrick Alves

11/03/2022, 4:25 PM
Hi @Adam Have you found a solution to your request? I need to do the same thing
a

Adam

11/03/2022, 4:26 PM
Hey @Patrick Alves, we decided to just do it in an external yaml like this:
1
import os

from prefect.infrastructure.kubernetes import KubernetesImagePullPolicy, KubernetesJob

dir_path = os.path.dirname(os.path.realpath(__file__))

job = KubernetesJob(
    namespace="prefect",
    image_pull_policy=KubernetesImagePullPolicy.ALWAYS,
    image="xxx",
    job=KubernetesJob.job_from_file(dir_path + "/kubernetes-job-default.yaml"),
)

job.save("kubernetes-job-default", overwrite=True)
and in the yaml, just the normal:
containers:
      - name: prefect-job
        image: ""
        envFrom:
          - secretRef:
              name: doppler-secrets-sett-prefect-staging
etc
p

Patrick Alves

11/03/2022, 4:27 PM
Got it, thanks for the quick response!
a

Adam

11/03/2022, 4:27 PM
couldnt make it work using python DSL