Skip to content

Cloud Run Functions data model #8767

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

inlined
Copy link
Member

@inlined inlined commented Jun 18, 2025

Thanks for your patience. I've got part one of 2-3 on getting some PoCs ready for CRF. This just extends the data model to support the RunV2 API (needed for the submit build stuff), the service<->endpoint stuff, and the changes that popped up with assertExhaustive once a new type has been added.

This PR exposed two bugs (not fixed):

  1. The Eventarc source is not converting function IDs to service IDs (which can use a utility function where there is a TODO in the runv2 code)
  2. The billing calculator was created when GCFv2 had a different SKU and that's no longer the case. But the billing change will also go out, so we need to figure out which way to fix it.

@taeold
Copy link
Contributor

taeold commented Jul 2, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request extends the data model to support Cloud Run Functions, introducing a new 'run' platform type. The changes include refactoring shared utilities into a new k8s.ts file and adding a comprehensive runv2.ts module with tests for interacting with the Cloud Run v2 API.

My review focuses on ensuring consistency and correctness in the new code. I've identified areas for improvement, including an inconsistency in the AllFunctionsPlatforms array, a potential bug in how CPU values are handled, and critical bugs related to function ID conversion and billing calculations.

// N.B. If GCF starts allowing v1's allowable characters in IDs they're
// going to need to have a transform to create a service ID (which has a
// more restrictive character set). We'll need to reimplement that here.
// BUG BUG BUG. This has happened and we need to fix it.

Choose a reason for hiding this comment

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

high

This comment indicates a known issue where the function ID to service ID conversion is not happening. It's marked as a BUG BUG BUG, suggesting it's critical and needs to be addressed.

Suggested change
// BUG BUG BUG. This has happened and we need to fix it.
// TODO: Implement function ID to service ID conversion

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO the severity of this comment is accurate. This is a WIP and a BUG should be resolved before releasing to the public whereas a TODO can be ignored for years.

],
resources: {
limits: {
cpu: String((endpoint.cpu as Number) || 1),

Choose a reason for hiding this comment

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

medium

Using the logical OR || for default values can lead to unexpected behavior if 0 is a valid value for endpoint.cpu. The nullish coalescing operator ?? is safer as it only provides the default for null or undefined values.

Suggested change
cpu: String((endpoint.cpu as Number) || 1),
cpu: String((endpoint.cpu as number) ?? 1),

Copy link
Member Author

Choose a reason for hiding this comment

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

0 is not a valid value AFAIK, so this shouldn't make a difference.

Comment on lines +363 to +365
// This may be tricky because the image has been deleted. How does this work
// with GCF?
throw new FirebaseError("Updating Cloud Run functions is not yet implemented.");

Choose a reason for hiding this comment

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

medium

This error message is not very informative. Consider adding more context to the error message to help users understand why updating Cloud Run functions is not yet implemented.

Suggested change
// This may be tricky because the image has been deleted. How does this work
// with GCF?
throw new FirebaseError("Updating Cloud Run functions is not yet implemented.");
throw new FirebaseError("Updating secrets for Cloud Run functions is not yet implemented. Please use GCFv2.");

Copy link
Member Author

Choose a reason for hiding this comment

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

Bad suggestion

Address robo-review

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Comment on lines +262 to +272
export const RUNTIME_LABEL = "goog-cloudfunctions-runtime";
export const CLIENT_NAME_LABEL = "goog-managed-by";
export const CLIENT_NAME_ANNOTATION = "run.googleapis.com/client-name";
export const CPU_BOOST_ANNOTATION = "run.googleapis.com/startup-cpu-boost";
export const TRIGGER_TYPE_ANNOTATION = "cloudfunctions.googleapis.com/trigger-type";
export const FUNCTION_TARGET_ANNOTATION = "run.googleapis.com/build-function-target"; // e.g. '{"worker":"triggerTest"}'
export const FUNCTION_ID_ANNOTATION = "cloudfunctions.googleapis.com/function-id"; // e.g. "triggerTest"
export const BASE_IMAGE_ANNOTATION = "run.googleapis.com/base-images"; // : '{"worker":"us-central1-docker.pkg.dev/serverless-runtimes/google-22-full/runtimes/nodejs22"}'
export const MAX_INSTANCES_ANNOTATION = "autoscaling.knative.dev/maxScale";
export const MIN_INSTANCES_ANNOTATION = "autoscaling.knative.dev/minScale";
export const DEFAULT_FUNCTION_CONTAINER_NAME = "worker";
Copy link
Contributor

Choose a reason for hiding this comment

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

In https://cloud.google.com/run/docs/reference/rest/v2/projects.locations.services#Service

Cloud Run API v2 does not support annotations with run.googleapis.com, cloud.googleapis.com, serving.knative.dev, or autoscaling.knative.dev namespaces, and they will be rejected in new resources. All system annotations in v1 now have a corresponding field in v2 Service.

Suspect we'll have to refactor many of these?

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

Successfully merging this pull request may close these issues.

2 participants