From e402f11b413f9c81eda3d95a30dd55285e324fda Mon Sep 17 00:00:00 2001 From: Ilya Dmitrichenko Date: Wed, 10 Oct 2018 17:31:01 +0100 Subject: [PATCH] Tighten default region logic, fix regression --- cmd/eksctl/create.go | 5 ----- cmd/eksctl/delete.go | 4 ---- cmd/eksctl/get.go | 4 ---- cmd/eksctl/utils.go | 8 -------- pkg/eks/api.go | 23 ++++++++++++++--------- 5 files changed, 14 insertions(+), 30 deletions(-) diff --git a/cmd/eksctl/create.go b/cmd/eksctl/create.go index d36a69e927..6804572dd8 100644 --- a/cmd/eksctl/create.go +++ b/cmd/eksctl/create.go @@ -108,11 +108,6 @@ func createClusterCmd() *cobra.Command { func doCreateCluster(cfg *api.ClusterConfig, name string) error { ctl := eks.New(cfg) - if cfg.Region == "" { - logger.Debug("no region specified in flags or config, setting to %s", api.DefaultEKSRegion) - cfg.Region = api.DefaultEKSRegion - } - if cfg.Region != api.EKSRegionUSWest2 && cfg.Region != api.EKSRegionUSEast1 && cfg.Region != api.EKSRegionEUWest1 { return fmt.Errorf("%s is not supported only %s, %s and %s are supported", cfg.Region, api.EKSRegionUSWest2, api.EKSRegionUSEast1, api.EKSRegionEUWest1) } diff --git a/cmd/eksctl/delete.go b/cmd/eksctl/delete.go index 53df920368..16d142f37e 100644 --- a/cmd/eksctl/delete.go +++ b/cmd/eksctl/delete.go @@ -59,10 +59,6 @@ func deleteClusterCmd() *cobra.Command { func doDeleteCluster(cfg *api.ClusterConfig, name string) error { ctl := eks.New(cfg) - if cfg.Region == "" { - cfg.Region = api.DefaultEKSRegion - } - if err := ctl.CheckAuth(); err != nil { return err } diff --git a/cmd/eksctl/get.go b/cmd/eksctl/get.go index 9479aedba6..4699b6ea4e 100644 --- a/cmd/eksctl/get.go +++ b/cmd/eksctl/get.go @@ -66,10 +66,6 @@ func getClusterCmd() *cobra.Command { func doGetCluster(cfg *api.ClusterConfig, name string) error { ctl := eks.New(cfg) - if cfg.Region == "" { - cfg.Region = api.DefaultEKSRegion - } - if err := ctl.CheckAuth(); err != nil { return err } diff --git a/cmd/eksctl/utils.go b/cmd/eksctl/utils.go index ff7258778b..57daae90c1 100644 --- a/cmd/eksctl/utils.go +++ b/cmd/eksctl/utils.go @@ -124,10 +124,6 @@ func writeKubeconfigCmd() *cobra.Command { func doWriteKubeconfigCmd(cfg *api.ClusterConfig, name string) error { ctl := eks.New(cfg) - if cfg.Region == "" { - cfg.Region = api.DefaultEKSRegion - } - if err := ctl.CheckAuth(); err != nil { return err } @@ -208,10 +204,6 @@ func describeStacksCmd() *cobra.Command { func doDescribeStacksCmd(cfg *api.ClusterConfig, name string) error { ctl := eks.New(cfg) - if cfg.Region == "" { - cfg.Region = api.DefaultEKSRegion - } - if err := ctl.CheckAuth(); err != nil { return err } diff --git a/pkg/eks/api.go b/pkg/eks/api.go index 4f5296313e..7d8fbd3286 100644 --- a/pkg/eks/api.go +++ b/pkg/eks/api.go @@ -71,13 +71,6 @@ func New(clusterConfig *api.ClusterConfig) *ClusterProvider { // later re-use if overriding sessions due to custom URL s := newSession(clusterConfig, "", nil) - // If there was no region supplied and we have a region - // from the config files then update the cluster config - if clusterConfig.Region == "" && *s.Config.Region != "" { - logger.Debug("using region %s from AWS shared configuraion or environment variables", *s.Config.Region) - clusterConfig.Region = *s.Config.Region - } - provider := &ProviderServices{ cfn: cloudformation.New(s), eks: awseks.New(s), @@ -207,9 +200,21 @@ func newSession(clusterConfig *api.ClusterConfig, endpoint string, credentials * // don't want yet // https://github.com/kubernetes/kops/blob/master/upup/pkg/fi/cloudup/awsup/aws_cloud.go#L179 config := aws.NewConfig() - if clusterConfig.Region != "" { - config = config.WithRegion(clusterConfig.Region) + + if clusterConfig.Region == "" { + if config.Region != nil { + // If there was no region supplied and we have a region + // from the config files then update the cluster config + logger.Debug("using region %s from AWS shared configuraion or environment variables", *config.Region) + clusterConfig.Region = *config.Region + } else { + // Otherwise set our own default + logger.Debug("no region specified in flags or config, setting to %s", api.DefaultEKSRegion) + clusterConfig.Region = api.DefaultEKSRegion + } } + + config = config.WithRegion(clusterConfig.Region) config = config.WithCredentialsChainVerboseErrors(true) if logger.Level >= api.AWSDebugLevel { config = config.WithLogLevel(aws.LogDebug |