Skip to content

Commit

Permalink
chore: k9s to support GCP clusters
Browse files Browse the repository at this point in the history
Ticket: ENG-1655
  • Loading branch information
benjaminch committed Dec 25, 2023
1 parent 6eb3515 commit c9c7f6b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/admin_k9s.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ func launchK9s(args []string) {

for _, variable := range vars {
os.Setenv(variable.Key, variable.Value)

// Generate temporary file + ENV for GCP auth
// https://serverfault.com/questions/848580/how-to-use-google-application-credentials-with-gcloud-on-a-server
if variable.Key == "GOOGLE_CREDENTIALS" {
googleCredentialsFile, err := os.CreateTemp("", "sample")
if err != nil {
log.Error("Can't create google credentials file : " + err.Error())
}
defer os.Remove(googleCredentialsFile.Name())

_, err = googleCredentialsFile.WriteString(variable.Value)
if err != nil {
log.Error("Can't create google credentials file : " + err.Error())
}

os.Setenv("CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE", googleCredentialsFile.Name())
}
}
utils.GenerateExportEnvVarsScript(vars, args[0])

Expand Down
8 changes: 8 additions & 0 deletions pkg/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pkg

import (
b64 "encoding/base64"
"encoding/json"
"os"

"github.com/hashicorp/vault/api"
Expand Down Expand Up @@ -52,6 +53,13 @@ func GetVarsByClusterId(clusterID string) []utils.Var {
vaultVars = append(vaultVars, utils.Var{Key: "AWS_DEFAULT_REGION", Value: value.(string)})
case "AWS_SECRET_ACCESS_KEY", "aws_secret_access_key":
vaultVars = append(vaultVars, utils.Var{Key: "AWS_SECRET_ACCESS_KEY", Value: value.(string)})
case "GOOGLE_CREDENTIALS", "google_credentials":
jsonStr, err := json.Marshal(value)
if err != nil {
log.Error("Can't convert to json GOOGLE_CREDENTIALS")
return []utils.Var{}
}
vaultVars = append(vaultVars, utils.Var{Key: "GOOGLE_CREDENTIALS", Value: string(jsonStr)})
case "kubeconfig_b64", "KUBECONFIG_b64":
decodedValue, encErr := b64.StdEncoding.DecodeString(value.(string))
if encErr != nil {
Expand Down

0 comments on commit c9c7f6b

Please sign in to comment.