Skip to content

Commit

Permalink
Merge pull request #300 from weaveworks/region-validation
Browse files Browse the repository at this point in the history
Improve region validation, only print log message in create cluster command
  • Loading branch information
errordeveloper authored Nov 4, 2018
2 parents adc1908 + f1a69a9 commit 186610b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
6 changes: 4 additions & 2 deletions pkg/ctl/create/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package create
import (
"fmt"
"os"
"strings"

"github.com/kubicorn/kubicorn/pkg/logger"
"github.com/pkg/errors"
Expand Down Expand Up @@ -101,9 +102,10 @@ func createClusterCmd() *cobra.Command {
func doCreateCluster(cfg *api.ClusterConfig, ng *api.NodeGroup, name string) error {
ctl := eks.New(cfg)

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)
if !cfg.IsSupportedRegion() {
return fmt.Errorf("--region=%s is not supported - use one of: %s", cfg.Region, strings.Join(api.SupportedRegions(), ", "))
}
logger.Info("using region %s", cfg.Region)

if err := ctl.CheckAuth(); err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion pkg/eks/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ func newSession(clusterConfig *api.ClusterConfig, endpoint string, credentials *
}
}

logger.Info("using region %s", clusterConfig.Region)
return s
}

Expand Down
20 changes: 16 additions & 4 deletions pkg/eks/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ const (
)

// SupportedRegions are the regions where EKS is available
var SupportedRegions = []string{
EKSRegionUSWest2,
EKSRegionUSEast1,
EKSRegionEUWest1,
func SupportedRegions() []string {
return []string{
EKSRegionUSWest2,
EKSRegionUSEast1,
EKSRegionEUWest1,
}
}

// DefaultWaitTimeout defines the default wait timeout
Expand Down Expand Up @@ -85,6 +87,16 @@ func NewClusterConfig() *ClusterConfig {
return cfg
}

// IsSupportedRegion check if given region is supported
func (c *ClusterConfig) IsSupportedRegion() bool {
for _, supportedRegion := range SupportedRegions() {
if c.Region == supportedRegion {
return true
}
}
return false
}

// NewNodeGroup crears new nodegroup inside cluster config,
// it returns pointer to the nodegroup for convenience
func (c *ClusterConfig) NewNodeGroup() *NodeGroup {
Expand Down

0 comments on commit 186610b

Please sign in to comment.