Skip to content

Commit

Permalink
Merge pull request #1447 from aaroniscode/eip_events
Browse files Browse the repository at this point in the history
馃悰 Create events for Elastic IP allocate/disassociate/release
  • Loading branch information
k8s-ci-robot committed Dec 30, 2019
2 parents 49faafe + f097949 commit 77ed730
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/cloud/services/ec2/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/filter"
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/services/wait"
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/tags"
"sigs.k8s.io/cluster-api-provider-aws/pkg/record"
)

func (s *Service) getOrAllocateAddress(role string) (string, error) {
Expand All @@ -51,7 +52,8 @@ func (s *Service) allocateAddress(role string) (string, error) {
})

if err != nil {
return "", errors.Wrap(err, "failed to create Elastic IP address")
record.Warnf(s.scope.AWSCluster, "FailedAllocateEIP", "Failed to allocate Elastic IP for %q: %v", role, err)
return "", errors.Wrap(err, "failed to allocate Elastic IP")
}

if err := wait.WaitForWithRetryable(wait.NewBackoff(), func() (bool, error) {
Expand All @@ -70,7 +72,7 @@ func (s *Service) allocateAddress(role string) (string, error) {
}
return true, nil
}, awserrors.EIPNotFound); err != nil {
return "", errors.Wrapf(err, "failed to tag elastic IP %q", aws.StringValue(out.AllocationId))
return "", errors.Wrapf(err, "failed to tag Elastic IP %q", aws.StringValue(out.AllocationId))
}

return aws.StringValue(out.AllocationId), nil
Expand Down Expand Up @@ -101,7 +103,8 @@ func (s *Service) disassociateAddress(ip *ec2.Address) error {
return true, nil
}, awserrors.AuthFailure)
if err != nil {
return errors.Wrapf(err, "failed to disassociate ElasticIP %q", *ip.AllocationId)
record.Warnf(s.scope.AWSCluster, "FailedDisassociateEIP", "Failed to disassociate Elastic IP %q: %v", *ip.AllocationId, err)
return errors.Wrapf(err, "failed to disassociate Elastic IP %q", *ip.AllocationId)
}
return nil
}
Expand All @@ -121,7 +124,8 @@ func (s *Service) releaseAddresses() error {
AssociationId: ip.AssociationId,
})
if err != nil {
return errors.Errorf("failed to release elastic IP %q with allocation ID %q: Still associated with association ID %q", *ip.PublicIp, *ip.AllocationId, *ip.AssociationId)
record.Warnf(s.scope.AWSCluster, "FailedDisassociateEIP", "Failed to disassociate Elastic IP %q: %v", *ip.AllocationId, err)
return errors.Errorf("failed to disassociate Elastic IP %q with allocation ID %q: Still associated with association ID %q", *ip.PublicIp, *ip.AllocationId, *ip.AssociationId)
}
}

Expand All @@ -139,6 +143,7 @@ func (s *Service) releaseAddresses() error {
return true, nil
}, awserrors.AuthFailure, awserrors.InUseIPAddress)
if err != nil {
record.Warnf(s.scope.AWSCluster, "FailedReleaseEIP", "Failed to disassociate Elastic IP %q: %v", *ip.AllocationId, err)
return errors.Wrapf(err, "failed to release ElasticIP %q", *ip.AllocationId)
}

Expand Down

0 comments on commit 77ed730

Please sign in to comment.