Skip to content

Commit 4a1c810

Browse files
committed
GEN-1862 kloud: log each releaseEIP attempt
1 parent e7c00a7 commit 4a1c810

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

  • go/src/koding/kites/kloud/provider/koding

go/src/koding/kites/kloud/provider/koding/machine.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package koding
33
import (
44
"fmt"
55
"koding/db/models"
6+
"koding/kites/kloud/api/amazon"
67
"koding/kites/kloud/contexthelper/session"
78
"koding/kites/kloud/eventer"
89
"koding/kites/kloud/klient"
@@ -235,22 +236,35 @@ func (m *Machine) Unlock() error {
235236
func (m *Machine) releaseEIP() {
236237
// try to release/delete a public elastic IP, if there is an error we don't
237238
// care (the instance might not have an elastic IP, aka a free user.
238-
m.Log.Debug("Releasing attached public IP: %s", m.IpAddress)
239+
addrs, err := m.Session.AWSClient.AddressesByIP(m.IpAddress)
240+
if err != nil {
241+
if !amazon.IsNotFound(err) {
242+
m.Log.Warning("querying for %q Elastic IPs failed: %s", m.IpAddress, err)
243+
}
244+
return
245+
}
246+
247+
m.Log.Debug("releasing Elastic IPs (%d): %s", len(addrs), m.IpAddress)
239248

240-
if addrs, err := m.Session.AWSClient.AddressesByIP(m.IpAddress); err == nil {
241-
for _, addr := range addrs {
242-
m.Log.Debug("Got an elastic IP %+v. Going to relaease it", addr)
249+
for _, addr := range addrs {
250+
m.Log.Debug("Got an elastic IP %+v. Going to relaease it", addr)
251+
ip := aws.StringValue(addr.PublicIp)
243252

244-
assocID := aws.StringValue(addr.AssociationId)
245-
if assocID != "" {
246-
// if the instance is running, try to disassociate EIP from
247-
// the instance
248-
m.Session.AWSClient.DisassociateAddress(assocID)
253+
assocID := aws.StringValue(addr.AssociationId)
254+
if assocID != "" {
255+
// if the instance is running, try to disassociate EIP from
256+
// the instance
257+
err := m.Session.AWSClient.DisassociateAddress(assocID)
258+
if err != nil {
259+
m.Log.Warning("disassociating Elastic IP failed: ip=%s, assocID=%s, err=%s", ip, assocID, err)
249260
}
261+
}
250262

251-
allocID := aws.StringValue(addr.AllocationId)
252-
if allocID != "" {
253-
m.Session.AWSClient.ReleaseAddress(allocID)
263+
allocID := aws.StringValue(addr.AllocationId)
264+
if allocID != "" {
265+
err := m.Session.AWSClient.ReleaseAddress(allocID)
266+
if err != nil {
267+
m.Log.Warning("releasing Elastic IP failed: ip=%s, allocID=%s, err=%s", ip, allocID, err)
254268
}
255269
}
256270
}

0 commit comments

Comments
 (0)