@@ -172,7 +172,6 @@ func (service *HTTPRestService) SyncHostNCVersion(ctx context.Context, channelMo
172172 service .Lock ()
173173 defer service .Unlock ()
174174 start := time .Now ()
175-
176175 programmedNCCount , err := service .syncHostNCVersion (ctx , channelMode )
177176 // even if we get an error, we want to write the CNI conflist if we have any NC programmed to any version
178177 if programmedNCCount > 0 {
@@ -208,7 +207,7 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
208207 logger .Errorf ("Received err when change nc version %s in containerstatus to int, err msg %v" , service .state .ContainerStatus [idx ].CreateNetworkContainerRequest .Version , err )
209208 continue
210209 }
211- logger . Printf ( "NC %s: local NC version %d, DNC NC version %d" , service . state . ContainerStatus [ idx ]. ID , localNCVersion , dncNCVersion )
210+
212211 // host NC version is the NC version from NMAgent, if it's smaller than NC version from DNC, then append it to indicate it needs update.
213212 if localNCVersion < dncNCVersion {
214213 outdatedNCs [service .state .ContainerStatus [idx ].ID ] = struct {}{}
@@ -223,7 +222,7 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
223222 if len (outdatedNCs ) == 0 {
224223 return len (programmedNCs ), nil
225224 }
226- logger . Printf ( "outdatedNCs: %v" , outdatedNCs )
225+
227226 ncVersionListResp , err := service .nma .GetNCVersionList (ctx )
228227 if err != nil {
229228 return len (programmedNCs ), errors .Wrap (err , "failed to get nc version list from nmagent" )
@@ -232,7 +231,6 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
232231 // Get IMDS NC versions for delegated NIC scenarios
233232 imdsNCVersions , err := service .GetIMDSNCVersions (ctx )
234233 if err != nil {
235- logger .Printf ("Failed to get NC versions from IMDS: %v" , err )
236234 // If any of the NMA API check calls, imds calls fails assume that nma build doesn't have the latest changes and create empty map
237235 imdsNCVersions = make (map [string ]string )
238236 }
@@ -249,7 +247,7 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
249247 }
250248 for ncID , version := range imdsNCVersions {
251249 if _ , exists := consolidatedNCs [ncID ]; ! exists {
252- consolidatedNCs [ncID ] = version
250+ consolidatedNCs [strings . ToLower ( ncID ) ] = version
253251 }
254252 }
255253 hasNC .Set (float64 (len (consolidatedNCs )))
@@ -298,7 +296,7 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
298296 // if we didn't empty out the needs update set, NMA has not programmed all the NCs we are expecting, and we
299297 // need to return an error indicating that
300298 if len (outdatedNCs ) > 0 {
301- return len (programmedNCs ), errors .Errorf ("unabled to update some NCs: %v, missing or bad response from NMA or ipam " , outdatedNCs )
299+ return len (programmedNCs ), errors .Errorf ("unable to update some NCs: %v, missing or bad response from NMA or IMDS " , outdatedNCs )
302300 }
303301
304302 return len (programmedNCs ), nil
@@ -359,7 +357,6 @@ func (service *HTTPRestService) ReconcileIPAssignment(podInfoByIP map[string]cns
359357
360358 for _ , ip := range ips {
361359 if ncReq , ok := allSecIPsIdx [ip .String ()]; ok {
362- logger .Printf ("secondary ip %s is assigned to pod %+v, ncId: %s ncVersion: %s" , ip , podIPs , ncReq .NetworkContainerid , ncReq .Version )
363360 desiredIPs = append (desiredIPs , ip .String ())
364361 ncIDs = append (ncIDs , ncReq .NetworkContainerid )
365362 } else {
@@ -388,7 +385,7 @@ func (service *HTTPRestService) ReconcileIPAssignment(podInfoByIP map[string]cns
388385 }
389386
390387 if _ , err := requestIPConfigsHelper (service , ipconfigsRequest ); err != nil {
391- logger .Errorf ("requestIPConfigsHelper failed for pod key %s, podInfo %+v, ncIds %v, error: %v" , podKey , podIPs , ncIDs , err )
388+ logger .Errorf ("requestIPConfigsHelper failed for pod key %s, podInfo %+v, ncIDs %v, error: %v" , podKey , podIPs , ncIDs , err )
392389 return types .FailedToAllocateIPConfig
393390 }
394391 }
@@ -666,54 +663,51 @@ func (service *HTTPRestService) SetVFForAccelnetNICs() error {
666663func (service * HTTPRestService ) checkNMAgentAPISupport (ctx context.Context ) (swiftV2Support bool , err error ) {
667664 // Use the existing NMAgent client instead of direct HTTP calls
668665 if service .nma == nil {
669- return false , fmt . Errorf ("NMAgent client is not available" )
666+ return false , errors . New ("NMAgent client is not available" )
670667 }
671668
672669 apis , err := service .nma .SupportedAPIs (ctx )
673670 if err != nil {
674- return false , fmt .Errorf ("failed to get supported APIs from NMAgent client: %w" , err )
671+ logger .Errorf ("failed to get supported APIs from NMAgent client: %v" , err )
672+ return false , errors .New ("failed to get supported APIs from NMAgent client" )
675673 }
676674
677- logger .Printf ("[checkNMAgentAPISupport] Found %d APIs from NMAgent client" , len (apis ))
678- for i , api := range apis {
679- logger .Printf ("[checkNMAgentAPISupport] API %d: %s" , i + 1 , api )
680-
681- if strings .Contains (api , nmAgentSwiftV2API ) { // change
675+ for _ , api := range apis {
676+ if strings .Contains (api , nmAgentSwiftV2API ) {
682677 swiftV2Support = true
683678 }
684679 }
685680
686- logger .Printf ("[checkNMAgentAPISupport] Support check - SwiftV2: %t" , swiftV2Support )
687681 return swiftV2Support , nil
688682}
689683
690684// GetIMDSNCVersions gets NC versions from IMDS and returns them as a map
691685func (service * HTTPRestService ) GetIMDSNCVersions (ctx context.Context ) (map [string ]string , error ) {
692- logger .Printf ("[GetIMDSNCVersions] Getting NC versions from IMDS" )
693-
694686 // Check NMAgent API support for SwiftV2, if it fails return empty map assuming support might not be available in that nma build
695687 swiftV2Support , err := service .checkNMAgentAPISupport (ctx )
696- if err != nil {
697- logger .Printf ("[GetIMDSNCVersions] Failed to check NMAgent API support, returning empty map: %v" , err )
698- return make (map [string ]string ), nil
699- }
700-
701- if ! swiftV2Support {
702- logger .Printf ("[GetIMDSNCVersions] SwiftV2 API not supported, returning empty NC versions map" )
688+ if err != nil || ! swiftV2Support {
703689 return make (map [string ]string ), nil
704690 }
705691
706- logger .Printf ("[GetIMDSNCVersions] SwiftV2 support API exists (%t), proceeding to get NC versions from IMDS" , swiftV2Support )
707-
708692 imdsClient := service .imdsClient
709693
710694 // Get all NC versions from IMDS
711- ncVersions , err := imdsClient .GetNCVersionsFromIMDS (ctx )
695+ networkInterfaces , err := imdsClient .GetNCVersions (ctx )
712696 if err != nil {
713- logger .Printf ("[GetIMDSNCVersions] Failed to get NC versions from IMDS: %v" , err )
714697 return make (map [string ]string ), nil
715698 }
716699
717- logger .Printf ("[GetIMDSNCVersions] Successfully got %d NC versions from IMDS" , len (ncVersions ))
700+ // Build ncVersions map from the network interfaces
701+ ncVersions := make (map [string ]string )
702+ for _ , iface := range networkInterfaces {
703+ // IMDS returns interfaceCompartmentId, interfaceCompartmentVersion fields, as nc id guid has different context on nma. We map these to NC ID and NC version
704+ ncID := iface .InterfaceCompartmentId
705+ ncVersion := iface .InterfaceCompartmentVersion
706+
707+ if ncID != "" {
708+ ncVersions [ncID ] = ncVersion
709+ }
710+ }
711+
718712 return ncVersions , nil
719713}
0 commit comments