-
Notifications
You must be signed in to change notification settings - Fork 1k
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
base: master
Are you sure you want to change the base?
Changes from all commits
7ef4f67
4e61dbe
3d43507
ec92c97
2ae9410
5ba79ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -359,8 +359,12 @@ | |||||||||
operationResourceName: op.name, | ||||||||||
}); | ||||||||||
return gcfV2.endpointFromFunction(cfn); | ||||||||||
} else if (endpoint.platform === "run") { | ||||||||||
// 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."); | ||||||||||
Comment on lines
+363
to
+365
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad suggestion |
||||||||||
} else { | ||||||||||
assertExhaustive(endpoint.platform); | ||||||||||
Check failure on line 367 in src/functions/secrets.ts
|
||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { expect } from "chai"; | ||
import * as k8s from "./k8s"; | ||
|
||
describe("megabytes", () => { | ||
enum Bytes { | ||
KB = 1e3, | ||
MB = 1e6, | ||
GB = 1e9, | ||
KiB = 1 << 10, | ||
MiB = 1 << 20, | ||
GiB = 1 << 30, | ||
} | ||
|
||
it("Should handle decimal SI units", () => { | ||
expect(k8s.mebibytes("1000k")).to.equal((1000 * Bytes.KB) / Bytes.MiB); | ||
expect(k8s.mebibytes("1.5M")).to.equal((1.5 * Bytes.MB) / Bytes.MiB); | ||
expect(k8s.mebibytes("1G")).to.equal(Bytes.GB / Bytes.MiB); | ||
}); | ||
|
||
it("Should handle binary SI units", () => { | ||
expect(k8s.mebibytes("1Mi")).to.equal(Bytes.MiB / Bytes.MiB); | ||
expect(k8s.mebibytes("1Gi")).to.equal(Bytes.GiB / Bytes.MiB); | ||
}); | ||
|
||
it("Should handle no unit", () => { | ||
expect(k8s.mebibytes("100000")).to.equal(100000 / Bytes.MiB); | ||
expect(k8s.mebibytes("1e9")).to.equal(1e9 / Bytes.MiB); | ||
expect(k8s.mebibytes("1.5E6")).to.equal((1.5 * 1e6) / Bytes.MiB); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// AvailableMemory suffixes and their byte count. | ||
type MemoryUnit = "" | "k" | "M" | "G" | "T" | "Ki" | "Mi" | "Gi" | "Ti"; | ||
const BYTES_PER_UNIT: Record<MemoryUnit, number> = { | ||
"": 1, | ||
k: 1e3, | ||
M: 1e6, | ||
G: 1e9, | ||
T: 1e12, | ||
Ki: 1 << 10, | ||
Mi: 1 << 20, | ||
Gi: 1 << 30, | ||
Ti: 1 << 40, | ||
}; | ||
/** | ||
* Returns the float-precision number of Mebi(not Mega)bytes in a | ||
* Kubernetes-style quantity | ||
* Must serve the same results as | ||
* https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/api/resource/quantity.go | ||
*/ | ||
|
||
export function mebibytes(memory: string): number { | ||
const re = /^([0-9]+(\.[0-9]*)?)(Ki|Mi|Gi|Ti|k|M|G|T|([eE]([0-9]+)))?$/; | ||
const matches = re.exec(memory); | ||
if (!matches) { | ||
throw new Error(`Invalid memory quantity "${memory}""`); | ||
} | ||
const quantity = Number.parseFloat(matches[1]); | ||
let bytes: number; | ||
if (matches[5]) { | ||
bytes = quantity * Math.pow(10, Number.parseFloat(matches[5])); | ||
} else { | ||
const suffix = matches[3] || ""; | ||
bytes = quantity * BYTES_PER_UNIT[suffix as MemoryUnit]; | ||
} | ||
return bytes / (1 << 20); | ||
} | ||
|
||
export interface PlaintextEnvVar { | ||
name: string; | ||
value: string; | ||
} | ||
|
||
export interface SecretEnvVar { | ||
name: string; | ||
valueSource: { | ||
secretKeyRef: { | ||
secret: string; // Secret name | ||
version?: string; // Optional version, defaults to latest | ||
}; | ||
}; | ||
} | ||
|
||
export type EnvVar = PlaintextEnvVar | SecretEnvVar; | ||
|
||
export type ResourceType = "cpu" | "memory" | "nvidia.com/gpu"; | ||
|
||
export interface Container { | ||
name?: string; | ||
image: string; | ||
command?: string[]; | ||
args?: string[]; | ||
env: EnvVar[]; | ||
workingDir?: string; | ||
resources: { | ||
limits: Record<ResourceType, string>; | ||
}; | ||
cpuIdle?: boolean; | ||
startupCpuBoost?: boolean; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.There was a problem hiding this comment.
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.