Skip to content

Commit

Permalink
chore: CI/CD GCP test cluster (16)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminch committed Feb 4, 2024
1 parent c4480d0 commit 4adf3c5
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 --set "environmentVariables.GOOGLE_APPLICATION_CREDENTIALS_JSON_BASE64=$(echo $(cat $GKE_GCP_CREDENTIALS_JSON | base64))" -n qovery -f $PLECO_VALUES_GCP --create-namespace pleco-gcp charts/pleco
- helm --kubeconfig $KUBECONFIG_GCP_TEST_CLUSTER upgrade --install --wait --set "mountedFiles[0].contentBase64=$(echo $(cat $GKE_GCP_CREDENTIALS_JSON | base64))" -n qovery -f $PLECO_VALUES_GCP --create-namespace pleco-gcp charts/pleco
only:
- tags
- schedules
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ $ export DO_VOLUME_TIMEOUT=<delay_before_detached_volume_deletion_in_hours_since

#### For GCP
```bash
$ export GOOGLE_APPLICATION_CREDENTIALS_JSON=<path_to_your_credentials_json_file>
$ export GOOGLE_APPLICATION_CREDENTIALS=<path_to_your_credentials_json_file>
```
---
## Basic command
Expand Down
13 changes: 13 additions & 0 deletions charts/pleco/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,19 @@ spec:
{{ end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
{{ range $mountedFile := .Values.mountedFiles -}}
- mountPath: "{{ $mountedFile.mountPath }}"
subPath: content
name: "pleco-{{ $mountedFile.name }}"
readOnly: true
{{ end }}
volumes:
{{ range $mountedFile := .Values.mountedFiles -}}
- name: "pleco-{{ $mountedFile.name }}"
secret:
secretName: "pleco-{{ $mountedFile.name }}"
{{ end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
11 changes: 11 additions & 0 deletions charts/pleco/templates/mounted_files_secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{ range $mountedFile := .Values.mountedFiles -}}
---
apiVersion: v1
kind: Secret
metadata:
name: "pleco-{{ $mountedFile.name }}"
type: Opaque
data:
content: |
{{ $mountedFile.contentBase64 }}
{{ end }}
6 changes: 6 additions & 0 deletions charts/pleco/values-gcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ cloudProvider: "gcp"

environmentVariables:
LOG_LEVEL: "debug"
GOOGLE_APPLICATION_CREDENTIALS: "/tmp/google/credentials.json"

mountedFiles:
- name: "google-credentials"
mountPath: "/tmp/google/credentials.json"
contentBase64: ""

enabledFeatures:
disableDryRun: true
Expand Down
5 changes: 5 additions & 0 deletions charts/pleco/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ image:

cloudProvider: ""

mountedFiles: []
# - name: "toto"
# mountPath: "/tmp"
# contentBase64: "content"

environmentVariables:
LOG_LEVEL: "info"
PLECO_IDENTIFIER: "tbd"
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func checkDOEnvVars(cmd *cobra.Command) []string {

func checkGCPEnvVars(cmd *cobra.Command) []string {
var requiredEnvVars = []string{
"GOOGLE_APPLICATION_CREDENTIALS_JSON_BASE64",
"GOOGLE_APPLICATION_CREDENTIALS",
}
if isUsed(cmd, "cluster") ||
isUsed(cmd, "object-storage") ||
Expand Down
16 changes: 0 additions & 16 deletions pkg/gcp/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ 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"
)
Expand Down Expand Up @@ -40,20 +38,6 @@ 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)
Expand Down

0 comments on commit 4adf3c5

Please sign in to comment.