-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- more visibility into what task manager does - print clear descriptions of what is being done - enable addition of `--dry-run` to every command - cleaner main functions for create and delete commands - more general abstraction for tasks - expose all common operations through functions - remove special purpose taks handler functions
- Loading branch information
1 parent
653cd2a
commit cbcb386
Showing
12 changed files
with
491 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package manager | ||
|
||
import ( | ||
"fmt" | ||
|
||
"k8s.io/apimachinery/pkg/util/sets" | ||
) | ||
|
||
// CreateTasksForClusterWithNodeGroups defines all tasks required to create a cluster along | ||
// with some nodegroups; see CreateAllNodeGroups for how onlyNodeGroupSubset works | ||
func (c *StackCollection) CreateTasksForClusterWithNodeGroups(onlyNodeGroupSubset sets.String) *TaskSet { | ||
tasks := &TaskSet{Parallel: false} | ||
|
||
tasks.Append( | ||
&taskWithoutParams{ | ||
info: fmt.Sprintf("create cluster control plane %q", c.spec.Metadata.Name), | ||
call: c.createClusterTask, | ||
}, | ||
) | ||
|
||
nodeGroupTasks := c.CreateTasksForNodeGroups(onlyNodeGroupSubset) | ||
if nodeGroupTasks.Len() > 0 { | ||
nodeGroupTasks.Sub = true | ||
tasks.Append(nodeGroupTasks) | ||
} | ||
|
||
return tasks | ||
} | ||
|
||
// CreateTasksForNodeGroups defines tasks required to create all of the nodegroups if | ||
// onlySubset is nil, otherwise just the tasks for nodegroups that are in onlySubset | ||
// will be defined | ||
func (c *StackCollection) CreateTasksForNodeGroups(onlySubset sets.String) *TaskSet { | ||
tasks := &TaskSet{Parallel: true} | ||
|
||
for i := range c.spec.NodeGroups { | ||
ng := c.spec.NodeGroups[i] | ||
if onlySubset != nil && !onlySubset.Has(ng.Name) { | ||
continue | ||
} | ||
tasks.Append(&taskWithNodeGroupSpec{ | ||
info: fmt.Sprintf("create nodegroup %q", ng.Name), | ||
nodeGroup: ng, | ||
call: c.createNodeGroupTask, | ||
}) | ||
} | ||
|
||
return tasks | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package manager | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/service/cloudformation" | ||
|
||
"k8s.io/apimachinery/pkg/util/sets" | ||
) | ||
|
||
// DeleteTasksForClusterWithNodeGroups defines tasks required to delete all the nodegroup | ||
// stacks and the cluster | ||
func (c *StackCollection) DeleteTasksForClusterWithNodeGroups(wait bool, cleanup func(chan error, string) error) (*TaskSet, error) { | ||
tasks := &TaskSet{Parallel: false} | ||
|
||
nodeGroupTasks, err := c.DeleteTasksForNodeGroups(nil, true, cleanup) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if nodeGroupTasks.Len() > 0 { | ||
nodeGroupTasks.Sub = true | ||
tasks.Append(nodeGroupTasks) | ||
} | ||
|
||
clusterStack, err := c.DescribeClusterStack() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
info := fmt.Sprintf("delete cluster control plane %q", c.spec.Metadata.Name) | ||
if wait { | ||
tasks.Append(&taskWithStackSpec{ | ||
info: info, | ||
stack: clusterStack, | ||
call: c.WaitDeleteStackBySpec, | ||
}) | ||
} else { | ||
tasks.Append(&asyncTaskWithStackSpec{ | ||
info: info, | ||
stack: clusterStack, | ||
call: c.DeleteStackBySpec, | ||
}) | ||
} | ||
|
||
return tasks, nil | ||
} | ||
|
||
// DeleteTasksForNodeGroups defines tasks required to delete all of the nodegroups if | ||
// onlySubset is nil, otherwise just the tasks for nodegroups that are in onlySubset | ||
// will be defined | ||
func (c *StackCollection) DeleteTasksForNodeGroups(onlySubset sets.String, wait bool, cleanup func(chan error, string) error) (*TaskSet, error) { | ||
nodeGroupStacks, err := c.DescribeNodeGroupStacks() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
tasks := &TaskSet{Parallel: true} | ||
|
||
for _, s := range nodeGroupStacks { | ||
name := getNodeGroupName(s) | ||
if onlySubset != nil && !onlySubset.Has(name) { | ||
continue | ||
} | ||
if *s.StackStatus == cloudformation.StackStatusDeleteFailed && cleanup != nil { | ||
tasks.Append(&taskWithNameParam{ | ||
info: fmt.Sprintf("cleanup for nodegroup %q", name), | ||
call: cleanup, | ||
}) | ||
} | ||
info := fmt.Sprintf("delete nodegroup %q", name) | ||
if wait { | ||
tasks.Append(&taskWithStackSpec{ | ||
info: info, | ||
stack: s, | ||
call: c.WaitDeleteStackBySpec, | ||
}) | ||
} else { | ||
tasks.Append(&asyncTaskWithStackSpec{ | ||
info: info, | ||
stack: s, | ||
call: c.DeleteStackBySpec, | ||
}) | ||
} | ||
} | ||
|
||
return tasks, nil | ||
} |
Oops, something went wrong.