@@ -121,9 +121,22 @@ func vpcCNIAddonSpecified(cfg *ClusterConfig) bool {
121
121
}
122
122
123
123
// SetNodeGroupDefaults will set defaults for a given nodegroup
124
- func SetNodeGroupDefaults (ng * NodeGroup , meta * ClusterMeta , controlPlaneOnOutposts bool ) {
124
+ func SetNodeGroupDefaults (ng * NodeGroup , meta * ClusterMeta , controlPlaneOnOutposts bool ) error {
125
125
setNodeGroupBaseDefaults (ng .NodeGroupBase , meta )
126
126
127
+ // Set default AMI family depending on Kubernetes version
128
+ isAL2EOLVersion , _ := utils .IsMinVersion (AmazonLinux2EOLVersion , meta .Version )
129
+ if isAL2EOLVersion {
130
+ // For newer Kubernetes versions, default to AL2023
131
+ if ng .AMIFamily == "" {
132
+ ng .AMIFamily = NodeImageFamilyAmazonLinux2023
133
+ }
134
+ // Since AL2 isn't supported, throw an error if the user explicitly requested AL2
135
+ if ng .AMIFamily == NodeImageFamilyAmazonLinux2 {
136
+ return fmt .Errorf ("AmazonLinux2 is not supported for Kubernetes version %s" , meta .Version )
137
+ }
138
+ }
139
+ // Default to AL2 for Kubernetes versions prior to AmazonLinux2EOLVersion
127
140
if ng .AMIFamily == "" {
128
141
ng .AMIFamily = DefaultNodeImageFamily
129
142
}
@@ -139,15 +152,27 @@ func SetNodeGroupDefaults(ng *NodeGroup, meta *ClusterMeta, controlPlaneOnOutpos
139
152
}
140
153
141
154
setContainerRuntimeDefault (ng , meta .Version )
155
+ return nil
142
156
}
143
157
144
158
// SetManagedNodeGroupDefaults sets default values for a ManagedNodeGroup
145
- func SetManagedNodeGroupDefaults (ng * ManagedNodeGroup , meta * ClusterMeta , controlPlaneOnOutposts bool ) {
159
+ func SetManagedNodeGroupDefaults (ng * ManagedNodeGroup , meta * ClusterMeta , controlPlaneOnOutposts bool ) error {
146
160
setNodeGroupBaseDefaults (ng .NodeGroupBase , meta )
147
161
148
162
// When using custom AMIs, we want the user to explicitly specify AMI family.
149
163
// Thus, we only set up default AMI family when no custom AMI is being used.
150
- if ng .AMIFamily == "" && ng .AMI == "" {
164
+ isAL2EOLVersion , _ := utils .IsMinVersion (AmazonLinux2EOLVersion , meta .Version )
165
+ if ng .AMI == "" && isAL2EOLVersion {
166
+ // Set default AMI family depending on Kubernetes version
167
+ // For newer Kubernetes versions, default to AL2023
168
+ if ng .AMIFamily == "" {
169
+ ng .AMIFamily = NodeImageFamilyAmazonLinux2023
170
+ }
171
+ // Since AL2 isn't supported for this K8s version, throw an error if the user explicitly requested AL2
172
+ if ng .AMIFamily == NodeImageFamilyAmazonLinux2 {
173
+ return fmt .Errorf ("AmazonLinux2 is not supported for Kubernetes version %s" , meta .Version )
174
+ }
175
+ } else if ng .AMI == "" && ng .AMIFamily == "" {
151
176
// AL2023 is the default ami type on EKS managed nodegroups after 1.30.
152
177
if isMinVer , _ := utils .IsMinVersion (Version1_30 , meta .Version ); isMinVer {
153
178
ng .AMIFamily = NodeImageFamilyAmazonLinux2023
@@ -164,6 +189,8 @@ func SetManagedNodeGroupDefaults(ng *ManagedNodeGroup, meta *ClusterMeta, contro
164
189
165
190
setVolumeDefaults (ng .NodeGroupBase , controlPlaneOnOutposts , ng .LaunchTemplate )
166
191
setDefaultsForAdditionalVolumes (ng .NodeGroupBase , controlPlaneOnOutposts )
192
+
193
+ return nil
167
194
}
168
195
169
196
func setNodeGroupBaseDefaults (ng * NodeGroupBase , meta * ClusterMeta ) {
0 commit comments