Skip to content

Commit

Permalink
Adds an omit parametrized configuration option for functions to skip …
Browse files Browse the repository at this point in the history
…deploy (#5117)
  • Loading branch information
Berlioz committed Nov 9, 2022
1 parent be10d72 commit dc44460
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/deploy/functions/build.ts
Expand Up @@ -220,6 +220,9 @@ export const AllIngressSettings: IngressSetting[] = [
];

export type Endpoint = Triggered & {
// Defaults to false. If true, the function will be ignored during the deploy process.
omit?: Field<boolean>;

// Defaults to "gcfv2". "Run" will be an additional option defined later
platform?: "gcfv1" | "gcfv2";

Expand Down Expand Up @@ -413,6 +416,9 @@ export function toBackend(
const bkEndpoints: Array<backend.Endpoint> = [];
for (const endpointId of Object.keys(build.endpoints)) {
const bdEndpoint = build.endpoints[endpointId];
if (r.resolveBoolean(bdEndpoint.omit || false)) {
continue;
}

let regions = bdEndpoint.region;
if (typeof regions === "undefined") {
Expand Down
3 changes: 3 additions & 0 deletions src/deploy/functions/runtimes/discovery/v1alpha1.ts
Expand Up @@ -44,6 +44,7 @@ export type WireEndpoint = build.Triggered &
Partial<build.TaskQueueTriggered> &
Partial<build.BlockingTriggered> &
Partial<{ scheduleTrigger: WireScheduleTrigger }> & {
omit?: build.Field<boolean>;
labels?: Record<string, string> | null;
environmentVariables?: Record<string, string> | null;
availableMemoryMb?: build.MemoryOption | build.Expression<number> | null;
Expand Down Expand Up @@ -124,6 +125,7 @@ function assertBuildEndpoint(ep: WireEndpoint, id: string): void {
region: "array",
platform: (platform) => build.AllFunctionsPlatforms.includes(platform),
entryPoint: "string",
omit: "Field<boolean>?",
availableMemoryMb: (mem) => mem === null || isCEL(mem) || build.isValidMemoryOption(mem),
maxInstances: "Field<number>?",
minInstances: "Field<number>?",
Expand Down Expand Up @@ -395,6 +397,7 @@ function parseEndpointForBuild(
copyIfPresent(
parsed,
ep,
"omit",
"availableMemoryMb",
"cpu",
"maxInstances",
Expand Down
29 changes: 29 additions & 0 deletions src/test/deploy/functions/build.spec.ts
Expand Up @@ -44,6 +44,35 @@ describe("toBackend", () => {
}
});

it("doesn't populate if omit is set on the build", () => {
const desiredBuild: build.Build = build.of({
func: {
omit: true,
platform: "gcfv1",
region: ["us-central1"],
project: "project",
runtime: "nodejs16",
entryPoint: "func",
maxInstances: 42,
minInstances: 1,
serviceAccount: "service-account-1@",
vpc: {
connector: "projects/project/locations/region/connectors/connector",
egressSettings: "PRIVATE_RANGES_ONLY",
},
ingressSettings: "ALLOW_ALL",
labels: {
test: "testing",
},
httpsTrigger: {
invoker: ["public"],
},
},
});
const backend = build.toBackend(desiredBuild, {});
expect(Object.keys(backend.endpoints).length).to.equal(0);
});

it("populates multiple specified invokers correctly", () => {
const desiredBuild: build.Build = build.of({
func: {
Expand Down

0 comments on commit dc44460

Please sign in to comment.