in pkg/providers/amifamily/resolver.go [222:290]
func (r DefaultResolver) resolveLaunchTemplates(
nodeClass *v1.EC2NodeClass,
nodeClaim *karpv1.NodeClaim,
instanceTypes []*cloudprovider.InstanceType,
capacityType string,
amiFamily AMIFamily,
amiID string,
maxPods int,
efaCount int,
capacityReservationIDs []string,
options *Options,
) []*LaunchTemplate {
kubeletConfig := &v1.KubeletConfiguration{}
if nodeClass.Spec.Kubelet != nil {
kubeletConfig = nodeClass.Spec.Kubelet.DeepCopy()
}
if kubeletConfig.MaxPods == nil {
// nolint:gosec
// We know that it's not possible to have values that would overflow int32 here since we control
// the maxPods values that we pass in here
kubeletConfig.MaxPods = lo.ToPtr(int32(maxPods))
}
taints := lo.Flatten([][]corev1.Taint{
nodeClaim.Spec.Taints,
nodeClaim.Spec.StartupTaints,
})
if _, found := lo.Find(taints, func(t corev1.Taint) bool {
return t.MatchTaint(&karpv1.UnregisteredNoExecuteTaint)
}); !found {
taints = append(taints, karpv1.UnregisteredNoExecuteTaint)
}
// If no reservation IDs are provided, insert an empty string so the end result is a single launch template with no
// associated capacity reservation.
// TODO: We can simplify this by creating an initial lt, and then copying it for each cr. However, this requires a deep
// copy of the LT struct, which contains an interface causing problems for deepcopy-gen. See review comment for context:
// https://github.com/aws/karpenter-provider-aws/pull/7726#discussion_r1955280055
if len(capacityReservationIDs) == 0 {
capacityReservationIDs = append(capacityReservationIDs, "")
}
return lo.Map(capacityReservationIDs, func(id string, _ int) *LaunchTemplate {
resolved := &LaunchTemplate{
Options: options,
UserData: amiFamily.UserData(
r.defaultClusterDNS(options, kubeletConfig),
taints,
options.Labels,
options.CABundle,
instanceTypes,
nodeClass.Spec.UserData,
options.InstanceStorePolicy,
),
BlockDeviceMappings: nodeClass.Spec.BlockDeviceMappings,
MetadataOptions: nodeClass.Spec.MetadataOptions,
DetailedMonitoring: aws.ToBool(nodeClass.Spec.DetailedMonitoring),
AMIID: amiID,
InstanceTypes: instanceTypes,
EFACount: efaCount,
CapacityType: capacityType,
CapacityReservationID: id,
}
if len(resolved.BlockDeviceMappings) == 0 {
resolved.BlockDeviceMappings = amiFamily.DefaultBlockDeviceMappings()
}
if resolved.MetadataOptions == nil {
resolved.MetadataOptions = amiFamily.DefaultMetadataOptions()
}
return resolved
})
}