Skip to content

Commit e49dd91

Browse files
authored
Merge pull request #7884 from cPu1/nodegroup-parallelism
Allow limiting the number of nodegroups created in parallel
2 parents b4af6ae + 4fcfce3 commit e49dd91

File tree

12 files changed

+100
-63
lines changed

12 files changed

+100
-63
lines changed

pkg/actions/nodegroup/create.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type CreateOpts struct {
3838
DryRunSettings DryRunSettings
3939
SkipOutdatedAddonsCheck bool
4040
ConfigFileProvided bool
41+
Parallelism int
4142
}
4243

4344
type DryRunSettings struct {
@@ -171,7 +172,7 @@ func (m *Manager) Create(ctx context.Context, options CreateOpts, nodegroupFilte
171172
return cmdutils.PrintNodeGroupDryRunConfig(clusterConfigCopy, options.DryRunSettings.OutStream)
172173
}
173174

174-
if err := m.nodeCreationTasks(ctx, isOwnedCluster, skipEgressRules, options.UpdateAuthConfigMap); err != nil {
175+
if err := m.nodeCreationTasks(ctx, isOwnedCluster, skipEgressRules, options.UpdateAuthConfigMap, options.Parallelism); err != nil {
175176
return err
176177
}
177178

@@ -203,7 +204,7 @@ func makeOutpostsService(clusterConfig *api.ClusterConfig, provider api.ClusterP
203204
}
204205
}
205206

206-
func (m *Manager) nodeCreationTasks(ctx context.Context, isOwnedCluster, skipEgressRules bool, updateAuthConfigMap *bool) error {
207+
func (m *Manager) nodeCreationTasks(ctx context.Context, isOwnedCluster, skipEgressRules bool, updateAuthConfigMap *bool, parallelism int) error {
207208
cfg := m.cfg
208209
meta := cfg.Metadata
209210

@@ -259,10 +260,10 @@ func (m *Manager) nodeCreationTasks(ctx context.Context, isOwnedCluster, skipEgr
259260
}
260261
disableAccessEntryCreation := !m.accessEntry.IsEnabled() || updateAuthConfigMap != nil
261262
if nodeGroupTasks := m.stackManager.NewUnmanagedNodeGroupTask(ctx, cfg.NodeGroups, !awsNodeUsesIRSA, skipEgressRules,
262-
disableAccessEntryCreation, vpcImporter); nodeGroupTasks.Len() > 0 {
263+
disableAccessEntryCreation, vpcImporter, parallelism); nodeGroupTasks.Len() > 0 {
263264
allNodeGroupTasks.Append(nodeGroupTasks)
264265
}
265-
managedTasks := m.stackManager.NewManagedNodeGroupTask(ctx, cfg.ManagedNodeGroups, !awsNodeUsesIRSA, vpcImporter)
266+
managedTasks := m.stackManager.NewManagedNodeGroupTask(ctx, cfg.ManagedNodeGroups, !awsNodeUsesIRSA, vpcImporter, parallelism)
266267
if managedTasks.Len() > 0 {
267268
allNodeGroupTasks.Append(managedTasks)
268269
}

pkg/actions/nodegroup/create_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ type stackManagerDelegate struct {
7777
ngTaskCreator nodeGroupTaskCreator
7878
}
7979

80-
func (s *stackManagerDelegate) NewUnmanagedNodeGroupTask(ctx context.Context, nodeGroups []*api.NodeGroup, forceAddCNIPolicy, skipEgressRules, disableAccessEntryCreation bool, vpcImporter vpc.Importer) *tasks.TaskTree {
80+
func (s *stackManagerDelegate) NewUnmanagedNodeGroupTask(ctx context.Context, nodeGroups []*api.NodeGroup, forceAddCNIPolicy, skipEgressRules, disableAccessEntryCreation bool, vpcImporter vpc.Importer, nodeGroupParallelism int) *tasks.TaskTree {
8181
return s.ngTaskCreator.NewUnmanagedNodeGroupTask(ctx, nodeGroups, forceAddCNIPolicy, skipEgressRules, disableAccessEntryCreation, vpcImporter)
8282
}
8383

84-
func (s *stackManagerDelegate) NewManagedNodeGroupTask(context.Context, []*api.ManagedNodeGroup, bool, vpc.Importer) *tasks.TaskTree {
84+
func (s *stackManagerDelegate) NewManagedNodeGroupTask(context.Context, []*api.ManagedNodeGroup, bool, vpc.Importer, int) *tasks.TaskTree {
8585
return nil
8686
}
8787

pkg/cfn/manager/create_tasks.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/pkg/errors"
8-
97
"github.com/kris-nova/logger"
108

119
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -25,7 +23,7 @@ import (
2523
// NewTasksToCreateCluster defines all tasks required to create a cluster along
2624
// with some nodegroups; see CreateAllNodeGroups for how onlyNodeGroupSubset works.
2725
func (c *StackCollection) NewTasksToCreateCluster(ctx context.Context, nodeGroups []*api.NodeGroup,
28-
managedNodeGroups []*api.ManagedNodeGroup, accessConfig *api.AccessConfig, accessEntryCreator accessentry.CreatorInterface, postClusterCreationTasks ...tasks.Task) *tasks.TaskTree {
26+
managedNodeGroups []*api.ManagedNodeGroup, accessConfig *api.AccessConfig, accessEntryCreator accessentry.CreatorInterface, nodeGroupParallelism int, postClusterCreationTasks ...tasks.Task) *tasks.TaskTree {
2927
taskTree := tasks.TaskTree{Parallel: false}
3028

3129
taskTree.Append(&createClusterTask{
@@ -46,11 +44,11 @@ func (c *StackCollection) NewTasksToCreateCluster(ctx context.Context, nodeGroup
4644
IsSubTask: true,
4745
}
4846
disableAccessEntryCreation := accessConfig.AuthenticationMode == ekstypes.AuthenticationModeConfigMap
49-
if unmanagedNodeGroupTasks := c.NewUnmanagedNodeGroupTask(ctx, nodeGroups, false, false, disableAccessEntryCreation, vpcImporter); unmanagedNodeGroupTasks.Len() > 0 {
47+
if unmanagedNodeGroupTasks := c.NewUnmanagedNodeGroupTask(ctx, nodeGroups, false, false, disableAccessEntryCreation, vpcImporter, nodeGroupParallelism); unmanagedNodeGroupTasks.Len() > 0 {
5048
unmanagedNodeGroupTasks.IsSubTask = true
5149
nodeGroupTasks.Append(unmanagedNodeGroupTasks)
5250
}
53-
if managedNodeGroupTasks := c.NewManagedNodeGroupTask(ctx, managedNodeGroups, false, vpcImporter); managedNodeGroupTasks.Len() > 0 {
51+
if managedNodeGroupTasks := c.NewManagedNodeGroupTask(ctx, managedNodeGroups, false, vpcImporter, nodeGroupParallelism); managedNodeGroupTasks.Len() > 0 {
5452
managedNodeGroupTasks.IsSubTask = true
5553
nodeGroupTasks.Append(managedNodeGroupTasks)
5654
}
@@ -75,7 +73,7 @@ func (c *StackCollection) NewTasksToCreateCluster(ctx context.Context, nodeGroup
7573
}
7674

7775
// NewUnmanagedNodeGroupTask returns tasks for creating self-managed nodegroups.
78-
func (c *StackCollection) NewUnmanagedNodeGroupTask(ctx context.Context, nodeGroups []*api.NodeGroup, forceAddCNIPolicy, skipEgressRules, disableAccessEntryCreation bool, vpcImporter vpc.Importer) *tasks.TaskTree {
76+
func (c *StackCollection) NewUnmanagedNodeGroupTask(ctx context.Context, nodeGroups []*api.NodeGroup, forceAddCNIPolicy, skipEgressRules, disableAccessEntryCreation bool, vpcImporter vpc.Importer, parallelism int) *tasks.TaskTree {
7977
task := &UnmanagedNodeGroupTask{
8078
ClusterConfig: c.spec,
8179
NodeGroups: nodeGroups,
@@ -93,12 +91,13 @@ func (c *StackCollection) NewUnmanagedNodeGroupTask(ctx context.Context, nodeGro
9391
SkipEgressRules: skipEgressRules,
9492
DisableAccessEntryCreation: disableAccessEntryCreation,
9593
VPCImporter: vpcImporter,
94+
Parallelism: parallelism,
9695
})
9796
}
9897

9998
// NewManagedNodeGroupTask defines tasks required to create managed nodegroups
100-
func (c *StackCollection) NewManagedNodeGroupTask(ctx context.Context, nodeGroups []*api.ManagedNodeGroup, forceAddCNIPolicy bool, vpcImporter vpc.Importer) *tasks.TaskTree {
101-
taskTree := &tasks.TaskTree{Parallel: true}
99+
func (c *StackCollection) NewManagedNodeGroupTask(ctx context.Context, nodeGroups []*api.ManagedNodeGroup, forceAddCNIPolicy bool, vpcImporter vpc.Importer, nodeGroupParallelism int) *tasks.TaskTree {
100+
taskTree := &tasks.TaskTree{Parallel: true, Limit: nodeGroupParallelism}
102101
for _, ng := range nodeGroups {
103102
// Disable parallelisation if any tags propagation is done
104103
// since nodegroup must be created to propagate tags to its ASGs.
@@ -162,7 +161,7 @@ func (c *StackCollection) NewTasksToCreateIAMServiceAccounts(serviceAccounts []*
162161
objectMeta.SetAnnotations(sa.AsObjectMeta().Annotations)
163162
objectMeta.SetLabels(sa.AsObjectMeta().Labels)
164163
if err := kubernetes.MaybeCreateServiceAccountOrUpdateMetadata(clientSet, objectMeta); err != nil {
165-
return errors.Wrapf(err, "failed to create service account %s/%s", objectMeta.GetNamespace(), objectMeta.GetName())
164+
return fmt.Errorf("failed to create service account %s/%s: %w", objectMeta.GetNamespace(), objectMeta.GetName(), err)
166165
}
167166
return nil
168167
},

pkg/cfn/manager/fakes/fake_stack_manager.go

Lines changed: 32 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)