Skip to content

Commit f22c4b0

Browse files
authored
Merge branch 'kubernetes:master' into fix-deleteNodesFromCloudProvider-panic
2 parents 476b524 + ed6ebbe commit f22c4b0

27 files changed

+1631
-194
lines changed

cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ var (
8888
}
8989
)
9090

91+
// GceInstance extends cloudprovider.Instance with GCE specific numeric id.
92+
type GceInstance struct {
93+
cloudprovider.Instance
94+
NumericId uint64
95+
}
96+
9197
// AutoscalingGceClient is used for communicating with GCE API.
9298
type AutoscalingGceClient interface {
9399
// reading resources
@@ -96,7 +102,7 @@ type AutoscalingGceClient interface {
96102
FetchAllMigs(zone string) ([]*gce.InstanceGroupManager, error)
97103
FetchMigTargetSize(GceRef) (int64, error)
98104
FetchMigBasename(GceRef) (string, error)
99-
FetchMigInstances(GceRef) ([]cloudprovider.Instance, error)
105+
FetchMigInstances(GceRef) ([]GceInstance, error)
100106
FetchMigTemplateName(migRef GceRef) (string, error)
101107
FetchMigTemplate(migRef GceRef, templateName string) (*gce.InstanceTemplate, error)
102108
FetchMigsWithName(zone string, filter *regexp.Regexp) ([]string, error)
@@ -306,7 +312,7 @@ func (client *autoscalingGceClientV1) DeleteInstances(migRef GceRef, instances [
306312
return client.waitForOp(op, migRef.Project, migRef.Zone, true)
307313
}
308314

309-
func (client *autoscalingGceClientV1) FetchMigInstances(migRef GceRef) ([]cloudprovider.Instance, error) {
315+
func (client *autoscalingGceClientV1) FetchMigInstances(migRef GceRef) ([]GceInstance, error) {
310316
registerRequest("instance_group_managers", "list_managed_instances")
311317
b := newInstanceListBuilder(migRef)
312318
err := client.gceService.InstanceGroupManagers.ListManagedInstances(migRef.Project, migRef.Zone, migRef.Name).Pages(context.Background(), b.loadPage)
@@ -321,7 +327,7 @@ type instanceListBuilder struct {
321327
migRef GceRef
322328
errorCodeCounts map[string]int
323329
errorLoggingQuota *klogx.Quota
324-
infos []cloudprovider.Instance
330+
infos []GceInstance
325331
}
326332

327333
func newInstanceListBuilder(migRef GceRef) *instanceListBuilder {
@@ -334,7 +340,7 @@ func newInstanceListBuilder(migRef GceRef) *instanceListBuilder {
334340

335341
func (i *instanceListBuilder) loadPage(page *gce.InstanceGroupManagersListManagedInstancesResponse) error {
336342
if i.infos == nil {
337-
i.infos = make([]cloudprovider.Instance, 0, len(page.ManagedInstances))
343+
i.infos = make([]GceInstance, 0, len(page.ManagedInstances))
338344
}
339345
for _, gceInstance := range page.ManagedInstances {
340346
ref, err := ParseInstanceUrlRef(gceInstance.Instance)
@@ -348,12 +354,15 @@ func (i *instanceListBuilder) loadPage(page *gce.InstanceGroupManagersListManage
348354
return nil
349355
}
350356

351-
func (i *instanceListBuilder) gceInstanceToInstance(ref GceRef, gceInstance *gce.ManagedInstance) cloudprovider.Instance {
352-
instance := cloudprovider.Instance{
353-
Id: ref.ToProviderId(),
354-
Status: &cloudprovider.InstanceStatus{
355-
State: getInstanceState(gceInstance.CurrentAction),
357+
func (i *instanceListBuilder) gceInstanceToInstance(ref GceRef, gceInstance *gce.ManagedInstance) GceInstance {
358+
instance := GceInstance{
359+
Instance: cloudprovider.Instance{
360+
Id: ref.ToProviderId(),
361+
Status: &cloudprovider.InstanceStatus{
362+
State: getInstanceState(gceInstance.CurrentAction),
363+
},
356364
},
365+
NumericId: gceInstance.Id,
357366
}
358367

359368
if instance.Status.State != cloudprovider.InstanceCreating {
@@ -395,7 +404,7 @@ func (i *instanceListBuilder) gceInstanceToInstance(ref GceRef, gceInstance *gce
395404
return instance
396405
}
397406

398-
func (i *instanceListBuilder) build() []cloudprovider.Instance {
407+
func (i *instanceListBuilder) build() []GceInstance {
399408
klogx.V(4).Over(i.errorLoggingQuota).Infof("Got %v other GCE instances being created with lastAttemptErrors", -i.errorLoggingQuota.Left())
400409
if len(i.errorCodeCounts) > 0 {
401410
klog.Warningf("Spotted following instance creation error codes: %#v", i.errorCodeCounts)

cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client_test.go

Lines changed: 91 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -237,20 +237,22 @@ func TestFetchMigInstancesInstanceUrlHandling(t *testing.T) {
237237
name string
238238
lmiResponse gce_api.InstanceGroupManagersListManagedInstancesResponse
239239
lmiPageResponses map[string]gce_api.InstanceGroupManagersListManagedInstancesResponse
240-
wantInstances []cloudprovider.Instance
240+
wantInstances []GceInstance
241241
}{
242242
{
243243
name: "all instances good",
244244
lmiResponse: gce_api.InstanceGroupManagersListManagedInstancesResponse{
245245
ManagedInstances: []*gce_api.ManagedInstance{
246246
{
247+
Id: 2,
247248
Instance: fmt.Sprintf(goodInstanceUrlTempl, 2),
248249
CurrentAction: "CREATING",
249250
LastAttempt: &gce_api.ManagedInstanceLastAttempt{
250251
Errors: &gce_api.ManagedInstanceLastAttemptErrors{},
251252
},
252253
},
253254
{
255+
Id: 42,
254256
Instance: fmt.Sprintf(goodInstanceUrlTempl, 42),
255257
CurrentAction: "CREATING",
256258
LastAttempt: &gce_api.ManagedInstanceLastAttempt{
@@ -259,14 +261,20 @@ func TestFetchMigInstancesInstanceUrlHandling(t *testing.T) {
259261
},
260262
},
261263
},
262-
wantInstances: []cloudprovider.Instance{
264+
wantInstances: []GceInstance{
263265
{
264-
Id: "gce://myprojid/myzone/myinst_2",
265-
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
266+
Instance: cloudprovider.Instance{
267+
Id: "gce://myprojid/myzone/myinst_2",
268+
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
269+
},
270+
NumericId: 2,
266271
},
267272
{
268-
Id: "gce://myprojid/myzone/myinst_42",
269-
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
273+
Instance: cloudprovider.Instance{
274+
Id: "gce://myprojid/myzone/myinst_42",
275+
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
276+
},
277+
NumericId: 42,
270278
},
271279
},
272280
},
@@ -275,13 +283,15 @@ func TestFetchMigInstancesInstanceUrlHandling(t *testing.T) {
275283
lmiResponse: gce_api.InstanceGroupManagersListManagedInstancesResponse{
276284
ManagedInstances: []*gce_api.ManagedInstance{
277285
{
286+
Id: 2,
278287
Instance: fmt.Sprintf(goodInstanceUrlTempl, 2),
279288
CurrentAction: "CREATING",
280289
LastAttempt: &gce_api.ManagedInstanceLastAttempt{
281290
Errors: &gce_api.ManagedInstanceLastAttemptErrors{},
282291
},
283292
},
284293
{
294+
Id: 42,
285295
Instance: fmt.Sprintf(goodInstanceUrlTempl, 42),
286296
CurrentAction: "CREATING",
287297
LastAttempt: &gce_api.ManagedInstanceLastAttempt{
@@ -295,13 +305,15 @@ func TestFetchMigInstancesInstanceUrlHandling(t *testing.T) {
295305
"foo": {
296306
ManagedInstances: []*gce_api.ManagedInstance{
297307
{
308+
Id: 123,
298309
Instance: fmt.Sprintf(goodInstanceUrlTempl, 123),
299310
CurrentAction: "CREATING",
300311
LastAttempt: &gce_api.ManagedInstanceLastAttempt{
301312
Errors: &gce_api.ManagedInstanceLastAttemptErrors{},
302313
},
303314
},
304315
{
316+
Id: 456,
305317
Instance: fmt.Sprintf(goodInstanceUrlTempl, 456),
306318
CurrentAction: "CREATING",
307319
LastAttempt: &gce_api.ManagedInstanceLastAttempt{
@@ -311,22 +323,34 @@ func TestFetchMigInstancesInstanceUrlHandling(t *testing.T) {
311323
},
312324
},
313325
},
314-
wantInstances: []cloudprovider.Instance{
326+
wantInstances: []GceInstance{
315327
{
316-
Id: "gce://myprojid/myzone/myinst_2",
317-
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
328+
Instance: cloudprovider.Instance{
329+
Id: "gce://myprojid/myzone/myinst_2",
330+
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
331+
},
332+
NumericId: 2,
318333
},
319334
{
320-
Id: "gce://myprojid/myzone/myinst_42",
321-
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
335+
Instance: cloudprovider.Instance{
336+
Id: "gce://myprojid/myzone/myinst_42",
337+
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
338+
},
339+
NumericId: 42,
322340
},
323341
{
324-
Id: "gce://myprojid/myzone/myinst_123",
325-
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
342+
Instance: cloudprovider.Instance{
343+
Id: "gce://myprojid/myzone/myinst_123",
344+
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
345+
},
346+
NumericId: 123,
326347
},
327348
{
328-
Id: "gce://myprojid/myzone/myinst_456",
329-
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
349+
Instance: cloudprovider.Instance{
350+
Id: "gce://myprojid/myzone/myinst_456",
351+
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
352+
},
353+
NumericId: 456,
330354
},
331355
},
332356
},
@@ -335,13 +359,15 @@ func TestFetchMigInstancesInstanceUrlHandling(t *testing.T) {
335359
lmiResponse: gce_api.InstanceGroupManagersListManagedInstancesResponse{
336360
ManagedInstances: []*gce_api.ManagedInstance{
337361
{
362+
Id: 2,
338363
Instance: fmt.Sprintf(goodInstanceUrlTempl, 2),
339364
CurrentAction: "CREATING",
340365
LastAttempt: &gce_api.ManagedInstanceLastAttempt{
341366
Errors: &gce_api.ManagedInstanceLastAttemptErrors{},
342367
},
343368
},
344369
{
370+
Id: 42,
345371
Instance: fmt.Sprintf(goodInstanceUrlTempl, 42),
346372
CurrentAction: "CREATING",
347373
LastAttempt: &gce_api.ManagedInstanceLastAttempt{
@@ -355,13 +381,15 @@ func TestFetchMigInstancesInstanceUrlHandling(t *testing.T) {
355381
"foo": {
356382
ManagedInstances: []*gce_api.ManagedInstance{
357383
{
384+
Id: 123,
358385
Instance: fmt.Sprintf(goodInstanceUrlTempl, 123),
359386
CurrentAction: "CREATING",
360387
LastAttempt: &gce_api.ManagedInstanceLastAttempt{
361388
Errors: &gce_api.ManagedInstanceLastAttemptErrors{},
362389
},
363390
},
364391
{
392+
Id: 456,
365393
Instance: fmt.Sprintf(goodInstanceUrlTempl, 456),
366394
CurrentAction: "CREATING",
367395
LastAttempt: &gce_api.ManagedInstanceLastAttempt{
@@ -374,13 +402,15 @@ func TestFetchMigInstancesInstanceUrlHandling(t *testing.T) {
374402
"bar": {
375403
ManagedInstances: []*gce_api.ManagedInstance{
376404
{
405+
Id: 789,
377406
Instance: fmt.Sprintf(goodInstanceUrlTempl, 789),
378407
CurrentAction: "CREATING",
379408
LastAttempt: &gce_api.ManagedInstanceLastAttempt{
380409
Errors: &gce_api.ManagedInstanceLastAttemptErrors{},
381410
},
382411
},
383412
{
413+
Id: 666,
384414
Instance: fmt.Sprintf(goodInstanceUrlTempl, 666),
385415
CurrentAction: "CREATING",
386416
LastAttempt: &gce_api.ManagedInstanceLastAttempt{
@@ -390,30 +420,48 @@ func TestFetchMigInstancesInstanceUrlHandling(t *testing.T) {
390420
},
391421
},
392422
},
393-
wantInstances: []cloudprovider.Instance{
423+
wantInstances: []GceInstance{
394424
{
395-
Id: "gce://myprojid/myzone/myinst_2",
396-
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
425+
Instance: cloudprovider.Instance{
426+
Id: "gce://myprojid/myzone/myinst_2",
427+
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
428+
},
429+
NumericId: 2,
397430
},
398431
{
399-
Id: "gce://myprojid/myzone/myinst_42",
400-
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
432+
Instance: cloudprovider.Instance{
433+
Id: "gce://myprojid/myzone/myinst_42",
434+
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
435+
},
436+
NumericId: 42,
401437
},
402438
{
403-
Id: "gce://myprojid/myzone/myinst_123",
404-
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
439+
Instance: cloudprovider.Instance{
440+
Id: "gce://myprojid/myzone/myinst_123",
441+
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
442+
},
443+
NumericId: 123,
405444
},
406445
{
407-
Id: "gce://myprojid/myzone/myinst_456",
408-
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
446+
Instance: cloudprovider.Instance{
447+
Id: "gce://myprojid/myzone/myinst_456",
448+
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
449+
},
450+
NumericId: 456,
409451
},
410452
{
411-
Id: "gce://myprojid/myzone/myinst_789",
412-
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
453+
Instance: cloudprovider.Instance{
454+
Id: "gce://myprojid/myzone/myinst_789",
455+
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
456+
},
457+
NumericId: 789,
413458
},
414459
{
415-
Id: "gce://myprojid/myzone/myinst_666",
416-
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
460+
Instance: cloudprovider.Instance{
461+
Id: "gce://myprojid/myzone/myinst_666",
462+
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
463+
},
464+
NumericId: 666,
417465
},
418466
},
419467
},
@@ -422,13 +470,15 @@ func TestFetchMigInstancesInstanceUrlHandling(t *testing.T) {
422470
lmiResponse: gce_api.InstanceGroupManagersListManagedInstancesResponse{
423471
ManagedInstances: []*gce_api.ManagedInstance{
424472
{
473+
Id: 99999,
425474
Instance: badInstanceUrl,
426475
CurrentAction: "CREATING",
427476
LastAttempt: &gce_api.ManagedInstanceLastAttempt{
428477
Errors: &gce_api.ManagedInstanceLastAttemptErrors{},
429478
},
430479
},
431480
{
481+
Id: 42,
432482
Instance: fmt.Sprintf(goodInstanceUrlTempl, 42),
433483
CurrentAction: "CREATING",
434484
LastAttempt: &gce_api.ManagedInstanceLastAttempt{
@@ -437,10 +487,13 @@ func TestFetchMigInstancesInstanceUrlHandling(t *testing.T) {
437487
},
438488
},
439489
},
440-
wantInstances: []cloudprovider.Instance{
490+
wantInstances: []GceInstance{
441491
{
442-
Id: "gce://myprojid/myzone/myinst_42",
443-
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
492+
Instance: cloudprovider.Instance{
493+
Id: "gce://myprojid/myzone/myinst_42",
494+
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
495+
},
496+
NumericId: 42,
444497
},
445498
},
446499
},
@@ -456,6 +509,7 @@ func TestFetchMigInstancesInstanceUrlHandling(t *testing.T) {
456509
},
457510
},
458511
{
512+
Id: 42,
459513
Instance: fmt.Sprintf(goodInstanceUrlTempl, 42),
460514
CurrentAction: "CREATING",
461515
LastAttempt: &gce_api.ManagedInstanceLastAttempt{
@@ -464,10 +518,13 @@ func TestFetchMigInstancesInstanceUrlHandling(t *testing.T) {
464518
},
465519
},
466520
},
467-
wantInstances: []cloudprovider.Instance{
521+
wantInstances: []GceInstance{
468522
{
469-
Id: "gce://myprojid/myzone/myinst_42",
470-
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
523+
Instance: cloudprovider.Instance{
524+
Id: "gce://myprojid/myzone/myinst_42",
525+
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
526+
},
527+
NumericId: 42,
471528
},
472529
},
473530
},

0 commit comments

Comments
 (0)