@@ -266,6 +266,7 @@ type EC2InstanceMetadataCache struct {
266266 additionalENITags map [string ]string
267267 imds TypedIMDS
268268 ec2SVC ec2wrapper.EC2
269+ connectionTrackingSpec * ec2types.ConnectionTrackingSpecificationRequest
269270}
270271
271272// ENIMetadata contains information about an ENI
@@ -1152,6 +1153,11 @@ func (cache *EC2InstanceMetadataCache) createENIInput(eniDescription string, tag
11521153 SubnetId : aws .String (cache .subnetID ),
11531154 TagSpecifications : tags ,
11541155 }
1156+
1157+ if cache .connectionTrackingSpec != nil {
1158+ input .ConnectionTrackingSpecification = cache .connectionTrackingSpec
1159+ }
1160+
11551161 // Even though IPv6 PD is enabled, we require a Primary IP for the ENI.
11561162 // This always creates an ENI which has 1 Primary IPv6 address
11571163 // We use assignIPv6Prefix to assign a prefix during setupENI
@@ -1169,6 +1175,32 @@ func (cache *EC2InstanceMetadataCache) createENIInput(eniDescription string, tag
11691175 return input
11701176}
11711177
1178+ // setConnectionTrackingSettings applies connection tracking settings only if the primary ENI has it configured.
1179+ // Only non-nil values from the primary ENI configuration are stored.
1180+ func (cache * EC2InstanceMetadataCache ) setConnectionTrackingSettings (config * ec2types.ConnectionTrackingConfiguration ) {
1181+ if config == nil || (config .TcpEstablishedTimeout == nil && config .UdpStreamTimeout == nil && config .UdpTimeout == nil ) {
1182+ cache .connectionTrackingSpec = nil
1183+ return
1184+ }
1185+
1186+ settings := & ec2types.ConnectionTrackingSpecificationRequest {}
1187+ msg := "Connection tracking settings from primary ENI"
1188+ if config .TcpEstablishedTimeout != nil {
1189+ settings .TcpEstablishedTimeout = config .TcpEstablishedTimeout
1190+ msg += fmt .Sprintf (" tcpEstablishedTimeout=%d" , * config .TcpEstablishedTimeout )
1191+ }
1192+ if config .UdpStreamTimeout != nil {
1193+ settings .UdpStreamTimeout = config .UdpStreamTimeout
1194+ msg += fmt .Sprintf (" udpStreamTimeout=%d" , * config .UdpStreamTimeout )
1195+ }
1196+ if config .UdpTimeout != nil {
1197+ settings .UdpTimeout = config .UdpTimeout
1198+ msg += fmt .Sprintf (" udpTimeout=%d" , * config .UdpTimeout )
1199+ }
1200+ cache .connectionTrackingSpec = settings
1201+ log .Debug (msg )
1202+ }
1203+
11721204// return ENI id, error
11731205func (cache * EC2InstanceMetadataCache ) createENI (ctx context.Context , sg []* string , eniCfgSubnet string , numIPs int ) (string , error ) {
11741206 eniDescription := eniDescriptionPrefix + cache .instanceID
@@ -1798,8 +1830,13 @@ func (cache *EC2InstanceMetadataCache) DescribeAllENIs(ctx context.Context) (Des
17981830 // Validate that Attachment is populated by EC2 response before logging
17991831 if attachment != nil {
18001832 log .Infof ("Got network card index %v for ENI %v" , aws .ToInt32 (attachment .NetworkCardIndex ), eniID )
1801- if aws .ToInt32 (attachment .DeviceIndex ) == 0 && aws .ToInt32 (attachment .NetworkCardIndex ) == 0 && ! aws .ToBool (attachment .DeleteOnTermination ) {
1802- log .Warn ("Primary ENI will not get deleted when node terminates because 'delete_on_termination' is set to false" )
1833+ if aws .ToInt32 (attachment .DeviceIndex ) == 0 && aws .ToInt32 (attachment .NetworkCardIndex ) == 0 {
1834+ // Check if DeleteOnTermination is set for Primary ENI
1835+ if ! aws .ToBool (attachment .DeleteOnTermination ) {
1836+ log .Warn ("Primary ENI will not get deleted when node terminates because 'delete_on_termination' is set to false" )
1837+ }
1838+ // Set Connection Tracking settings from Primary ENI
1839+ cache .setConnectionTrackingSettings (ec2res .ConnectionTrackingConfiguration )
18031840 }
18041841 enisByNetworkCard [int (aws .ToInt32 (attachment .NetworkCardIndex ))] = append (enisByNetworkCard [int (aws .ToInt32 (attachment .NetworkCardIndex ))], eniID )
18051842 // Network Card where EFA-only ENI is attached
0 commit comments