Skip to content

Commit 9fc4aec

Browse files
committed
fix logic for updating aws-auth configmap
1 parent cbb613c commit 9fc4aec

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

integration/tests/accessentries/accessentries_test.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ var (
5050
namespaceRoleARN string
5151
err error
5252

53-
apiEnabledCluster = "accessentries-api-enabled-2"
54-
apiDisabledCluster = "accessentries-api-disabled-2"
53+
apiEnabledCluster = "accessentries-api-enabled"
54+
apiDisabledCluster = "accessentries-api-disabled"
5555
)
5656

5757
func init() {
@@ -123,24 +123,39 @@ var _ = Describe("(Integration) [AccessEntries Test]", func() {
123123
cfg = makeClusterConfig(apiDisabledCluster)
124124
})
125125

126-
It("should create a cluster with authenticationMode set to CONFIG_MAP", func() {
126+
It("should create a cluster with authenticationMode set to CONFIG_MAP and allow self-managed nodes to join via aws-auth", func() {
127127
cfg.AccessConfig.AuthenticationMode = ekstypes.AuthenticationModeConfigMap
128-
128+
cfg.NodeGroups = append(cfg.NodeGroups, &api.NodeGroup{
129+
NodeGroupBase: &api.NodeGroupBase{
130+
Name: "aws-auth-ng",
131+
ScalingConfig: &api.ScalingConfig{
132+
DesiredCapacity: aws.Int(1),
133+
},
134+
},
135+
})
129136
data, err := json.Marshal(cfg)
130137
Expect(err).NotTo(HaveOccurred())
131138

132139
Expect(params.EksctlCreateCmd.
133140
WithArgs(
134141
"cluster",
135142
"--config-file", "-",
136-
"--without-nodegroup",
137143
"--verbose", "4",
138144
).
139145
WithoutArg("--region", params.Region).
140146
WithStdin(bytes.NewReader(data))).To(RunSuccessfully())
141147

142148
Expect(ctl.RefreshClusterStatus(context.Background(), cfg)).NotTo(HaveOccurred())
143149
Expect(ctl.IsAccessEntryEnabled()).To(BeFalse())
150+
151+
Expect(params.EksctlGetCmd.WithArgs(
152+
"nodegroup",
153+
"--cluster", apiDisabledCluster,
154+
"--name", "aws-auth-ng",
155+
"-o", "yaml",
156+
)).To(runner.RunSuccessfullyWithOutputStringLines(
157+
ContainElement(ContainSubstring("Status: CREATE_COMPLETE")),
158+
))
144159
})
145160

146161
It("should fail early when trying to create access entries", func() {
@@ -400,6 +415,7 @@ var _ = SynchronizedAfterSuite(func() {}, func() {
400415
WithArgs(
401416
"cluster",
402417
"--name", apiDisabledCluster,
418+
"--disable-nodegroup-eviction",
403419
"--wait",
404420
)).To(RunSuccessfully())
405421

pkg/actions/nodegroup/create.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,17 @@ func (m *Manager) postNodeCreationTasks(ctx context.Context, clientSet kubernete
285285
timeoutCtx, cancel := context.WithTimeout(ctx, m.ctl.AWSProvider.WaitTimeout())
286286
defer cancel()
287287

288-
if (!m.accessEntry.IsEnabled() && !api.IsDisabled(options.UpdateAuthConfigMap)) || api.IsEnabled(options.UpdateAuthConfigMap) {
288+
// authorize self-managed nodes to join the cluster via aws-auth configmap
289+
// if EKS access entries are disabled OR
290+
if (!m.accessEntry.IsEnabled() && !api.IsDisabled(options.UpdateAuthConfigMap)) ||
291+
// if explicitly requested by the user
292+
api.IsEnabled(options.UpdateAuthConfigMap) {
289293
if err := eks.UpdateAuthConfigMap(m.cfg.NodeGroups, clientSet); err != nil {
290294
return err
291295
}
292296
}
297+
298+
// only wait for self-managed nodes to join if either authorization method is being used
293299
if !api.IsDisabled(options.UpdateAuthConfigMap) {
294300
for _, ng := range m.cfg.NodeGroups {
295301
if err := eks.WaitForNodes(timeoutCtx, clientSet, ng); err != nil {
@@ -298,6 +304,7 @@ func (m *Manager) postNodeCreationTasks(ctx context.Context, clientSet kubernete
298304
}
299305
}
300306
logger.Success("created %d nodegroup(s) in cluster %q", len(m.cfg.NodeGroups), m.cfg.Metadata.Name)
307+
301308
for _, ng := range m.cfg.ManagedNodeGroups {
302309
if err := eks.WaitForNodes(timeoutCtx, clientSet, ng); err != nil {
303310
if m.cfg.PrivateCluster.Enabled {
@@ -308,8 +315,8 @@ func (m *Manager) postNodeCreationTasks(ctx context.Context, clientSet kubernete
308315
}
309316
}
310317
}
311-
312318
logger.Success("created %d managed nodegroup(s) in cluster %q", len(m.cfg.ManagedNodeGroups), m.cfg.Metadata.Name)
319+
313320
return nil
314321
}
315322

pkg/ctl/create/cluster.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"sync"
99

1010
"github.com/aws/aws-sdk-go-v2/aws"
11+
ekstypes "github.com/aws/aws-sdk-go-v2/service/eks/types"
1112

1213
"github.com/aws/amazon-ec2-instance-selector/v2/pkg/selector"
1314
"github.com/kris-nova/logger"
@@ -426,18 +427,28 @@ func doCreateCluster(cmd *cmdutils.Cmd, ngFilter *filter.NodeGroupFilter, params
426427
} else {
427428
ngCtx, cancel := context.WithTimeout(ctx, cmd.ProviderConfig.WaitTimeout)
428429
defer cancel()
430+
431+
// authorize self-managed nodes to join the cluster via aws-auth configmap
432+
// only if EKS access entries are disabled
433+
if cfg.AccessConfig.AuthenticationMode == ekstypes.AuthenticationModeConfigMap {
434+
if err := eks.UpdateAuthConfigMap(cfg.NodeGroups, clientSet); err != nil {
435+
return err
436+
}
437+
}
438+
429439
for _, ng := range cfg.NodeGroups {
430-
// wait for nodes to join
431440
if err := eks.WaitForNodes(ngCtx, clientSet, ng); err != nil {
432441
return err
433442
}
434443
}
444+
logger.Success("created %d nodegroup(s) in cluster %q", len(cfg.NodeGroups), cfg.Metadata.Name)
435445

436446
for _, ng := range cfg.ManagedNodeGroups {
437447
if err := eks.WaitForNodes(ngCtx, clientSet, ng); err != nil {
438448
return err
439449
}
440450
}
451+
logger.Success("created %d managed nodegroup(s) in cluster %q", len(cfg.ManagedNodeGroups), cfg.Metadata.Name)
441452
}
442453
}
443454
if postNodegroupAddons != nil && postNodegroupAddons.Len() > 0 {

0 commit comments

Comments
 (0)