Skip to content

Commit

Permalink
remove context from google create/destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Mar 25, 2022
1 parent 62bd73b commit 4547d56
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions drivers/google/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func (p *provider) Create(ctx context.Context, opts autoscaler.InstanceCreateOpt
}

name := strings.ToLower(opts.Name)

// select random zone from the list
zone := p.zones[rand.Intn(len(p.zones))]

logger := logger.FromContext(ctx).
WithField("zone", zone).
WithField("image", p.image).
Expand Down Expand Up @@ -106,7 +106,7 @@ func (p *provider) Create(ctx context.Context, opts autoscaler.InstanceCreateOpt
},
}

op, err := p.service.Instances.Insert(p.project, zone, in).Context(ctx).Do()
op, err := p.service.Instances.Insert(p.project, zone, in).Do()
if err != nil {
logger.WithError(err).
Errorln("instance insert failed")
Expand Down
2 changes: 1 addition & 1 deletion drivers/google/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func (p *provider) Destroy(ctx context.Context, instance *autoscaler.Instance) error {
// An instance's Region is actually a Zone in the google provider
op, err := p.service.Instances.Delete(p.project, instance.Region, instance.ID).Context(ctx).Do()
op, err := p.service.Instances.Delete(p.project, instance.Region, instance.ID).Do()
if err != nil {
// https://github.com/googleapis/google-api-go-client/blob/master/googleapi/googleapi.go#L135
if gerr, ok := err.(*googleapi.Error); ok &&
Expand Down
7 changes: 4 additions & 3 deletions engine/pinger.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ func (p *pinger) ping(ctx context.Context, server *autoscaler.Server) error {
for i := 0; i < 5; i++ {
logger.Debugln("pinging the server")

// TODO should this be moved outside of the loop
timeout, cancel := context.WithTimeout(nocontext, time.Minute)
_, err := client.Ping(timeout)
cancel()
if err == nil {
defer cancel()

if _, err := client.Ping(timeout); err == nil {
logger.WithField("state", "healthy").
Debugln("server ping successful")
return nil
Expand Down

0 comments on commit 4547d56

Please sign in to comment.