Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new helper function mergeVpc in src/v2/options.ts to correctly merge global and function-specific VPC configurations. It ensures that setting a specific VPC connector/network interface or egress setting does not inadvertently drop the other global VPC configuration. This helper is integrated across all v2 event providers (including AI, Alerts, Database, Firestore, HTTPS, Pub/Sub, and others) to maintain consistent VPC merging behavior. Comprehensive unit tests have been added to verify various merging scenarios and reset behaviors. There are no review comments, and I have no additional feedback to provide.
IzaakGough
left a comment
There was a problem hiding this comment.
Hi @Ultranmus Thanks for the contribution! This fix looks right to me.
One suggestion for the release note: a function that sets its own vpcConnector or networkInterface but no vpcEgress now inherits the global vpcEgress. Before, it got the platform default (PRIVATE_RANGES_ONLY). It may be worth a line, for example: "A v2 function that sets its own VPC connector or network interface, but no egress setting, now inherits the global VPC egress setting instead of the default."
| ).to.deep.equal({ vpc: { connector: "global", egressSettings: "ALL_TRAFFIC" } }); | ||
| }); | ||
|
|
||
| it("should reset vpc when the function resets it", () => { |
There was a problem hiding this comment.
Could we add a case for a function resetting only its egress? Since the global egress is now inherited, vpcEgress: RESET_VALUE is the way to opt out, so it would be good to pin it:
it("should keep the global connector when the function resets only egress", () => {
expect(
mergeVpc(
{ vpc: { connector: "global", egressSettings: "ALL_TRAFFIC" } },
{ vpc: { egressSettings: RESET_VALUE } }
)
).to.deep.equal({ vpc: { connector: "global", egressSettings: RESET_VALUE } });
});There was a problem hiding this comment.
Added, thanks. I also put your egress line in the release note.
optionsToEndpoint builds a complete vpc object for the global options and another for the function's options, and the providers merge them with a shallow spread. So a function that set only vpcConnectorEgressSettings (or vpcEgress) replaced the global vpc, the connector was dropped, and the deploy failed with "VPC settings on fn must specify either 'connector' or 'networkInterfaces'". Add mergeVpc() and use it in every v2 provider that builds an endpoint from global and function options. The function's network (connector or network interfaces) replaces the global one when it sets one, its egress setting replaces the global one when it sets one, and a reset vpc still opts out. Fixes firebase#2002
45a0b35 to
d4405c1
Compare
Description
Fixes #2002.
A function that sets only
vpcConnectorEgressSettings(orvpcEgress) no longer drops avpcConnectorset insetGlobalOptions. The deploy used to fail with "VPC settings on fn must specify either 'connector' or 'networkInterfaces'".optionsToEndpointbuilds a completevpcobject for the global options and another for the function's options, and each provider merges them with a shallow spread, so the function'svpcreplaced the global one. This addsmergeVpc()tosrc/v2/options.tsand uses it in every v2 provider that builds an endpoint from global and function options (18 endpoints in 15 files, next to the existinglabelsmerge):connectorornetworkInterfaces) replaces the global network when the function sets one. Otherwise the global network is kept. Setting a different kind replaces it, so a mergedvpcnever has both.egressSettingsreplaces the global one when the function sets it. Otherwise the global egress setting is kept.vpcis a reset value still opts out of VPC.The legacy
__triggerannotations keep these options as flat keys, so the spread already merged them correctly; only__endpointchanges. v1 has no global options merge.This only touches how global and function options are combined, not how
optionsToEndpointreadsRESET_VALUE, so it should not conflict with #1978.Code sample
Testing
mergeVpcunit tests inspec/v2/options.spec.ts: no vpc, global only, function only, egress only over a global connector or global network interfaces, a connector only over a global egress, a different network kind, egress override, a function resetting only its egress, and both reset cases.onMessagePublishedandonRequestin their provider specs.vpcreplacing the global one), 6 of the new tests fail, including both repros.npm test: 1012 passing.npm run buildandnpm run lintpass (no new warnings in the changed files).Release notes
relnote: Fixed a global
vpcConnectorbeing dropped when a v2 function sets only its VPC egress setting. A v2 function that sets its own VPC connector or network interface, but no egress setting, now inherits the global VPC egress setting instead of the default.