@@ -259,9 +259,11 @@ func (h *Handler) UpdateStatus(ctx context.Context, nodeGUID string, status pb.U
259259 // IntelMachine for the node doesn't exist yet
260260 if intelmachine == nil {
261261 // unpause the cluster if paused
262- cluster , err := getCluster (ctx , h . client , projectId , nodeGUID )
262+ cluster , err := h . getCluster (ctx , projectId , nodeGUID )
263263 if cluster != nil && cluster .Spec .Paused {
264+ log .Debug ().Msgf ("Unpausing cluster %s/%s" , cluster .Namespace , cluster .Name )
264265 err = unpauseCluster (ctx , h .client , cluster )
266+ log .Debug ().Msgf ("Cluster unpause result: %v" , err )
265267 }
266268 return pb .UpdateClusterStatusResponse_NONE , err
267269 }
@@ -393,16 +395,31 @@ func (h *Handler) getIntelMachine(ctx context.Context, client ctrlclient.Client,
393395 return intelMachine , nil
394396}
395397
396- func getCluster (ctx context.Context , client ctrlclient. Client , projectId string , nodeID string ) (* clusterv1.Cluster , error ) {
398+ func ( h * Handler ) getCluster (ctx context.Context , projectId string , nodeID string ) (* clusterv1.Cluster , error ) {
397399 // see if there is machine binding for this node
398400 var machineBindingList infrastructurev1alpha1.IntelMachineBindingList
399401
400- if err := client .List (ctx , & machineBindingList ,
401- ctrlclient .InNamespace (projectId ),
402- ctrlclient.MatchingFields {nodeGUIDKey : nodeID }); err != nil {
402+ // TODO: always convert nodeID(GUID format) to hostID before search the cluster once host
403+ // unification from cluster-manager is done. For 3.2 release, try to get
404+ // hostID by UUID if no machine binding is found.
405+ if err := h .client .List (ctx , & machineBindingList , ctrlclient .InNamespace (projectId ), ctrlclient.MatchingFields {nodeGUIDKey : nodeID }); err != nil {
403406 return nil , fmt .Errorf ("failed to get intel machine binding list: %w" , err )
404407 }
405408
409+ if len (machineBindingList .Items ) == 0 && h .inventoryClient != nil {
410+ log .Debug ().Msgf ("No IntelMachineBinding found for node %s in project %s, attempt to get hostID by UUID" , nodeID , projectId )
411+ host , err := h .inventoryClient .Client .GetHostByUUID (ctx , projectId , nodeID )
412+ if err != nil {
413+ return nil , fmt .Errorf ("failed to get host resource by UUID: %w" , err )
414+ }
415+
416+ if err := h .client .List (ctx , & machineBindingList ,
417+ ctrlclient .InNamespace (projectId ),
418+ ctrlclient.MatchingFields {nodeGUIDKey : host .GetResourceId ()}); err != nil {
419+ return nil , fmt .Errorf ("failed to get intel machine binding list: %w" , err )
420+ }
421+ }
422+
406423 if len (machineBindingList .Items ) == 0 {
407424 // no cluster is available for this node
408425 return nil , nil
@@ -412,9 +429,10 @@ func getCluster(ctx context.Context, client ctrlclient.Client, projectId string,
412429 }
413430
414431 // one cluster is found for the node
432+ log .Debug ().Msgf ("Found cluster for node %s %s/%s" , nodeID , projectId , machineBindingList .Items [0 ].Spec .ClusterName )
415433 cluster := & clusterv1.Cluster {}
416434 key := types.NamespacedName {Namespace : projectId , Name : machineBindingList .Items [0 ].Spec .ClusterName }
417- if err := client .Get (ctx , key , cluster ); err != nil {
435+ if err := h . client .Get (ctx , key , cluster ); err != nil {
418436 return nil , err
419437 }
420438
0 commit comments