@@ -537,6 +537,7 @@ func findFlattenClusterRegistrationToken(client *managementClient.Client, cluste
537537}
538538
539539func findClusterRegistrationToken (client * managementClient.Client , clusterID string ) (* managementClient.ClusterRegistrationToken , error ) {
540+ log .Printf ("[TRACE] Finding cluster registration token for %s" , clusterID )
540541 for i := range clusterRegistrationTokenNames {
541542 regTokenID := clusterID + ":" + clusterRegistrationTokenNames [i ]
542543 for retry , retries := 1 , 10 ; retry <= retries ; retry ++ {
@@ -545,25 +546,36 @@ func findClusterRegistrationToken(client *managementClient.Client, clusterID str
545546 if ! IsNotFound (err ) {
546547 return nil , err
547548 }
549+ log .Printf ("[TRACE] Cluster registration token %s not found for %s" , regTokenID , clusterID )
548550 break
549551 }
550552 if (len (regToken .Command ) > 0 && len (regToken .NodeCommand ) > 0 ) || retry == retries {
553+ log .Printf ("[INFO] Found existing cluster registration token for %s" , clusterID )
551554 return regToken , nil
552555 }
556+ log .Printf ("[DEBUG] Sleeping for 3 seconds before checking cluster registration token for %s" , clusterID )
553557 time .Sleep (3 * time .Second )
554558 }
555559 }
560+ log .Printf ("[TRACE] Cluster registration token not found for %s" , clusterID )
556561 return createClusterRegistrationToken (client , clusterID )
557562}
558563
559564func createClusterRegistrationToken (client * managementClient.Client , clusterID string ) (* managementClient.ClusterRegistrationToken , error ) {
565+ log .Printf ("[DEBUG] Creating cluster registration token for %s" , clusterID )
566+
560567 regToken , err := expandClusterRegistationToken ([]interface {}{}, clusterID )
561568 if err != nil {
562569 return nil , err
563570 }
564571
565572 newRegToken , err := client .ClusterRegistrationToken .Create (regToken )
566573 if err != nil {
574+ if IsConflict (err ) {
575+ log .Printf ("[INFO] Found existing cluster registration token for %s" , clusterID )
576+ regTokenID := clusterID + ":" + clusterRegistrationTokenName
577+ return client .ClusterRegistrationToken .ByID (regTokenID )
578+ }
567579 return nil , err
568580 }
569581
@@ -583,6 +595,7 @@ func createClusterRegistrationToken(client *managementClient.Client, clusterID s
583595 if err != nil {
584596 return nil , err
585597 }
598+ log .Printf ("[INFO] Created cluster registration token %s for %s" , newRegToken .ID , clusterID )
586599 return newRegToken , nil
587600}
588601
0 commit comments