Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

feat: add detection for Cloud Run#1177

Merged
JustinBeckwith merged 2 commits intomasterfrom
detectrun
May 21, 2021
Merged

feat: add detection for Cloud Run#1177
JustinBeckwith merged 2 commits intomasterfrom
detectrun

Conversation

@JustinBeckwith
Copy link
Contributor

@JustinBeckwith JustinBeckwith commented May 19, 2021

Fixes #1155. This adds detection for Cloud Run via the K_CONFIGURATION env var. The order of checks is important in that it:

  • First makes sure there's a GCE Metadata server available
  • Makes sure we're not on k8s
  • Then finally checks for the env var

This should help get rid of false positives via Knative on k8s or non-gcp environments.

@JustinBeckwith JustinBeckwith requested a review from a team as a code owner May 19, 2021 23:37
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label May 19, 2021
@JustinBeckwith JustinBeckwith merged commit 4512363 into master May 21, 2021
@JustinBeckwith JustinBeckwith deleted the detectrun branch May 21, 2021 16:40
Comment on lines +73 to +75
function isCloudRun() {
return !!process.env.K_CONFIGURATION;
}

Choose a reason for hiding this comment

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

I guess it's too late now but we should be querying metadata endpoint first and use this env variable only in case metadata endpoint doesn't return the environment

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GCPEnv to detect more GCP services

3 participants