Skip to content

Commit

Permalink
disallow overrideBootstrapCommand and preBootstrapCommands for MNG AL…
Browse files Browse the repository at this point in the history
…2023
  • Loading branch information
TiberiuGC committed Oct 7, 2024
1 parent 5546810 commit f2eeb47
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 24 deletions.
23 changes: 16 additions & 7 deletions pkg/apis/eksctl.io/v1alpha5/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,22 @@ func validateNodeGroupBase(np NodePool, path string, controlPlaneOnOutposts bool
}
}

if ng.AMIFamily == NodeImageFamilyAmazonLinux2023 {
fieldNotSupported := func(field string) error {
return &unsupportedFieldError{
ng: ng,
path: path,
field: field,
}
}
if ng.PreBootstrapCommands != nil {
return fieldNotSupported("preBootstrapCommands")
}
if ng.OverrideBootstrapCommand != nil {
return fieldNotSupported("overrideBootstrapCommand")
}
}

if ng.CapacityReservation != nil {
if ng.CapacityReservation.CapacityReservationPreference != nil {
if ng.CapacityReservation.CapacityReservationTarget != nil {
Expand Down Expand Up @@ -871,13 +887,6 @@ func ValidateNodeGroup(i int, ng *NodeGroup, cfg *ClusterConfig) error {
if ng.KubeletExtraConfig != nil {
return fieldNotSupported("kubeletExtraConfig")
}
} else if ng.AMIFamily == NodeImageFamilyAmazonLinux2023 {
if ng.PreBootstrapCommands != nil {
return fieldNotSupported("preBootstrapCommands")
}
if ng.OverrideBootstrapCommand != nil {
return fieldNotSupported("overrideBootstrapCommand")
}
} else if ng.AMIFamily == NodeImageFamilyBottlerocket {
if ng.KubeletExtraConfig != nil {
return fieldNotSupported("kubeletExtraConfig")
Expand Down
51 changes: 34 additions & 17 deletions pkg/apis/eksctl.io/v1alpha5/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,6 @@ var _ = Describe("ClusterConfig validation", func() {
errMsg := fmt.Sprintf("overrideBootstrapCommand is required when using a custom AMI based on %s", ng0.AMIFamily)
Expect(api.ValidateNodeGroup(0, ng0, cfg)).To(MatchError(ContainSubstring(errMsg)))
})
It("should not require overrideBootstrapCommand if ami is set and type is AmazonLinux2023", func() {
cfg := api.NewClusterConfig()
ng0 := cfg.NewNodeGroup()
ng0.Name = "node-group"
ng0.AMI = "ami-1234"
ng0.AMIFamily = api.NodeImageFamilyAmazonLinux2023
Expect(api.ValidateNodeGroup(0, ng0, cfg)).To(Succeed())
})
It("should not require overrideBootstrapCommand if ami is set and type is Bottlerocket", func() {
cfg := api.NewClusterConfig()
ng0 := cfg.NewNodeGroup()
Expand All @@ -204,15 +196,6 @@ var _ = Describe("ClusterConfig validation", func() {
ng0.OverrideBootstrapCommand = aws.String("echo 'yo'")
Expect(api.ValidateNodeGroup(0, ng0, cfg)).To(Succeed())
})
It("should throw an error if overrideBootstrapCommand is set and type is AmazonLinux2023", func() {
cfg := api.NewClusterConfig()
ng0 := cfg.NewNodeGroup()
ng0.Name = "node-group"
ng0.AMI = "ami-1234"
ng0.AMIFamily = api.NodeImageFamilyAmazonLinux2023
ng0.OverrideBootstrapCommand = aws.String("echo 'yo'")
Expect(api.ValidateNodeGroup(0, ng0, cfg)).To(MatchError(ContainSubstring(fmt.Sprintf("overrideBootstrapCommand is not supported for %s nodegroups", api.NodeImageFamilyAmazonLinux2023))))
})
It("should throw an error if overrideBootstrapCommand is set and type is Bottlerocket", func() {
cfg := api.NewClusterConfig()
ng0 := cfg.NewNodeGroup()
Expand Down Expand Up @@ -2104,6 +2087,40 @@ 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()
ng.Name = "node-group"
ng.AMI = "ami-1234"
ng.AMIFamily = api.NodeImageFamilyAmazonLinux2023
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"
ng.AMI = "ami-1234"
ng.AMIFamily = api.NodeImageFamilyAmazonLinux2023
ng.OverrideBootstrapCommand = aws.String("echo 'rubarb'")
Expect(api.ValidateManagedNodeGroup(0, ng)).To(MatchError(ContainSubstring(fmt.Sprintf("overrideBootstrapCommand is not supported for %s nodegroups", api.NodeImageFamilyAmazonLinux2023))))
})
})

Describe("Windows node groups", func() {
Expand Down

0 comments on commit f2eeb47

Please sign in to comment.