From f70fe45c72016789d56372319c5a5eb17b0c25c7 Mon Sep 17 00:00:00 2001 From: Hrishikesh Barman Date: Sun, 19 Jul 2020 06:17:56 +0530 Subject: [PATCH 1/6] Refactor infra and GKE provider * Made call to gke.NewGKEClient lazy * Add GKE.checkDeploymentVarsAndFiles to validate inputs * Remov GKE.setProjectID Signed-off-by: Hrishikesh Barman --- infra/infra.go | 11 +++++---- pkg/provider/gke/gke.go | 51 +++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/infra/infra.go b/infra/infra.go index 469e07665..d02342ef6 100644 --- a/infra/infra.go +++ b/infra/infra.go @@ -31,14 +31,12 @@ func main() { app.HelpFlag.Short('h') g := gke.New() - k8sGKE := app.Command("gke", `Google container engine provider - https://cloud.google.com/kubernetes-engine/`). - Action(g.NewGKEClient) + k8sGKE := app.Command("gke", `Google container engine provider - https://cloud.google.com/kubernetes-engine/`) k8sGKE.Flag("auth", "json authentication for the project. Accepts a filepath or an env variable that inlcudes tha json data. If not set the tool will use the GOOGLE_APPLICATION_CREDENTIALS env variable (export GOOGLE_APPLICATION_CREDENTIALS=service-account.json). https://cloud.google.com/iam/docs/creating-managing-service-account-keys."). PlaceHolder("service-account.json"). Short('a'). StringVar(&g.Auth) k8sGKE.Flag("file", "yaml file or folder that describes the parameters for the object that will be deployed."). - Required(). Short('f'). ExistingFilesOrDirsVar(&g.DeploymentFiles) k8sGKE.Flag("vars", "When provided it will substitute the token holders in the yaml file. Follows the standard golang template formating - {{ .hashStable }}."). @@ -47,6 +45,7 @@ func main() { // Cluster operations. k8sGKECluster := k8sGKE.Command("cluster", "manage GKE clusters"). + Action(g.NewGKEClient). Action(g.GKEDeploymentsParse) k8sGKECluster.Command("create", "gke cluster create -a service-account.json -f FileOrFolder"). Action(g.ClusterCreate) @@ -55,6 +54,7 @@ func main() { // Cluster node-pool operations k8sGKENodePool := k8sGKE.Command("nodepool", "manage GKE clusters nodepools"). + Action(g.NewGKEClient). Action(g.GKEDeploymentsParse) k8sGKENodePool.Command("create", "gke nodepool create -a service-account.json -f FileOrFolder"). Action(g.NodePoolCreate) @@ -67,8 +67,9 @@ func main() { // K8s resource operations. k8sGKEResource := k8sGKE.Command("resource", `Apply and delete different k8s resources - deployments, services, config maps etc.Required variables -v PROJECT_ID, -v ZONE: -west1-b -v CLUSTER_NAME`). - Action(g.NewK8sProvider). - Action(g.K8SDeploymentsParse) + Action(g.NewGKEClient). + Action(g.K8SDeploymentsParse). + Action(g.NewK8sProvider) k8sGKEResource.Command("apply", "gke resource apply -a service-account.json -f manifestsFileOrFolder -v PROJECT_ID:test -v ZONE:europe-west1-b -v CLUSTER_NAME:test -v hashStable:COMMIT1 -v hashTesting:COMMIT2"). Action(g.ResourceApply) k8sGKEResource.Command("delete", "gke resource delete -a service-account.json -f manifestsFileOrFolder -v PROJECT_ID:test -v ZONE:europe-west1-b -v CLUSTER_NAME:test -v hashStable:COMMIT1 -v hashTesting:COMMIT2"). diff --git a/pkg/provider/gke/gke.go b/pkg/provider/gke/gke.go index ac8be84c5..d9b0971af 100644 --- a/pkg/provider/gke/gke.go +++ b/pkg/provider/gke/gke.go @@ -16,7 +16,6 @@ package gke import ( "context" "encoding/base64" - "encoding/json" "fmt" "io/ioutil" "log" @@ -114,6 +113,7 @@ func (c *GKE) NewGKEClient(*kingpin.ParseContext) error { // Set the auth env variable needed to the k8s client. // The client looks for this special variable name and it is the only way to set the auth for now. // TODO: Remove when the client supports an auth config option in NewDefaultClientConfig. + // https://github.com/kubernetes/kubernetes/pull/80303 os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", saFile.Name()) opts := option.WithCredentialsJSON([]byte(c.Auth)) @@ -130,7 +130,9 @@ func (c *GKE) NewGKEClient(*kingpin.ParseContext) error { // GKEDeploymentsParse parses the cluster/nodepool deployment files and saves the result as bytes grouped by the filename. // Any variables passed to the cli will be replaced in the resources files following the golang text template format. func (c *GKE) GKEDeploymentsParse(*kingpin.ParseContext) error { - c.setProjectID() + if err := c.checkDeploymentVarsAndFiles(); err != nil { + return err + } deploymentResource, err := provider.DeploymentsParse(c.DeploymentFiles, c.DeploymentVars) if err != nil { @@ -144,7 +146,9 @@ func (c *GKE) GKEDeploymentsParse(*kingpin.ParseContext) error { // K8SDeploymentsParse parses the k8s objects deployment files and saves the result as k8s objects grouped by the filename. // Any variables passed to the cli will be replaced in the resources files following the golang text template format. func (c *GKE) K8SDeploymentsParse(*kingpin.ParseContext) error { - c.setProjectID() + if err := c.checkDeploymentVarsAndFiles(); err != nil { + return err + } deploymentResource, err := provider.DeploymentsParse(c.DeploymentFiles, c.DeploymentVars) if err != nil { @@ -178,19 +182,19 @@ func (c *GKE) K8SDeploymentsParse(*kingpin.ParseContext) error { return nil } -// setProjectID either from the cli arg or read it from the auth data. -func (c *GKE) setProjectID() { - if v, ok := c.DeploymentVars["PROJECT_ID"]; !ok || v == "" { - d := make(map[string]interface{}) - if err := json.Unmarshal([]byte(c.Auth), &d); err != nil { - log.Fatalf("Couldn't parse auth file: %v", err) +// checkDeploymentVarsAndFiles checks whether the requied deployment vars are passed. +func (c *GKE) checkDeploymentVarsAndFiles() error { + reqDepVars := []string{"PROJECT_ID", "ZONE", "CLUSTER_NAME"} + for _, k := range reqDepVars { + v := c.DeploymentVars[k] + if v == "" { + return fmt.Errorf("missing required %v variable", k) } - v, ok := d["project_id"].(string) - if !ok { - log.Fatal("Couldn't get project id from the auth file") - } - c.DeploymentVars["PROJECT_ID"] = v } + if len(c.DeploymentFiles) == 0 { + return fmt.Errorf("missing deployment file(s)") + } + return nil } // ClusterCreate create a new cluster or applies changes to an existing cluster. @@ -501,24 +505,11 @@ func (c *GKE) AllNodepoolsDeleted(*kingpin.ParseContext) error { // NewK8sProvider sets the k8s provider used for deploying k8s manifests. func (c *GKE) NewK8sProvider(*kingpin.ParseContext) error { - projectID, ok := c.DeploymentVars["PROJECT_ID"] - if !ok { - return fmt.Errorf("missing required PROJECT_ID variable") - } - zone, ok := c.DeploymentVars["ZONE"] - if !ok { - return fmt.Errorf("missing required ZONE variable") - } - clusterID, ok := c.DeploymentVars["CLUSTER_NAME"] - if !ok { - return fmt.Errorf("missing required CLUSTER_NAME variable") - } - // Get the authentication certificate for the cluster using the GKE client. req := &containerpb.GetClusterRequest{ - ProjectId: projectID, - Zone: zone, - ClusterId: clusterID, + ProjectId: c.DeploymentVars["PROJECT_ID"], + Zone: c.DeploymentVars["ZONE"], + ClusterId: c.DeploymentVars["CLUSTER_NAME"], } rep, err := c.clientGKE.GetCluster(c.ctx, req) if err != nil { From 4cc5b4e8ce1638e79c444ea190da1c26ab575a9a Mon Sep 17 00:00:00 2001 From: Hrishikesh Barman Date: Sun, 19 Jul 2020 08:01:05 +0530 Subject: [PATCH 2/6] Add provider.DeploymentResource * Add support for default DeploymentVars and DeploymentFiles * Update gke.New * Update infra to use provider.DeploymentResource Signed-off-by: Hrishikesh Barman --- infra/infra.go | 17 ++++++++++------- pkg/provider/gke/gke.go | 5 ++--- pkg/provider/provider.go | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/infra/infra.go b/infra/infra.go index d02342ef6..ec15770d0 100644 --- a/infra/infra.go +++ b/infra/infra.go @@ -20,6 +20,7 @@ import ( "path/filepath" "github.com/pkg/errors" + "github.com/prometheus/test-infra/pkg/provider" "github.com/prometheus/test-infra/pkg/provider/gke" "gopkg.in/alecthomas/kingpin.v2" ) @@ -27,21 +28,23 @@ import ( func main() { log.SetFlags(log.Ltime | log.Lshortfile) + dr := provider.DefaultDeploymentResource() + app := kingpin.New(filepath.Base(os.Args[0]), "The prometheus/test-infra deployment tool") app.HelpFlag.Short('h') + app.Flag("file", "yaml file or folder that describes the parameters for the object that will be deployed."). + Short('f'). + ExistingFilesOrDirsVar(&dr.DeploymentFiles) + app.Flag("vars", "When provided it will substitute the token holders in the yaml file. Follows the standard golang template formating - {{ .hashStable }}."). + Short('v'). + StringMapVar(&dr.DeploymentVars) - g := gke.New() + g := gke.New(dr) k8sGKE := app.Command("gke", `Google container engine provider - https://cloud.google.com/kubernetes-engine/`) k8sGKE.Flag("auth", "json authentication for the project. Accepts a filepath or an env variable that inlcudes tha json data. If not set the tool will use the GOOGLE_APPLICATION_CREDENTIALS env variable (export GOOGLE_APPLICATION_CREDENTIALS=service-account.json). https://cloud.google.com/iam/docs/creating-managing-service-account-keys."). PlaceHolder("service-account.json"). Short('a'). StringVar(&g.Auth) - k8sGKE.Flag("file", "yaml file or folder that describes the parameters for the object that will be deployed."). - Short('f'). - ExistingFilesOrDirsVar(&g.DeploymentFiles) - k8sGKE.Flag("vars", "When provided it will substitute the token holders in the yaml file. Follows the standard golang template formating - {{ .hashStable }}."). - Short('v'). - StringMapVar(&g.DeploymentVars) // Cluster operations. k8sGKECluster := k8sGKE.Command("cluster", "manage GKE clusters"). diff --git a/pkg/provider/gke/gke.go b/pkg/provider/gke/gke.go index d9b0971af..a660c0501 100644 --- a/pkg/provider/gke/gke.go +++ b/pkg/provider/gke/gke.go @@ -42,9 +42,9 @@ import ( ) // New is the GKE constructor. -func New() *GKE { +func New(dr provider.DeploymentResource) *GKE { return &GKE{ - DeploymentVars: make(map[string]string), + DeploymentVars: dr.DeploymentVars, } } @@ -64,7 +64,6 @@ type GKE struct { // DeploymentFiles files provided from the cli. DeploymentFiles []string // Variables to substitute in the DeploymentFiles. - // These are also used when the command requires some variables that are not provided by the deployment file. DeploymentVars map[string]string // Content bytes after parsing the template variables, grouped by filename. gkeResources []Resource diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go index be3e10d50..d7237c228 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -31,6 +31,22 @@ const ( globalRetryTime = 10 * time.Second ) +// DeploymentResource holds list of variables and corresponding files. +type DeploymentResource struct { + // DeploymentFiles files provided from the cli. + DeploymentFiles []string + // Variables to substitute in the DeploymentFiles. + DeploymentVars map[string]string +} + +// DefaultDeploymentResource returns DeploymentResource with default values. +func DefaultDeploymentResource() DeploymentResource { + return DeploymentResource{ + DeploymentFiles: []string{}, + DeploymentVars: map[string]string{}, + } +} + // Resource holds the file content after parsing the template variables. type Resource struct { FileName string From 2532f39278f51564094d5a46a076767b506a05da Mon Sep 17 00:00:00 2001 From: Hrishikesh Barman Date: Sun, 19 Jul 2020 11:16:59 +0530 Subject: [PATCH 3/6] Improve DeploymentResource by separating Flag and Default DeploymentVars * Add test for provider.MergeDeploymentVars * Change provider.DefaultDeploymentResource to NewDeploymentResource * Add provider.MergeDeploymentVars * Separate FlagDeploymentVars and DefaultDeploymentVars Signed-off-by: Hrishikesh Barman --- infra/infra.go | 4 +-- pkg/provider/gke/gke.go | 8 ++++- pkg/provider/provider.go | 26 +++++++++++---- pkg/provider/provider_test.go | 59 +++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 pkg/provider/provider_test.go diff --git a/infra/infra.go b/infra/infra.go index ec15770d0..173a6a033 100644 --- a/infra/infra.go +++ b/infra/infra.go @@ -28,7 +28,7 @@ import ( func main() { log.SetFlags(log.Ltime | log.Lshortfile) - dr := provider.DefaultDeploymentResource() + dr := provider.NewDeploymentResource() app := kingpin.New(filepath.Base(os.Args[0]), "The prometheus/test-infra deployment tool") app.HelpFlag.Short('h') @@ -37,7 +37,7 @@ func main() { ExistingFilesOrDirsVar(&dr.DeploymentFiles) app.Flag("vars", "When provided it will substitute the token holders in the yaml file. Follows the standard golang template formating - {{ .hashStable }}."). Short('v'). - StringMapVar(&dr.DeploymentVars) + StringMapVar(&dr.FlagDeploymentVars) g := gke.New(dr) k8sGKE := app.Command("gke", `Google container engine provider - https://cloud.google.com/kubernetes-engine/`) diff --git a/pkg/provider/gke/gke.go b/pkg/provider/gke/gke.go index a660c0501..30739bbe8 100644 --- a/pkg/provider/gke/gke.go +++ b/pkg/provider/gke/gke.go @@ -43,8 +43,14 @@ import ( // New is the GKE constructor. func New(dr provider.DeploymentResource) *GKE { + // The next one in order will override the previous. + res := provider.MergeDeploymentVars( + dr.DefaultDeploymentVars, + dr.FlagDeploymentVars, + ) return &GKE{ - DeploymentVars: dr.DeploymentVars, + DeploymentVars: res, + DeploymentFiles: dr.DeploymentFiles, } } diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go index d7237c228..2b81c1eef 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -35,15 +35,18 @@ const ( type DeploymentResource struct { // DeploymentFiles files provided from the cli. DeploymentFiles []string - // Variables to substitute in the DeploymentFiles. - DeploymentVars map[string]string + // DeploymentVars provided from the cli. + FlagDeploymentVars map[string]string + // Default DeploymentVars. + DefaultDeploymentVars map[string]string } -// DefaultDeploymentResource returns DeploymentResource with default values. -func DefaultDeploymentResource() DeploymentResource { +// NewDeploymentResource returns DeploymentResource with default values. +func NewDeploymentResource() DeploymentResource { return DeploymentResource{ - DeploymentFiles: []string{}, - DeploymentVars: map[string]string{}, + DeploymentFiles: []string{}, + FlagDeploymentVars: map[string]string{}, + DefaultDeploymentVars: map[string]string{}, } } @@ -122,3 +125,14 @@ func DeploymentsParse(deploymentFiles []string, deploymentVars map[string]string } return deploymentObjects, nil } + +// MergeDeploymentVars merges multiple maps based on the order. +func MergeDeploymentVars(ms ...map[string]string) map[string]string { + res := map[string]string{} + for _, m := range ms { + for k, v := range m { + res[k] = v + } + } + return res +} diff --git a/pkg/provider/provider_test.go b/pkg/provider/provider_test.go new file mode 100644 index 000000000..fc27eca30 --- /dev/null +++ b/pkg/provider/provider_test.go @@ -0,0 +1,59 @@ +// Copyright 2020 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package provider + +import ( + "reflect" + "testing" +) + +func TestMergeDeploymentVars(t *testing.T) { + dv1 := map[string]string{ + "foo": "apple", + "bar": "orange", + } + dv2 := map[string]string{ + "foo": "mango", + "baz": "banana", + "buzz": "jackfruit", + } + dv3 := map[string]string{ + "foo": "grape", + "baz": "blueberry", + } + testCases := []struct { + vars []map[string]string + merged map[string]string + }{ + { + vars: []map[string]string{dv1, dv2, dv3}, + merged: map[string]string{"bar": "orange", "baz": "blueberry", "buzz": "jackfruit", "foo": "grape"}, + }, + { + vars: []map[string]string{dv3, dv2, dv1}, + merged: map[string]string{"bar": "orange", "baz": "banana", "buzz": "jackfruit", "foo": "apple"}, + }, + { + vars: []map[string]string{dv3, dv1, dv2}, + merged: map[string]string{"bar": "orange", "baz": "banana", "buzz": "jackfruit", "foo": "mango"}, + }, + } + + for _, tc := range testCases { + r := MergeDeploymentVars(tc.vars...) + if eq := reflect.DeepEqual(tc.merged, r); !eq { + t.Errorf("\nexpect %#v\ngot %#v", tc.merged, r) + } + } +} From e320e0847fe988e72dccbab9cb02d347733d6fdf Mon Sep 17 00:00:00 2001 From: Hrishikesh Barman Date: Sun, 19 Jul 2020 16:06:14 +0530 Subject: [PATCH 4/6] Add SetupGKEDeploymentResources Signed-off-by: Hrishikesh Barman --- infra/infra.go | 3 ++- pkg/provider/gke/gke.go | 27 +++++++++++++++++---------- pkg/provider/provider.go | 4 ++-- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/infra/infra.go b/infra/infra.go index 173a6a033..9e6befe50 100644 --- a/infra/infra.go +++ b/infra/infra.go @@ -40,7 +40,8 @@ func main() { StringMapVar(&dr.FlagDeploymentVars) g := gke.New(dr) - k8sGKE := app.Command("gke", `Google container engine provider - https://cloud.google.com/kubernetes-engine/`) + k8sGKE := app.Command("gke", `Google container engine provider - https://cloud.google.com/kubernetes-engine/`). + Action(g.SetupGKEDeploymentResources) k8sGKE.Flag("auth", "json authentication for the project. Accepts a filepath or an env variable that inlcudes tha json data. If not set the tool will use the GOOGLE_APPLICATION_CREDENTIALS env variable (export GOOGLE_APPLICATION_CREDENTIALS=service-account.json). https://cloud.google.com/iam/docs/creating-managing-service-account-keys."). PlaceHolder("service-account.json"). Short('a'). diff --git a/pkg/provider/gke/gke.go b/pkg/provider/gke/gke.go index 30739bbe8..936e02096 100644 --- a/pkg/provider/gke/gke.go +++ b/pkg/provider/gke/gke.go @@ -42,15 +42,9 @@ import ( ) // New is the GKE constructor. -func New(dr provider.DeploymentResource) *GKE { - // The next one in order will override the previous. - res := provider.MergeDeploymentVars( - dr.DefaultDeploymentVars, - dr.FlagDeploymentVars, - ) +func New(dr *provider.DeploymentResource) *GKE { return &GKE{ - DeploymentVars: res, - DeploymentFiles: dr.DeploymentFiles, + DeploymentResource: dr, } } @@ -67,10 +61,12 @@ type GKE struct { clientGKE *gke.ClusterManagerClient // The k8s provider used when we work with the manifest files. k8sProvider *k8sProvider.K8s - // DeploymentFiles files provided from the cli. + // Final DeploymentFiles files. DeploymentFiles []string - // Variables to substitute in the DeploymentFiles. + // Final DeploymentVars. DeploymentVars map[string]string + // DeployResource to construct DeploymentVars and DeploymentFiles + DeploymentResource *provider.DeploymentResource // Content bytes after parsing the template variables, grouped by filename. gkeResources []Resource // K8s resource.runtime objects after parsing the template variables, grouped by filename. @@ -129,6 +125,17 @@ func (c *GKE) NewGKEClient(*kingpin.ParseContext) error { } c.clientGKE = cl c.ctx = context.Background() + + return nil +} + +// SetupGKEDeploymentResources Sets up DeploymentVars and DeploymentFiles +func (c *GKE) SetupGKEDeploymentResources(*kingpin.ParseContext) error { + c.DeploymentFiles = c.DeploymentResource.DeploymentFiles + c.DeploymentVars = provider.MergeDeploymentVars( + c.DeploymentResource.DefaultDeploymentVars, + c.DeploymentResource.FlagDeploymentVars, + ) return nil } diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go index 2b81c1eef..a5843c89a 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -42,8 +42,8 @@ type DeploymentResource struct { } // NewDeploymentResource returns DeploymentResource with default values. -func NewDeploymentResource() DeploymentResource { - return DeploymentResource{ +func NewDeploymentResource() *DeploymentResource { + return &DeploymentResource{ DeploymentFiles: []string{}, FlagDeploymentVars: map[string]string{}, DefaultDeploymentVars: map[string]string{}, From 95996526f119a1d85c0d4ba73cfa09680c5d9687 Mon Sep 17 00:00:00 2001 From: Hrishikesh Barman Date: Sun, 19 Jul 2020 16:54:25 +0530 Subject: [PATCH 5/6] Update README Signed-off-by: Hrishikesh Barman --- infra/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/infra/README.md b/infra/README.md index c9014f11d..9e1f8efab 100644 --- a/infra/README.md +++ b/infra/README.md @@ -17,7 +17,13 @@ usage: infra [] [ ...] The prometheus/test-infra deployment tool Flags: - -h, --help Show context-sensitive help (also try --help-long and --help-man). + -h, --help Show context-sensitive help (also try --help-long and + --help-man). + -f, --file=FILE ... yaml file or folder that describes the parameters for the + object that will be deployed. + -v, --vars=VARS ... When provided it will substitute the token holders in the + yaml file. Follows the standard golang template formating + - {{ .hashStable }}. Commands: help [...] From 0f7220ba3c65743d789d00973452bbe51cd03edf Mon Sep 17 00:00:00 2001 From: Hrishikesh Barman Date: Tue, 21 Jul 2020 09:28:42 +0530 Subject: [PATCH 6/6] Update checkDeploymentVarsAndFiles and SetupDeploymentResources * Update SetupGKEDeploymentResources to SetupDeploymentResources * Minor refactorings to checkDeploymentVarsAndFiles Signed-off-by: Hrishikesh Barman --- infra/infra.go | 2 +- pkg/provider/gke/gke.go | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/infra/infra.go b/infra/infra.go index 9e6befe50..ac65a3033 100644 --- a/infra/infra.go +++ b/infra/infra.go @@ -41,7 +41,7 @@ func main() { g := gke.New(dr) k8sGKE := app.Command("gke", `Google container engine provider - https://cloud.google.com/kubernetes-engine/`). - Action(g.SetupGKEDeploymentResources) + Action(g.SetupDeploymentResources) k8sGKE.Flag("auth", "json authentication for the project. Accepts a filepath or an env variable that inlcudes tha json data. If not set the tool will use the GOOGLE_APPLICATION_CREDENTIALS env variable (export GOOGLE_APPLICATION_CREDENTIALS=service-account.json). https://cloud.google.com/iam/docs/creating-managing-service-account-keys."). PlaceHolder("service-account.json"). Short('a'). diff --git a/pkg/provider/gke/gke.go b/pkg/provider/gke/gke.go index 936e02096..887a1e9c3 100644 --- a/pkg/provider/gke/gke.go +++ b/pkg/provider/gke/gke.go @@ -129,8 +129,8 @@ func (c *GKE) NewGKEClient(*kingpin.ParseContext) error { return nil } -// SetupGKEDeploymentResources Sets up DeploymentVars and DeploymentFiles -func (c *GKE) SetupGKEDeploymentResources(*kingpin.ParseContext) error { +// SetupDeploymentResources Sets up DeploymentVars and DeploymentFiles +func (c *GKE) SetupDeploymentResources(*kingpin.ParseContext) error { c.DeploymentFiles = c.DeploymentResource.DeploymentFiles c.DeploymentVars = provider.MergeDeploymentVars( c.DeploymentResource.DefaultDeploymentVars, @@ -198,8 +198,7 @@ func (c *GKE) K8SDeploymentsParse(*kingpin.ParseContext) error { func (c *GKE) checkDeploymentVarsAndFiles() error { reqDepVars := []string{"PROJECT_ID", "ZONE", "CLUSTER_NAME"} for _, k := range reqDepVars { - v := c.DeploymentVars[k] - if v == "" { + if v, ok := c.DeploymentVars[k]; !ok || v == "" { return fmt.Errorf("missing required %v variable", k) } }