Skip to content

Commit

Permalink
Handle optional keys in ctl.GetClusterVPC
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Jan 17, 2019
1 parent 8d05318 commit ed2e2fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pkg/ctl/utils/update_cluster_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/spf13/pflag"

api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha3"
"github.com/weaveworks/eksctl/pkg/cfn/builder"
"github.com/weaveworks/eksctl/pkg/ctl/cmdutils"
"github.com/weaveworks/eksctl/pkg/eks"
)
Expand Down Expand Up @@ -62,7 +63,7 @@ func doUpdateClusterStacksCmd(p *api.ProviderConfig, cfg *api.ClusterConfig, nam
return fmt.Errorf("--name must be set")
}

if err := ctl.GetClusterVPC(cfg); err != nil {
if err := ctl.GetClusterVPC(cfg, builder.CfnOutputClusterSharedNodeSecurityGroup); err != nil {
return errors.Wrapf(err, "getting VPC configuration for cluster %q", cfg.Metadata.Name)
}

Expand Down
15 changes: 11 additions & 4 deletions pkg/eks/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (c *ClusterProvider) GetCredentials(spec *api.ClusterConfig) error {
}

// GetClusterVPC retrieves the VPC configuration
func (c *ClusterProvider) GetClusterVPC(spec *api.ClusterConfig) error {
func (c *ClusterProvider) GetClusterVPC(spec *api.ClusterConfig, ignoreMissingKeys ...string) error {
cluster, err := c.NewStackManager(spec).DescribeClusterStack()
if err != nil {
return err
Expand All @@ -103,7 +103,14 @@ func (c *ClusterProvider) GetClusterVPC(spec *api.ClusterConfig) error {
}

requiredKeyErrFmt := "cluster stack has no output key %q"

isKeyRequired := func(k string) bool {
for _, key := range ignoreMissingKeys {
if key == k {
return false
}
}
return true
}
if vpc, ok := outputs[builder.CfnOutputClusterVPC]; ok {
spec.VPC.ID = vpc
} else {
Expand All @@ -112,13 +119,13 @@ func (c *ClusterProvider) GetClusterVPC(spec *api.ClusterConfig) error {

if securityGroup, ok := outputs[builder.CfnOutputClusterSecurityGroup]; ok {
spec.VPC.SecurityGroup = securityGroup
} else {
} else if isKeyRequired(builder.CfnOutputClusterSharedNodeSecurityGroup) {
return fmt.Errorf(requiredKeyErrFmt, builder.CfnOutputClusterSecurityGroup)
}

if sharedNodeSecurityGroup, ok := outputs[builder.CfnOutputClusterSharedNodeSecurityGroup]; ok {
spec.VPC.SharedNodeSecurityGroup = sharedNodeSecurityGroup
} else {
} else if isKeyRequired(builder.CfnOutputClusterSharedNodeSecurityGroup) {
return fmt.Errorf(requiredKeyErrFmt, builder.CfnOutputClusterSharedNodeSecurityGroup)
}

Expand Down

0 comments on commit ed2e2fa

Please sign in to comment.