Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: k9s to support GCP clusters #231

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading