Skip to content

Commit

Permalink
Merge pull request #1129 from weaveworks/append-cluster-config-tasks
Browse files Browse the repository at this point in the history
Refactor how additional cluster config tasks are handled
  • Loading branch information
errordeveloper committed Aug 9, 2019
2 parents ed8da92 + de71bd4 commit c9d01ef
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 39 deletions.
4 changes: 1 addition & 3 deletions pkg/ctl/create/cluster.go
Expand Up @@ -276,9 +276,7 @@ func doCreateCluster(cmd *cmdutils.Cmd, params *createClusterCmdParams) error {
}
logger.Info("if you encounter any issues, check CloudFormation console or try 'eksctl utils describe-stacks --region=%s --name=%s'", meta.Region, meta.Name)
tasks := stackManager.NewTasksToCreateClusterWithNodeGroups(ngSubset)
if updateClusterTasks := ctl.GetUpdateClusterConfigTasks(cfg); updateClusterTasks != nil {
tasks.Append(updateClusterTasks)
}
ctl.AppendExtraClusterConfigTasks(cfg, tasks)

logger.Info(tasks.Describe())
if errs := tasks.DoAllSync(); len(errs) > 0 {
Expand Down
44 changes: 44 additions & 0 deletions pkg/eks/tasks.go
@@ -0,0 +1,44 @@
package eks

import (
"github.com/kris-nova/logger"

api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
"github.com/weaveworks/eksctl/pkg/cfn/manager"
)

type clusterConfigTask struct {
info string
spec *api.ClusterConfig
call func(*api.ClusterConfig) error
}

func (t *clusterConfigTask) Describe() string { return t.info }

func (t *clusterConfigTask) Do(errs chan error) error {
err := t.call(t.spec)
close(errs)
return err
}

// AppendExtraClusterConfigTasks returns all tasks for updating cluster configuration or nil if there are no tasks
func (c *ClusterProvider) AppendExtraClusterConfigTasks(cfg *api.ClusterConfig, tasks *manager.TaskTree) {
newTasks := &manager.TaskTree{
Parallel: false,
IsSubTask: true,
}
if !cfg.HasClusterCloudWatchLogging() {
logger.Info("CloudWatch logging will not be enabled for cluster %q in %q", cfg.Metadata.Name, cfg.Metadata.Region)
logger.Info("you can enable it with 'eksctl utils update-cluster-logging --region=%s --name=%s'", cfg.Metadata.Region, cfg.Metadata.Name)

} else {
newTasks.Append(&clusterConfigTask{
info: "update CloudWatch logging configuration",
spec: cfg,
call: c.UpdateClusterConfigForLogging,
})
}
if newTasks.Len() > 0 {
tasks.Append(newTasks)
}
}
38 changes: 2 additions & 36 deletions pkg/eks/update.go
Expand Up @@ -4,34 +4,17 @@ import (
"fmt"
"strings"

"github.com/kris-nova/logger"
"github.com/pkg/errors"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/request"
awseks "github.com/aws/aws-sdk-go/service/eks"

"github.com/kris-nova/logger"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/sets"

api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
"github.com/weaveworks/eksctl/pkg/cfn/manager"
"github.com/weaveworks/eksctl/pkg/utils/waiters"
)

type updateClusterConfigTask struct {
info string
spec *api.ClusterConfig
call func(*api.ClusterConfig) error
}

func (t *updateClusterConfigTask) Describe() string { return t.info }

func (t *updateClusterConfigTask) Do(errs chan error) error {
err := t.call(t.spec)
close(errs)
return err
}

// GetCurrentClusterConfigForLogging fetches current cluster logging configuration as two sets - enabled and disabled types
func (c *ClusterProvider) GetCurrentClusterConfigForLogging(cl *api.ClusterMeta) (sets.String, sets.String, error) {
enabled := sets.NewString()
Expand Down Expand Up @@ -109,23 +92,6 @@ func (c *ClusterProvider) UpdateClusterConfigForLogging(cfg *api.ClusterConfig)
return nil
}

// GetUpdateClusterConfigTasks returns all tasks for updating cluster configuration or nil if there are no tasks
func (c *ClusterProvider) GetUpdateClusterConfigTasks(cfg *api.ClusterConfig) *manager.TaskTree {
if !cfg.HasClusterCloudWatchLogging() {
logger.Info("CloudWatch logging will not be enabled for cluster %q in %q", cfg.Metadata.Name, cfg.Metadata.Region)
logger.Info("you can enable it with 'eksctl utils update-cluster-logging --region=%s --name=%s'", cfg.Metadata.Region, cfg.Metadata.Name)
return nil
}

loggingTasks := &manager.TaskTree{Parallel: false}
loggingTasks.Append(&updateClusterConfigTask{
info: "update CloudWatch logging configuration",
spec: cfg,
call: c.UpdateClusterConfigForLogging,
})
return loggingTasks
}

// UpdateClusterVersion calls eks.UpdateClusterVersion and updates to cfg.Metadata.Version,
// it will return update ID along with an error (if it occurs)
func (c *ClusterProvider) UpdateClusterVersion(cfg *api.ClusterConfig) (*awseks.Update, error) {
Expand Down

0 comments on commit c9d01ef

Please sign in to comment.