4
4
"context"
5
5
"errors"
6
6
"fmt"
7
+ "strings"
7
8
"sync"
8
9
"time"
9
10
@@ -168,12 +169,19 @@ func (i *Instances) InstanceExists(ctx context.Context, node *v1.Node) (bool, er
168
169
169
170
func (i * Instances ) InstanceMetadata (ctx context.Context , node * v1.Node ) (* cloudprovider.InstanceMetadata , error ) {
170
171
klog .Infof ("Get Instance Metadata for (%v)" , node .Name )
171
- currInstance , responseBody , err := i .apiClient .GetInstanceByID (ctx , getInstanceIDFromProviderID (node .Spec .ProviderID ))
172
+ prefixedProviderID , err := getProviderID (ctx , node , i )
173
+ if err != nil {
174
+ klog .Errorf ("could not get provider ID from Crusoe Cloud %v" , err )
175
+
176
+ return nil , err
177
+ }
178
+ providerID := getInstanceIDFromProviderID (prefixedProviderID )
179
+ currInstance , responseBody , err := i .apiClient .GetInstanceByID (ctx , providerID )
172
180
if responseBody != nil {
173
181
defer responseBody .Body .Close ()
174
182
}
175
183
if err != nil {
176
- return nil , fmt .Errorf ("failed to get instance by ID %s: %w" , node . Spec . ProviderID , err )
184
+ return nil , fmt .Errorf ("failed to get instance by ID %s: %w" , providerID , err )
177
185
}
178
186
klog .Infof ("InstanceMetadata for (%v:%v)" , node .Name , currInstance )
179
187
nodeAddress , err := getNodeAddress (currInstance )
@@ -218,6 +226,17 @@ func NewCrusoeInstances(c client.APIClient) *Instances {
218
226
219
227
func getProviderID (ctx context.Context , node * v1.Node , i * Instances ) (string , error ) {
220
228
providerID := node .Spec .ProviderID
229
+ // While kubelet does not update the node.spec or the node.status.addresses or metadata fields when
230
+ // node information changes it is still able to update the nodeInfo field in node.status. Kubelet updates
231
+ // node.Status.NodeInfo.SystemUUID to /sys/class/dmi/id/product_uuid which is the correct VM ID in Crusoe Cloud
232
+ if node .Status .NodeInfo .SystemUUID != "" &&
233
+ getInstanceIDFromProviderID (node .Spec .ProviderID ) != node .Status .NodeInfo .SystemUUID {
234
+
235
+ klog .Warningf ("ProviderID and SystemUUID do not match; providerID: " +
236
+ "%s; systemUUID: %s. Fetching UUID from Crusoe Cloud directly." ,
237
+ providerID , node .Status .NodeInfo .SystemUUID )
238
+ providerID = ""
239
+ }
221
240
if providerID == "" {
222
241
currInstance , err := i .apiClient .GetInstanceByName (ctx , node .Name )
223
242
if err != nil {
@@ -230,7 +249,7 @@ func getProviderID(ctx context.Context, node *v1.Node, i *Instances) (string, er
230
249
}
231
250
232
251
func getInstanceIDFromProviderID (providerID string ) string {
233
- return providerID [ len ( ProviderPrefix ):]
252
+ return strings . TrimPrefix ( providerID , ProviderPrefix )
234
253
}
235
254
236
255
func getNodeAddress (currInstance * crusoeapi.InstanceV1Alpha5 ) ([]v1.NodeAddress , error ) {
@@ -243,7 +262,7 @@ func getNodeAddress(currInstance *crusoeapi.InstanceV1Alpha5) ([]v1.NodeAddress,
243
262
Address : currInstance .NetworkInterfaces [0 ].Ips [0 ].PublicIpv4 .Address ,
244
263
}, v1.NodeAddress {
245
264
Type : v1 .NodeHostName ,
246
- Address : currInstance .Name ,
265
+ Address : fmt . Sprintf ( "%s.%s.compute.internal" , currInstance .Name , currInstance . Location ) ,
247
266
},
248
267
)
249
268
0 commit comments