diff --git a/integration/tests/accessentries/accessentries_test.go b/integration/tests/accessentries/accessentries_test.go index ab60e57563..1e48dba4cc 100644 --- a/integration/tests/accessentries/accessentries_test.go +++ b/integration/tests/accessentries/accessentries_test.go @@ -50,8 +50,8 @@ var ( namespaceRoleARN string err error - apiEnabledCluster = "accessentries-api-enabled-2" - apiDisabledCluster = "accessentries-api-disabled-2" + apiEnabledCluster = "accessentries-api-enabled" + apiDisabledCluster = "accessentries-api-disabled" ) func init() { @@ -123,9 +123,16 @@ var _ = Describe("(Integration) [AccessEntries Test]", func() { cfg = makeClusterConfig(apiDisabledCluster) }) - It("should create a cluster with authenticationMode set to CONFIG_MAP", func() { + It("should create a cluster with authenticationMode set to CONFIG_MAP and allow self-managed nodes to join via aws-auth", func() { cfg.AccessConfig.AuthenticationMode = ekstypes.AuthenticationModeConfigMap - + cfg.NodeGroups = append(cfg.NodeGroups, &api.NodeGroup{ + NodeGroupBase: &api.NodeGroupBase{ + Name: "aws-auth-ng", + ScalingConfig: &api.ScalingConfig{ + DesiredCapacity: aws.Int(1), + }, + }, + }) data, err := json.Marshal(cfg) Expect(err).NotTo(HaveOccurred()) @@ -133,7 +140,6 @@ var _ = Describe("(Integration) [AccessEntries Test]", func() { WithArgs( "cluster", "--config-file", "-", - "--without-nodegroup", "--verbose", "4", ). WithoutArg("--region", params.Region). @@ -141,6 +147,15 @@ var _ = Describe("(Integration) [AccessEntries Test]", func() { Expect(ctl.RefreshClusterStatus(context.Background(), cfg)).NotTo(HaveOccurred()) Expect(ctl.IsAccessEntryEnabled()).To(BeFalse()) + + Expect(params.EksctlGetCmd.WithArgs( + "nodegroup", + "--cluster", apiDisabledCluster, + "--name", "aws-auth-ng", + "-o", "yaml", + )).To(runner.RunSuccessfullyWithOutputStringLines( + ContainElement(ContainSubstring("Status: CREATE_COMPLETE")), + )) }) It("should fail early when trying to create access entries", func() { @@ -400,6 +415,7 @@ var _ = SynchronizedAfterSuite(func() {}, func() { WithArgs( "cluster", "--name", apiDisabledCluster, + "--disable-nodegroup-eviction", "--wait", )).To(RunSuccessfully()) diff --git a/pkg/actions/nodegroup/create.go b/pkg/actions/nodegroup/create.go index 50247e15d5..136c27f628 100644 --- a/pkg/actions/nodegroup/create.go +++ b/pkg/actions/nodegroup/create.go @@ -285,11 +285,17 @@ func (m *Manager) postNodeCreationTasks(ctx context.Context, clientSet kubernete timeoutCtx, cancel := context.WithTimeout(ctx, m.ctl.AWSProvider.WaitTimeout()) defer cancel() - if (!m.accessEntry.IsEnabled() && !api.IsDisabled(options.UpdateAuthConfigMap)) || api.IsEnabled(options.UpdateAuthConfigMap) { + // authorize self-managed nodes to join the cluster via aws-auth configmap + // if EKS access entries are disabled OR + if (!m.accessEntry.IsEnabled() && !api.IsDisabled(options.UpdateAuthConfigMap)) || + // if explicitly requested by the user + api.IsEnabled(options.UpdateAuthConfigMap) { if err := eks.UpdateAuthConfigMap(m.cfg.NodeGroups, clientSet); err != nil { return err } } + + // only wait for self-managed nodes to join if either authorization method is being used if !api.IsDisabled(options.UpdateAuthConfigMap) { for _, ng := range m.cfg.NodeGroups { if err := eks.WaitForNodes(timeoutCtx, clientSet, ng); err != nil { @@ -298,6 +304,7 @@ func (m *Manager) postNodeCreationTasks(ctx context.Context, clientSet kubernete } } logger.Success("created %d nodegroup(s) in cluster %q", len(m.cfg.NodeGroups), m.cfg.Metadata.Name) + for _, ng := range m.cfg.ManagedNodeGroups { if err := eks.WaitForNodes(timeoutCtx, clientSet, ng); err != nil { if m.cfg.PrivateCluster.Enabled { @@ -308,8 +315,8 @@ func (m *Manager) postNodeCreationTasks(ctx context.Context, clientSet kubernete } } } - logger.Success("created %d managed nodegroup(s) in cluster %q", len(m.cfg.ManagedNodeGroups), m.cfg.Metadata.Name) + return nil } diff --git a/pkg/ctl/create/cluster.go b/pkg/ctl/create/cluster.go index 3ee32407cf..248e40ff3a 100644 --- a/pkg/ctl/create/cluster.go +++ b/pkg/ctl/create/cluster.go @@ -8,6 +8,7 @@ import ( "sync" "github.com/aws/aws-sdk-go-v2/aws" + ekstypes "github.com/aws/aws-sdk-go-v2/service/eks/types" "github.com/aws/amazon-ec2-instance-selector/v2/pkg/selector" "github.com/kris-nova/logger" @@ -426,18 +427,28 @@ func doCreateCluster(cmd *cmdutils.Cmd, ngFilter *filter.NodeGroupFilter, params } else { ngCtx, cancel := context.WithTimeout(ctx, cmd.ProviderConfig.WaitTimeout) defer cancel() + + // authorize self-managed nodes to join the cluster via aws-auth configmap + // only if EKS access entries are disabled + if cfg.AccessConfig.AuthenticationMode == ekstypes.AuthenticationModeConfigMap { + if err := eks.UpdateAuthConfigMap(cfg.NodeGroups, clientSet); err != nil { + return err + } + } + for _, ng := range cfg.NodeGroups { - // wait for nodes to join if err := eks.WaitForNodes(ngCtx, clientSet, ng); err != nil { return err } } + logger.Success("created %d nodegroup(s) in cluster %q", len(cfg.NodeGroups), cfg.Metadata.Name) for _, ng := range cfg.ManagedNodeGroups { if err := eks.WaitForNodes(ngCtx, clientSet, ng); err != nil { return err } } + logger.Success("created %d managed nodegroup(s) in cluster %q", len(cfg.ManagedNodeGroups), cfg.Metadata.Name) } } if postNodegroupAddons != nil && postNodegroupAddons.Len() > 0 {