From 1b96e2d8d4817afca9b6eac1c06f3f7056d8d298 Mon Sep 17 00:00:00 2001 From: Hans Kristian Flaatten Date: Mon, 6 Nov 2023 09:14:12 +0100 Subject: [PATCH] Add support for GOOGLE_CLOUD_PROJECT environment variable --- pkg/resourcecreator/google/gcp/gcp.go | 8 ++++++++ pkg/resourcecreator/testdata/gcp_bigquery.yaml | 2 ++ .../testdata/gcp_bigquery_cascading_delete.yaml | 2 ++ pkg/resourcecreator/testdata/gcp_buckets.yaml | 2 ++ .../testdata/gcp_buckets_publicaccessprevention.yaml | 2 ++ .../testdata/gcp_buckets_uniformlevelaccess.yaml | 2 ++ .../gcp_buckets_with_lifecycle_and_retention.yaml | 2 ++ pkg/resourcecreator/testdata/gcp_database.yaml | 2 ++ .../testdata/gcp_database_with_insights.yaml | 2 ++ .../naisjob/cronjob_gcp_bigquery_cascading_delete.yaml | 2 ++ .../testdata/naisjob/cronjob_gcp_buckets.yaml | 2 ++ .../testdata/naisjob/cronjob_gcp_database.yaml | 2 ++ 12 files changed, 30 insertions(+) diff --git a/pkg/resourcecreator/google/gcp/gcp.go b/pkg/resourcecreator/google/gcp/gcp.go index 173b9d06e..34e5ace45 100644 --- a/pkg/resourcecreator/google/gcp/gcp.go +++ b/pkg/resourcecreator/google/gcp/gcp.go @@ -41,6 +41,14 @@ func Create(source Source, ast *resource.Ast, cfg Config) error { googleServiceAccount := google_iam.CreateServiceAccount(source, projectID) googleServiceAccountBinding := google_iam.CreatePolicy(source, &googleServiceAccount, projectID) + + // Standard environment variable name in Google SDKs + ast.Env = append(ast.Env, v1.EnvVar{ + Name: "GOOGLE_CLOUD_PROJECT", + Value: teamProjectID, + }) + + // Legacy environment variable for backwards compability ast.Env = append(ast.Env, v1.EnvVar{ Name: "GCP_TEAM_PROJECT_ID", Value: teamProjectID, diff --git a/pkg/resourcecreator/testdata/gcp_bigquery.yaml b/pkg/resourcecreator/testdata/gcp_bigquery.yaml index 571a049fa..15f51b4f2 100644 --- a/pkg/resourcecreator/testdata/gcp_bigquery.yaml +++ b/pkg/resourcecreator/testdata/gcp_bigquery.yaml @@ -87,6 +87,8 @@ tests: containers: - image: navikt/myapplication:1.2.3 env: + - name: GOOGLE_CLOUD_PROJECT + value: team-project-id - name: GCP_TEAM_PROJECT_ID value: team-project-id dnsPolicy: ClusterFirst diff --git a/pkg/resourcecreator/testdata/gcp_bigquery_cascading_delete.yaml b/pkg/resourcecreator/testdata/gcp_bigquery_cascading_delete.yaml index 90c9cea5f..f3fa37cd4 100644 --- a/pkg/resourcecreator/testdata/gcp_bigquery_cascading_delete.yaml +++ b/pkg/resourcecreator/testdata/gcp_bigquery_cascading_delete.yaml @@ -90,6 +90,8 @@ tests: containers: - image: navikt/myapplication:1.2.3 env: + - name: GOOGLE_CLOUD_PROJECT + value: team-project-id - name: GCP_TEAM_PROJECT_ID value: team-project-id dnsPolicy: ClusterFirst diff --git a/pkg/resourcecreator/testdata/gcp_buckets.yaml b/pkg/resourcecreator/testdata/gcp_buckets.yaml index 6bf1aac70..9a0761e9c 100644 --- a/pkg/resourcecreator/testdata/gcp_buckets.yaml +++ b/pkg/resourcecreator/testdata/gcp_buckets.yaml @@ -138,6 +138,8 @@ tests: containers: - image: navikt/myapplication:1.2.3 env: + - name: GOOGLE_CLOUD_PROJECT + value: team-project-id - name: GCP_TEAM_PROJECT_ID value: team-project-id dnsPolicy: ClusterFirst diff --git a/pkg/resourcecreator/testdata/gcp_buckets_publicaccessprevention.yaml b/pkg/resourcecreator/testdata/gcp_buckets_publicaccessprevention.yaml index 3ac243e99..4680b1169 100644 --- a/pkg/resourcecreator/testdata/gcp_buckets_publicaccessprevention.yaml +++ b/pkg/resourcecreator/testdata/gcp_buckets_publicaccessprevention.yaml @@ -128,6 +128,8 @@ tests: containers: - image: navikt/myapplication:1.2.3 env: + - name: GOOGLE_CLOUD_PROJECT + value: team-project-id - name: GCP_TEAM_PROJECT_ID value: team-project-id dnsPolicy: ClusterFirst diff --git a/pkg/resourcecreator/testdata/gcp_buckets_uniformlevelaccess.yaml b/pkg/resourcecreator/testdata/gcp_buckets_uniformlevelaccess.yaml index 3179178b5..23b255bc3 100644 --- a/pkg/resourcecreator/testdata/gcp_buckets_uniformlevelaccess.yaml +++ b/pkg/resourcecreator/testdata/gcp_buckets_uniformlevelaccess.yaml @@ -167,6 +167,8 @@ tests: containers: - image: navikt/myapplication:1.2.3 env: + - name: GOOGLE_CLOUD_PROJECT + value: team-project-id - name: GCP_TEAM_PROJECT_ID value: team-project-id dnsPolicy: ClusterFirst diff --git a/pkg/resourcecreator/testdata/gcp_buckets_with_lifecycle_and_retention.yaml b/pkg/resourcecreator/testdata/gcp_buckets_with_lifecycle_and_retention.yaml index d368d6a4c..756a854b9 100644 --- a/pkg/resourcecreator/testdata/gcp_buckets_with_lifecycle_and_retention.yaml +++ b/pkg/resourcecreator/testdata/gcp_buckets_with_lifecycle_and_retention.yaml @@ -151,6 +151,8 @@ tests: containers: - image: navikt/myapplication:1.2.3 env: + - name: GOOGLE_CLOUD_PROJECT + value: team-project-id - name: GCP_TEAM_PROJECT_ID value: team-project-id dnsPolicy: ClusterFirst diff --git a/pkg/resourcecreator/testdata/gcp_database.yaml b/pkg/resourcecreator/testdata/gcp_database.yaml index 97d7a72b8..dfacf82e5 100644 --- a/pkg/resourcecreator/testdata/gcp_database.yaml +++ b/pkg/resourcecreator/testdata/gcp_database.yaml @@ -224,6 +224,8 @@ tests: - secretRef: name: google-sql-myapplication env: + - name: GOOGLE_CLOUD_PROJECT + value: team-project-id - name: GCP_TEAM_PROJECT_ID value: team-project-id - name: cloudsql-proxy diff --git a/pkg/resourcecreator/testdata/gcp_database_with_insights.yaml b/pkg/resourcecreator/testdata/gcp_database_with_insights.yaml index 68f0a6749..57051ddbf 100644 --- a/pkg/resourcecreator/testdata/gcp_database_with_insights.yaml +++ b/pkg/resourcecreator/testdata/gcp_database_with_insights.yaml @@ -223,6 +223,8 @@ tests: - secretRef: name: google-sql-myapplication env: + - name: GOOGLE_CLOUD_PROJECT + value: team-project-id - name: GCP_TEAM_PROJECT_ID value: team-project-id - name: cloudsql-proxy diff --git a/pkg/resourcecreator/testdata/naisjob/cronjob_gcp_bigquery_cascading_delete.yaml b/pkg/resourcecreator/testdata/naisjob/cronjob_gcp_bigquery_cascading_delete.yaml index 19ae6e5a4..06b480fff 100644 --- a/pkg/resourcecreator/testdata/naisjob/cronjob_gcp_bigquery_cascading_delete.yaml +++ b/pkg/resourcecreator/testdata/naisjob/cronjob_gcp_bigquery_cascading_delete.yaml @@ -93,6 +93,8 @@ tests: containers: - image: navikt/mynaisjob:1.2.3 env: + - name: GOOGLE_CLOUD_PROJECT + value: team-project-id - name: GCP_TEAM_PROJECT_ID value: team-project-id dnsPolicy: ClusterFirst diff --git a/pkg/resourcecreator/testdata/naisjob/cronjob_gcp_buckets.yaml b/pkg/resourcecreator/testdata/naisjob/cronjob_gcp_buckets.yaml index 08087ec5b..48d2892d1 100644 --- a/pkg/resourcecreator/testdata/naisjob/cronjob_gcp_buckets.yaml +++ b/pkg/resourcecreator/testdata/naisjob/cronjob_gcp_buckets.yaml @@ -143,6 +143,8 @@ tests: containers: - image: navikt/mynaisjob:1.2.3 env: + - name: GOOGLE_CLOUD_PROJECT + value: team-project-id - name: GCP_TEAM_PROJECT_ID value: team-project-id dnsPolicy: ClusterFirst diff --git a/pkg/resourcecreator/testdata/naisjob/cronjob_gcp_database.yaml b/pkg/resourcecreator/testdata/naisjob/cronjob_gcp_database.yaml index 5c5db317b..c054987c3 100644 --- a/pkg/resourcecreator/testdata/naisjob/cronjob_gcp_database.yaml +++ b/pkg/resourcecreator/testdata/naisjob/cronjob_gcp_database.yaml @@ -216,6 +216,8 @@ tests: - secretRef: name: google-sql-mynaisjob env: + - name: GOOGLE_CLOUD_PROJECT + value: team-project-id - name: GCP_TEAM_PROJECT_ID value: team-project-id - name: cloudsql-proxy