diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 18bb66a..46c1e23 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -63,7 +63,7 @@ gcp-test-cluster: script: - gcloud auth activate-service-account $(cat $GKE_GCP_CREDENTIALS_JSON | jq -r .client_email) --key-file=$GKE_GCP_CREDENTIALS_JSON - gcloud container clusters get-credentials $GKE_GCP_TEST_CLUSTER_NAME --region=$GKE_GCP_DEFAULT_REGION --project=$(cat $GKE_GCP_CREDENTIALS_JSON | jq -r .project_id) - - helm --kubeconfig $KUBECONFIG_GCP_TEST_CLUSTER upgrade --install --wait -n qovery -f $PLECO_VALUES_GCP --create-namespace --set 'environmentVariables.GOOGLE_APPLICATION_CREDENTIALS_JSON=`$(echo GKE_GCP_CREDENTIALS_JSON)`' pleco-gcp charts/pleco + - helm --kubeconfig $KUBECONFIG_GCP_TEST_CLUSTER upgrade --install --wait -n qovery -f $PLECO_VALUES_GCP --create-namespace --set `"environmentVariables.GOOGLE_APPLICATION_CREDENTIALS_JSON=$(echo GKE_GCP_CREDENTIALS_JSON)"` pleco-gcp charts/pleco only: - tags - schedules diff --git a/README.md b/README.md index 72c37aa..400dc36 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ $ export DO_VOLUME_TIMEOUT= +$ export GOOGLE_APPLICATION_CREDENTIALS_JSON= ``` --- ## Basic command diff --git a/charts/pleco/Chart.yaml b/charts/pleco/Chart.yaml index fe79ac5..875bb35 100644 --- a/charts/pleco/Chart.yaml +++ b/charts/pleco/Chart.yaml @@ -3,6 +3,6 @@ name: pleco description: Automatically removes Cloud managed services and Kubernetes resources based on tags with TTL type: application home: https://github.com/Qovery/pleco -version: 0.14.11 -appVersion: 0.14.11 +version: 0.14.12 +appVersion: 0.14.12 icon: https://github.com/Qovery/pleco/raw/main/assets/pleco_logo.png diff --git a/charts/pleco/values.yaml b/charts/pleco/values.yaml index 5dddc98..6da2877 100644 --- a/charts/pleco/values.yaml +++ b/charts/pleco/values.yaml @@ -3,7 +3,7 @@ replicaCount: 1 image: repository: public.ecr.aws/r3m4q3r9/pleco pullPolicy: IfNotPresent - plecoImageTag: "0.14.11" + plecoImageTag: "0.14.12" cloudProvider: "" @@ -24,7 +24,7 @@ environmentVariables: # DO_SPACES_SECRET: "" # DO_VOLUME_TIMEOUT: "" # GCP - # GOOGLE_APPLICATION_CREDENTIALS_JSON: "" + # GOOGLE_APPLICATION_CREDENTIALS_JSON_BASE64: "" enabledFeatures: diff --git a/cmd/version.go b/cmd/version.go index 55b4aaa..b55d38a 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -20,5 +20,5 @@ func init() { } func GetCurrentVersion() string { - return "0.14.11" // ci-version-check + return "0.14.12" // ci-version-check } diff --git a/pkg/common/validate.go b/pkg/common/validate.go index 1e98171..73381a6 100644 --- a/pkg/common/validate.go +++ b/pkg/common/validate.go @@ -109,7 +109,7 @@ func checkDOEnvVars(cmd *cobra.Command) []string { func checkGCPEnvVars(cmd *cobra.Command) []string { var requiredEnvVars = []string{ - "GOOGLE_APPLICATION_CREDENTIALS_JSON", + "GOOGLE_APPLICATION_CREDENTIALS_JSON_BASE64", } if isUsed(cmd, "cluster") || isUsed(cmd, "object-storage") || diff --git a/pkg/gcp/run.go b/pkg/gcp/run.go index 5be8224..0b1db10 100644 --- a/pkg/gcp/run.go +++ b/pkg/gcp/run.go @@ -5,9 +5,11 @@ import ( compute "cloud.google.com/go/compute/apiv1" container "cloud.google.com/go/container/apiv1" "cloud.google.com/go/storage" + "encoding/base64" "github.com/sirupsen/logrus" "golang.org/x/net/context" iam "google.golang.org/api/iam/v1" + "os" "sync" "time" ) @@ -38,6 +40,20 @@ type GCPSessions struct { type funcDeleteExpired func(sessions GCPSessions, options GCPOptions) func RunPlecoGCP(regions []string, interval int64, wg *sync.WaitGroup, options GCPOptions) { + if os.Getenv("GOOGLE_APPLICATION_CREDENTIALS_JSON") == "" { + jsonB64EncodedCredentialsEnv := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS_JSON_BASE64") + if jsonB64EncodedCredentialsEnv != "" { + decodedCredentialsEnv, err := base64.StdEncoding.DecodeString(jsonB64EncodedCredentialsEnv) + if err != nil { + logrus.Errorf("GOOGLE_APPLICATION_CREDENTIALS_JSON_BASE64 cannot be base64 decoded: %s", err) + return + } + if os.Setenv("GOOGLE_APPLICATION_CREDENTIALS_JSON", string(decodedCredentialsEnv)) != nil { + logrus.Errorf("GOOGLE_APPLICATION_CREDENTIALS_JSON cannot be set: %s", err) + return + } + } + } for _, region := range regions { wg.Add(1) go runPlecoInRegion(region, interval, wg, options)