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

Add environment variables from GCP secrets to cloud run job v2 workers #15423

Merged

Conversation

Ultramann
Copy link
Contributor

This PR adds the ability to create environment variables from GCP secrets in cloud run v2 prefect workers. To do so a new attribute was added to cloud run job v2 workers configurations, env_from_secrets which allows for the referencing of GCP secrets in a cloud run job v2 worker template with the following structure.

{
  "job_configuration": {
    "env_from_secrets": "{{ env_from_secrets }}"
  },
  "variables": {
    "env_from_secrets": {
      "title": "Secrets as Environment Variables",
      "description": "Environment variables to set from GCP secrets when starting a flow run.",
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    }
  }
}

Deployments can then set environment variables from secrets via job variables, e.g.

"env_from_secrets": {
  "ENV_VAR": {
    "secret": "SECRET_NAME",
    "version": "latest"
  }
}

Closes #15406

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
  • If this pull request adds new functionality, it includes unit tests that cover the changes
  • If this pull request removes docs files, it includes redirect settings in mint.json.
  • If this pull request adds functions or classes, it includes helpful docstrings.

@github-actions github-actions bot added the enhancement An improvement of an existing feature label Sep 18, 2024
Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @Ultramann! The implementation looks good, but I think we need an attribute for this field on CloudRunWorkerV2Variables to ensure it shows up in the UI.

Something like this should work:

    env_from_secrets: Dict[str, SecretKeySelector] = Field(
        default_factory=dict,
        title="Environment Variables from Secrets",
        description="Environment variables to set from GCP secrets when starting a flow run.",
        example={
            "ENV_VAR_NAME": {
                "secret": "SECRET_NAME",
                "version": "latest",
            }
        },
    )

Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@desertaxle desertaxle merged commit 0a5e38a into PrefectHQ:main Sep 19, 2024
12 checks passed
@Ultramann
Copy link
Contributor Author

@desertaxle Thanks for the quick review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable environment variables from GCP secrets in GCP cloud run v2 workers
2 participants