Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud Run Jobs customization #260

Closed
AdeelK93 opened this issue Oct 15, 2022 · 4 comments · Fixed by #262
Closed

Cloud Run Jobs customization #260

AdeelK93 opened this issue Oct 15, 2022 · 4 comments · Fixed by #262
Labels
documentation Improvements or additions to documentation

Comments

@AdeelK93
Copy link
Contributor

Hi I'm trying to customize a few things about the cloud run jobs deployment, but can't find any documentation or examples on how to change:

  • cpu/memory resources
  • timeout
  • number of retries
  • VPC connector
  • total number of tasks

Would love some help! Thanks

@anovis anovis added the documentation Improvements or additions to documentation label Oct 17, 2022
@anovis
Copy link
Collaborator

anovis commented Oct 17, 2022

Thanks for the issue and will add some more documentation to the example config. Most fields can be set in either the job spec or job container fields. https://cloud.google.com/run/docs/reference/rest/v1/TaskSpec for a reference.

The total number of tasks is calculated by goblet based on the number of task_id set for the specific job.
ie

app.job("test", task_id=0)
app.job("test", task_id=1)
app.job("test", task_id=2)

will result in number of tasks to be 3.

@rasnes
Copy link

rasnes commented Oct 17, 2022

By looking at the code it was possible to see how one could change this values by directly controlling the JSON that goblet deploys the Job with:

def _deploy(self, source=None, entrypoint=None, config={}):
if not self.resources:
return
config = GConfig(config=config)
artifact = getCloudbuildArtifact(
self.versioned_clients.cloudbuild, self.name, config=config
)
log.info("deploying cloudrun jobs......")
for job_name, job in self.resources.items():
container = {**(config.job_container or {})}
container["image"] = artifact
container["command"] = [
"goblet",
"job",
"run",
job_name,
]
job_spec = {
"apiVersion": "run.googleapis.com/v1",
"kind": "Job",
"metadata": {
"name": job_name,
"annotations": {"run.googleapis.com/launch-stage": "BETA"},
},
"spec": {
"template": {
"spec": {
"taskCount": len(job.keys()) - 1,
"template": {
"spec": {
"containers": [container],
**(config.job_spec or {}),
}
},
},
**job["execution_spec"],
}
},
}

For example, I now deploy with this in my .goblet/config.json:

{
	...,
    "job_spec": {
        "serviceAccountName": "<sa-name>@<project-id>.iam.gserviceaccount.com",
        "timeoutSeconds": "3600",
        "maxRetries": 3
    },
    "job_container": {
        "resources": {
            "limits": {
                "memory": "8Gi",
                "cpu": "2000m"
            }
        },
        "env": [
            {
                "name": "GOOGLE_PROJECT",
                "value": "<project-id>"
            },
            {
                "name": "GOOGLE_ENV",
                "value": "test"
            }
        ]
    }
}

I believe you can set the VPC connector in this JSON as well, but haven't checked.

@anovis
Copy link
Collaborator

anovis commented Oct 17, 2022

@rasnes thanks for the example. i have updated the example config.json and will try to add more examples there going forward as it is a pain to read the code or go through the gcp docs to figure out where to place what.

also it looks like the vpc connector info is actually set as annotations in the metadata field, so added a pr that allows those fields to be passed in as well (#262 )

@anovis anovis closed this as completed in 79901d8 Oct 17, 2022
@AdeelK93
Copy link
Contributor Author

Thank you both, this was very helpful!
job_annotations - who woulda guessed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants