diff --git a/pkg/apis/eksctl.io/v1alpha5/validation_test.go b/pkg/apis/eksctl.io/v1alpha5/validation_test.go index 1fa4b2eed1..b93cd93992 100644 --- a/pkg/apis/eksctl.io/v1alpha5/validation_test.go +++ b/pkg/apis/eksctl.io/v1alpha5/validation_test.go @@ -2087,15 +2087,6 @@ var _ = Describe("ClusterConfig validation", func() { err := api.ValidateManagedNodeGroup(0, ng) Expect(err).To(MatchError(ContainSubstring("eksctl does not support configuring maxPodsPerNode EKS-managed nodes"))) }) - It("returns an error when setting preBootstrapCommands for self-managed nodegroups", func() { - cfg := api.NewClusterConfig() - ng := cfg.NewNodeGroup() - ng.Name = "node-group" - ng.AMI = "ami-1234" - ng.AMIFamily = api.NodeImageFamilyAmazonLinux2023 - ng.PreBootstrapCommands = []string{"echo 'rubarb'"} - Expect(api.ValidateNodeGroup(0, ng, cfg)).To(MatchError(ContainSubstring(fmt.Sprintf("preBootstrapCommands is not supported for %s nodegroups", api.NodeImageFamilyAmazonLinux2023)))) - }) It("returns an error when setting overrideBootstrapCommand for self-managed nodegroups", func() { cfg := api.NewClusterConfig() ng := cfg.NewNodeGroup() @@ -2105,14 +2096,6 @@ var _ = Describe("ClusterConfig validation", func() { ng.OverrideBootstrapCommand = aws.String("echo 'rubarb'") Expect(api.ValidateNodeGroup(0, ng, cfg)).To(MatchError(ContainSubstring(fmt.Sprintf("overrideBootstrapCommand is not supported for %s nodegroups", api.NodeImageFamilyAmazonLinux2023)))) }) - It("returns an error when setting preBootstrapCommands for EKS-managed nodegroups", func() { - ng := api.NewManagedNodeGroup() - ng.Name = "node-group" - ng.AMI = "ami-1234" - ng.AMIFamily = api.NodeImageFamilyAmazonLinux2023 - ng.PreBootstrapCommands = []string{"echo 'rubarb'"} - Expect(api.ValidateManagedNodeGroup(0, ng)).To(MatchError(ContainSubstring(fmt.Sprintf("preBootstrapCommands is not supported for %s nodegroups", api.NodeImageFamilyAmazonLinux2023)))) - }) It("returns an error when setting overrideBootstrapCommand for EKS-managed nodegroups", func() { ng := api.NewManagedNodeGroup() ng.Name = "node-group" diff --git a/pkg/nodebootstrap/al2023.go b/pkg/nodebootstrap/al2023.go index 1943f92823..2fcc28e8b2 100644 --- a/pkg/nodebootstrap/al2023.go +++ b/pkg/nodebootstrap/al2023.go @@ -58,6 +58,11 @@ func (m *AL2023) UserData() (string, error) { if err != nil { return "", fmt.Errorf("generating node config: %w", err) } + + for _, command := range m.nodePool.BaseNodeGroup().PreBootstrapCommands { + m.scripts = append(m.scripts, "#!/bin/bash\n"+command) + } + if len(m.scripts) == 0 && len(m.cloudboot) == 0 && nodeConfig == nil { return "", nil }