Martijn van Elferen
06/17/2024, 4:20 PMimage
url of my work pool (GCP Cloud Run Push) using the Create Flow Run From Deployment API Call. This API call has a body item called jobs_variables
. The body looks as follows:
{
"state": {
"type": "SCHEDULED"
},
"job_variables": {
"image": "eu.gcr.io/abc/prefect/prefect-pricing:development"
}
}
After the API is called and the workflow starts, the flow does not run using the specified image URL, instead it falls back to the default value. Yet, I do see the value in the Flow's job variables.
My work pool's job template looks as follows:
{
"variables": {
"type": "object",
"required": [
"credentials"
],
"properties": {
"image": {
"type": "string",
"title": "Image Name",
"default": "eu.gcr.io/xxx/prefect/prefect-pricing:production",
"description": "The image to use for the Cloud Run job. If not provided the latest Prefect image will be used."
},
...
"job_configuration": {
"env": "{{ env }}",
"name": "{{ name }}",
"labels": "{{ labels }}",
"region": "{{ region }}",
"command": "{{ command }}",
"timeout": "{{ timeout }}",
"job_body": {
"client": "prefect",
"template": {
"template": {
"timeout": "{{ timeout }}",
"containers": [
{
"env": [],
"args": "{{ args }}",
"image": "{{ image }}",
"command": "{{ command }}",
"resources": {
"limits": {
"cpu": "{{ cpu }}",
"memory": "{{ memory }}"
}
}
}
...
}
}
Why is the image value not overriding the default value? What am I doing wrong/missing?
Thanks πNate
06/18/2024, 7:21 PMMartijn van Elferen
06/19/2024, 9:23 AMimage
variable in a work pool works when I hardcode the image
value in a deployment, as job variable.
Yet, when I try to set the image job variable in a deployment as a variable like:
{
"image": "{{ $gcr_image }}"
}
and then pass it in my CLI command like
prefect deployment run \
--id "de27fd5c-eab1-4f40-8bbc-7a6684e1ceb2" \
--job-variable gcr_image="eu.gcr.io/abc/prefect/prefect-pricing:production"
the flow run will yield this error.
Expected an image path like [host/]repo-path[:tag and/or @digest], where host is one of [region.]gcr.io, [region-]docker.pkg.dev or docker.io but obtained {{ $gcr_image }}'}]}]">
Nate
06/19/2024, 6:10 PM{
"image": "{{ $gcr_image }}"
}
that is the syntax for when you want it to render an env var set on your local named gcr_image
if you want a prefect variable value to be rendered, you should use
{
"image": "{{ prefect.variables.gcr_image }}"
}
Nate
06/19/2024, 6:11 PM--job-variable gcr_image="eu.gcr.io/abc/prefect/prefect-pricing:production"
here the key you're passing should be the name of a job variable, like image
like
--job-variable image="eu.gcr.io/abc/prefect/prefect-pricing:production"
Martijn van Elferen
06/20/2024, 12:27 PM-jv syntax
included.Martijn van Elferen
06/20/2024, 12:34 PM{
"image": "eu.gcr.io/abc/prefect/prefect-pricing:production"
}
If this deployment is quick run
, the used image is this default one. β¬οΈ So far so good.
Yet, when I select custom run
and intent to override the image
value using the job variable below:
{
"image": "eu.gcr.io/abc/prefect/prefect-pricing:development"
}
Then the run is triggered using the default value (production), instead of the expected image (development).Nate
06/20/2024, 2:10 PMI expect Prefect to override this value whenever a deployment flow run is triggered withthis is how it should work today is the override failing specifically when you try from the UI?included.-jv syntax
Martijn van Elferen
06/20/2024, 5:21 PMMartijn van Elferen
06/20/2024, 8:12 PMNate
06/20/2024, 9:08 PMMartijn van Elferen
06/21/2024, 8:11 AMenv
variable was added as a parameter in the screenshot on this page.
I've detailed the steps I undertook below. Hopefully, this will help you understand the issue and reproduce it.
Work Pool:
The work pool I use is a Cloud Run Push V2. No base image is defined. Hence, if no image is passed in the deployment or flow run, it defaults back to the Prefect base image.
Deployment:
My flow is deployed using the .deploy
method:
if __name__ == "__main__":
process_pricing_xx_files.deploy(
parameters={"host": '<http://sysmgr.xxx.com|sysmgr.xxx.com>', "username": 'FTP-Agent'},
work_pool_name="cloud-run-push-pricing",
image="<http://eu.gcr.io/xxx/prefect/prefect-pricing:production|eu.gcr.io/xxx/prefect/prefect-pricing:production>",
build=False
)
Once deployed, I can see on the deployment page in the Prefect Cloud UI that the image is correctly passed as a job variable under the configuration
tab.
{
"image": "<http://eu.gcr.io/xxx/prefect/prefect-pricing:production|eu.gcr.io/xxx/prefect/prefect-pricing:production>"
}
When triggered, using the quick run
option, Google Cloud Run pulls the image as defined in the deployment. So far so good.
Custom Flow Run
This is where the unexpected behavior occurs. Whenever I perform a custom run of this deployment by triggering a flow run, I am unable to override the image
value. I have tried multiple methods. Below, I describe the CLI approach:
I execute the following command in the CLI (note that I am specifying development
as the image tag, rather than the default production
):
prefect deployment run \
--id "de27fd5c-eab1-4f40-8bbc-7a6684e1ceb2" \
--job-variable image="<http://eu.gcr.io/xxx/prefect/prefect-pricing:development|eu.gcr.io/xxx/prefect/prefect-pricing:development>"
Prefect creates a flow run and correctly reads back my variables, noting the flow run name, dramatic-swan:
Creating flow run for deployment 'process-pricing-xx-files/1tis_supplier_pricing_xx'...
Created flow run 'dramatic-swan'.
βββ UUID: 8eb04784-b910-43b9-8e94-48c91fc93ac1
βββ Parameters: {'host': '<http://sysmgr.xx.com|sysmgr.xx.com>', 'username': 'FTP-Agent'}
βββ Job Variables: {'image': '<http://eu.gcr.io/xxx/prefect/prefect-pricing:development|eu.gcr.io/xxx/prefect/prefect-pricing:development>'}
βββ Scheduled start time: 2024-06-21 09:54:09 CEST (now)
βββ URL: <https://app.prefect.cloud/account/xx/workspace/xx/flow-runs/flow-run/8eb04784-b910-43b9-8e94-48c91fc93ac1>
I can also see on the flow run page in the UI that under Job Variables, the image is overridden as expected:
{
"image": "<http://eu.gcr.io/xxx/prefect/prefect-pricing:development|eu.gcr.io/xxx/prefect/prefect-pricing:development>"
}
Yet, in Google Cloud Run, as the attached image shows, it did not override the image URL with the development
tag; instead it used production
, the default value.
In conclusion
β’ Prefect passes the image variable set during deployment correctly and normal quick runs work as expected.
β’ Custom runs with job variables that should override the image variable of a deployment are not actually overridden
Please let me know if you need additional details and thanks again!Nate
06/21/2024, 2:14 PMMartijn van Elferen
06/24/2024, 7:33 PMMartijn van Elferen
06/27/2024, 6:26 AMNate
06/27/2024, 3:05 PM