Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/packages/gcp-metadata/src/gcp-residency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ export function isGoogleCloudServerless(): boolean {
* `K_SERVICE` is used in Cloud Run and newer Cloud Functions environments:
* - See {@link https://cloud.google.com/run/docs/container-contract#env-vars Cloud Run environment variables}.
* - See {@link https://cloud.google.com/functions/docs/env-var Cloud Functions newer runtimes}.
*
* `CLOUD_RUN_WORKER_POOL` is used for Cloud Run worker pools:
* - See {@link https://cloud.google.com/run/docs/container-contract#env-vars Cloud Run environment variables}.
*/
const isGFEnvironment =
process.env.CLOUD_RUN_JOB ||
process.env.FUNCTION_NAME ||
process.env.K_SERVICE;
process.env.K_SERVICE ||
process.env.CLOUD_RUN_WORKER_POOL;

return !!isGFEnvironment;
}
Expand Down
6 changes: 6 additions & 0 deletions core/packages/gcp-metadata/test/gcp-residency.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ describe('gcp-residency', () => {
assert(gcpResidency.isGoogleCloudServerless());
});

it('should return `true` if `CLOUD_RUN_WORKER_POOL` env is set', () => {
process.env.CLOUD_RUN_WORKER_POOL = '1';

assert(gcpResidency.isGoogleCloudServerless());
});

it('should return `false` if none of the envs are set', () => {
assert.equal(gcpResidency.isGoogleCloudServerless(), false);
});
Expand Down
1 change: 1 addition & 0 deletions core/packages/gcp-metadata/test/utils/gcp-residency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {strict as assert} from 'assert';

Check warning on line 17 in core/packages/gcp-metadata/test/utils/gcp-residency.ts

View workflow job for this annotation

GitHub Actions / lint

'assert' is defined but never used
import fs from 'fs';
import os from 'os';

Expand All @@ -27,12 +27,12 @@
* Stubs used in this utility. These are used within the provided sandbox.
* */
stubs: {
[key in

Check failure on line 30 in core/packages/gcp-metadata/test/utils/gcp-residency.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎······`
| 'fsReadFileSync'

Check failure on line 31 in core/packages/gcp-metadata/test/utils/gcp-residency.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
| 'fsStatSync'

Check failure on line 32 in core/packages/gcp-metadata/test/utils/gcp-residency.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
| 'processEnv'

Check failure on line 33 in core/packages/gcp-metadata/test/utils/gcp-residency.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
| 'osNetworkInterfaces'

Check failure on line 34 in core/packages/gcp-metadata/test/utils/gcp-residency.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
| 'osPlatform']?: SinonStub | void;

Check failure on line 35 in core/packages/gcp-metadata/test/utils/gcp-residency.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `······|·'osPlatform'` with `········|·'osPlatform'⏎····`
} = {};

constructor(public sandbox: SinonSandbox) {}
Expand Down Expand Up @@ -109,6 +109,7 @@
delete customEnv.CLOUD_RUN_JOB;
delete customEnv.FUNCTION_NAME;
delete customEnv.K_SERVICE;
delete customEnv.CLOUD_RUN_WORKER_POOL;

this.stubs.processEnv ??= this.sandbox.stub(process, 'env');
this.stubs.processEnv.value(customEnv);
Expand Down
Loading