@@ -133,7 +133,7 @@ func (ic *IbmCloudClient) Create(ctx context.Context, cluster *clusterv1.Cluster
133133 return fmt .Errorf ("Guest %s does not exist after created in cluster %s" , machine .Name , cluster .Name )
134134 }
135135
136- return ic .updateAnnotation (machine , strconv .Itoa (* guest .Id ))
136+ return ic .updateMachine (machine , strconv .Itoa (* guest .Id ))
137137}
138138
139139// Delete deletes a machine and is invoked by the Machine Controller
@@ -176,6 +176,13 @@ func (ic *IbmCloudClient) Exists(ctx context.Context, cluster *clusterv1.Cluster
176176 return false , err
177177 }
178178
179+ if (guest != nil ) && (machine .Spec .ProviderID == nil || * machine .Spec .ProviderID == "" ) {
180+ // TODO(xunpan): this does not work in ibm cloud
181+ // check why related providers only set it in Exists but not update resource works
182+ providerID := fmt .Sprintf ("ibmcloud:////%d" , * guest .Id )
183+ machine .Spec .ProviderID = & providerID
184+ }
185+
179186 return guest != nil , nil
180187}
181188
@@ -205,7 +212,7 @@ func (ic *IbmCloudClient) getIP(machine *clusterv1.Machine) (string, error) {
205212 return * guest .PrimaryIpAddress , nil
206213}
207214
208- func (ic * IbmCloudClient ) updateAnnotation (machine * clusterv1.Machine , id string ) error {
215+ func (ic * IbmCloudClient ) updateMachine (machine * clusterv1.Machine , id string ) error {
209216 if machine .ObjectMeta .Annotations == nil {
210217 machine .ObjectMeta .Annotations = make (map [string ]string )
211218 }
@@ -217,6 +224,11 @@ func (ic *IbmCloudClient) updateAnnotation(machine *clusterv1.Machine, id string
217224 }
218225 machine .ObjectMeta .Annotations [ibmcloud .IBMCloudIPAnnotationKey ] = ip
219226
227+ if machine .Spec .ProviderID == nil || * machine .Spec .ProviderID == "" {
228+ providerID := fmt .Sprintf ("ibmcloud:////%s" , id )
229+ machine .Spec .ProviderID = & providerID
230+ }
231+
220232 if err := ic .params .Client .Update (nil , machine ); err != nil {
221233 return err
222234 }
0 commit comments