@@ -133,7 +133,7 @@ func (ic *IbmCloudClient) Create(ctx context.Context, cluster *clusterv1.Cluster
133
133
return fmt .Errorf ("Guest %s does not exist after created in cluster %s" , machine .Name , cluster .Name )
134
134
}
135
135
136
- return ic .updateAnnotation (machine , strconv .Itoa (* guest .Id ))
136
+ return ic .updateMachine (machine , strconv .Itoa (* guest .Id ))
137
137
}
138
138
139
139
// 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
176
176
return false , err
177
177
}
178
178
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
+
179
186
return guest != nil , nil
180
187
}
181
188
@@ -205,7 +212,7 @@ func (ic *IbmCloudClient) getIP(machine *clusterv1.Machine) (string, error) {
205
212
return * guest .PrimaryIpAddress , nil
206
213
}
207
214
208
- func (ic * IbmCloudClient ) updateAnnotation (machine * clusterv1.Machine , id string ) error {
215
+ func (ic * IbmCloudClient ) updateMachine (machine * clusterv1.Machine , id string ) error {
209
216
if machine .ObjectMeta .Annotations == nil {
210
217
machine .ObjectMeta .Annotations = make (map [string ]string )
211
218
}
@@ -217,6 +224,11 @@ func (ic *IbmCloudClient) updateAnnotation(machine *clusterv1.Machine, id string
217
224
}
218
225
machine .ObjectMeta .Annotations [ibmcloud .IBMCloudIPAnnotationKey ] = ip
219
226
227
+ if machine .Spec .ProviderID == nil || * machine .Spec .ProviderID == "" {
228
+ providerID := fmt .Sprintf ("ibmcloud:////%s" , id )
229
+ machine .Spec .ProviderID = & providerID
230
+ }
231
+
220
232
if err := ic .params .Client .Update (nil , machine ); err != nil {
221
233
return err
222
234
}
0 commit comments