Skip to content

Commit

Permalink
Merge pull request #2475 from DataDog/JulienBalestra/ca-gcp-tests
Browse files Browse the repository at this point in the history
cluster-autoscaler/gce: create a test for an instance with unknown mig
  • Loading branch information
k8s-ci-robot authored Nov 4, 2019
2 parents 0690933 + 8745965 commit cc7a214
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions cluster-autoscaler/cloudprovider/gce/gce_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,10 @@ func newTestGceManager(t *testing.T, testServerURL string, regional bool) *gceMa
gceService.operationPollInterval = 1 * time.Millisecond

cache := &GceCache{
migs: make(map[GceRef]Mig),
GceService: gceService,
instanceRefToMigRef: make(map[GceRef]GceRef),
migs: make(map[GceRef]Mig),
GceService: gceService,
instanceRefToMigRef: make(map[GceRef]GceRef),
instancesFromUnknownMigs: make(map[GceRef]struct{}),
machinesCache: map[MachineTypeKey]*gce.MachineType{
{"us-central1-b", "n1-standard-1"}: {GuestCpus: 1, MemoryMb: 1},
{"us-central1-c", "n1-standard-1"}: {GuestCpus: 1, MemoryMb: 1},
Expand Down Expand Up @@ -680,17 +681,29 @@ func TestGetMigForInstance(t *testing.T) {
g.cache.InvalidateAllMigBasenames()

server.On("handle", "/project1/zones/us-central1-b/instanceGroupManagers/gke-cluster-1-default-pool").Return(buildDefaultInstanceGroupManagerResponse(zoneB)).Once()
server.On("handle", "/project1/zones/us-central1-b/instanceGroupManagers/gke-cluster-1-default-pool/listManagedInstances").Return(buildFourRunningInstancesOnDefaultMigManagedInstancesResponse(zoneB)).Once()
gceRef := GceRef{
server.On("handle", "/project1/zones/us-central1-b/instanceGroupManagers/gke-cluster-1-default-pool/listManagedInstances").Return(buildFourRunningInstancesOnDefaultMigManagedInstancesResponse(zoneB)).Twice()
gceRef1 := GceRef{
Project: projectId,
Zone: zoneB,
Name: "gke-cluster-1-default-pool-f7607aac-f1hm",
}

mig, err := g.GetMigForInstance(gceRef)
mig, err := g.GetMigForInstance(gceRef1)
assert.NoError(t, err)
assert.NotNil(t, mig)
assert.Equal(t, "gke-cluster-1-default-pool", mig.GceRef().Name)

gceRef2 := GceRef{
Project: projectId,
Zone: zoneB,
Name: "gke-cluster-1-default-pool-f7607aac-0000", // instance from unknown MIG
}
mig, err = g.GetMigForInstance(gceRef2)
assert.NoError(t, err)
assert.Nil(t, mig)
_, found := g.cache.instancesFromUnknownMigs[gceRef2]
assert.True(t, found)

mock.AssertExpectationsForObjects(t, server)
}

Expand Down

0 comments on commit cc7a214

Please sign in to comment.