Skip to content

Commit

Permalink
Tighten default region logic, fix regression
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Oct 10, 2018
1 parent a7702b6 commit e402f11
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 30 deletions.
5 changes: 0 additions & 5 deletions cmd/eksctl/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 0 additions & 4 deletions cmd/eksctl/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 0 additions & 4 deletions cmd/eksctl/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 0 additions & 8 deletions cmd/eksctl/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
23 changes: 14 additions & 9 deletions pkg/eks/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 |
Expand Down

0 comments on commit e402f11

Please sign in to comment.