|
|
|
|
@ -707,7 +707,8 @@ var tagsEventualConsistencyErrors = map[string]bool{
|
|
|
|
|
"InvalidInternetGatewayID.NotFound": true,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// isTagsEventualConsistencyError checks if the error is one of the errors encountered when we try to create/get tags before the resource has fully 'propagated' in EC2
|
|
|
|
|
// isTagsEventualConsistencyError checks if the error is one of the errors encountered
|
|
|
|
|
// when we try to create/get tags before the resource has fully 'propagated' in EC2
|
|
|
|
|
func isTagsEventualConsistencyError(err error) bool {
|
|
|
|
|
if awsErr, ok := err.(awserr.Error); ok {
|
|
|
|
|
isEventualConsistency, found := tagsEventualConsistencyErrors[awsErr.Code()]
|
|
|
|
|
@ -720,21 +721,22 @@ func isTagsEventualConsistencyError(err error) bool {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetTags will fetch the tags for the specified resource, retrying (up to MaxDescribeTagsAttempts) if it hits an eventual-consistency type error
|
|
|
|
|
// GetTags will fetch the tags for the specified resource,
|
|
|
|
|
// retrying (up to MaxDescribeTagsAttempts) if it hits an eventual-consistency type error
|
|
|
|
|
func (c *awsCloudImplementation) GetTags(resourceID string) (map[string]string, error) {
|
|
|
|
|
return getTags(c, resourceID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getTags(c AWSCloud, resourceId string) (map[string]string, error) {
|
|
|
|
|
if resourceId == "" {
|
|
|
|
|
return nil, fmt.Errorf("resourceId not provided to getTags")
|
|
|
|
|
func getTags(c AWSCloud, resourceID string) (map[string]string, error) {
|
|
|
|
|
if resourceID == "" {
|
|
|
|
|
return nil, fmt.Errorf("resourceID not provided to getTags")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tags := map[string]string{}
|
|
|
|
|
|
|
|
|
|
request := &ec2.DescribeTagsInput{
|
|
|
|
|
Filters: []*ec2.Filter{
|
|
|
|
|
NewEC2Filter("resource-id", resourceId),
|
|
|
|
|
NewEC2Filter("resource-id", resourceID),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -746,19 +748,19 @@ func getTags(c AWSCloud, resourceId string) (map[string]string, error) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
if isTagsEventualConsistencyError(err) {
|
|
|
|
|
if attempt > DescribeTagsMaxAttempts {
|
|
|
|
|
return nil, fmt.Errorf("Got retryable error while getting tags on %q, but retried too many times without success: %v", resourceId, err)
|
|
|
|
|
return nil, fmt.Errorf("Got retryable error while getting tags on %q, but retried too many times without success: %v", resourceID, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (attempt % DescribeTagsLogInterval) == 0 {
|
|
|
|
|
klog.Infof("waiting for eventual consistency while describing tags on %q", resourceId)
|
|
|
|
|
klog.Infof("waiting for eventual consistency while describing tags on %q", resourceID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
klog.V(2).Infof("will retry after encountering error getting tags on %q: %v", resourceId, err)
|
|
|
|
|
klog.V(2).Infof("will retry after encountering error getting tags on %q: %v", resourceID, err)
|
|
|
|
|
time.Sleep(DescribeTagsRetryInterval)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("error listing tags on %v: %v", resourceId, err)
|
|
|
|
|
return nil, fmt.Errorf("error listing tags on %v: %v", resourceID, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tag := range response.Tags {
|
|
|
|
|
@ -774,11 +776,11 @@ func getTags(c AWSCloud, resourceId string) (map[string]string, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateTags will add tags to the specified resource, retrying up to MaxCreateTagsAttempts times if it hits an eventual-consistency type error
|
|
|
|
|
func (c *awsCloudImplementation) CreateTags(resourceId string, tags map[string]string) error {
|
|
|
|
|
return createTags(c, resourceId, tags)
|
|
|
|
|
func (c *awsCloudImplementation) CreateTags(resourceID string, tags map[string]string) error {
|
|
|
|
|
return createTags(c, resourceID, tags)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func createTags(c AWSCloud, resourceId string, tags map[string]string) error {
|
|
|
|
|
func createTags(c AWSCloud, resourceID string, tags map[string]string) error {
|
|
|
|
|
if len(tags) == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
@ -794,38 +796,39 @@ func createTags(c AWSCloud, resourceId string, tags map[string]string) error {
|
|
|
|
|
|
|
|
|
|
request := &ec2.CreateTagsInput{
|
|
|
|
|
Tags: ec2Tags,
|
|
|
|
|
Resources: []*string{&resourceId},
|
|
|
|
|
Resources: []*string{&resourceID},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.EC2().CreateTags(request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if isTagsEventualConsistencyError(err) {
|
|
|
|
|
if attempt > CreateTagsMaxAttempts {
|
|
|
|
|
return fmt.Errorf("Got retryable error while creating tags on %q, but retried too many times without success: %v", resourceId, err)
|
|
|
|
|
return fmt.Errorf("Got retryable error while creating tags on %q, but retried too many times without success: %v", resourceID, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (attempt % CreateTagsLogInterval) == 0 {
|
|
|
|
|
klog.Infof("waiting for eventual consistency while creating tags on %q", resourceId)
|
|
|
|
|
klog.Infof("waiting for eventual consistency while creating tags on %q", resourceID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
klog.V(2).Infof("will retry after encountering error creating tags on %q: %v", resourceId, err)
|
|
|
|
|
klog.V(2).Infof("will retry after encountering error creating tags on %q: %v", resourceID, err)
|
|
|
|
|
time.Sleep(CreateTagsRetryInterval)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fmt.Errorf("error creating tags on %v: %v", resourceId, err)
|
|
|
|
|
return fmt.Errorf("error creating tags on %v: %v", resourceID, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteTags will remove tags from the specified resource, retrying up to MaxCreateTagsAttempts times if it hits an eventual-consistency type error
|
|
|
|
|
func (c *awsCloudImplementation) DeleteTags(resourceId string, tags map[string]string) error {
|
|
|
|
|
return deleteTags(c, resourceId, tags)
|
|
|
|
|
// DeleteTags will remove tags from the specified resource,
|
|
|
|
|
// retrying up to MaxCreateTagsAttempts times if it hits an eventual-consistency type error
|
|
|
|
|
func (c *awsCloudImplementation) DeleteTags(resourceID string, tags map[string]string) error {
|
|
|
|
|
return deleteTags(c, resourceID, tags)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func deleteTags(c AWSCloud, resourceId string, tags map[string]string) error {
|
|
|
|
|
func deleteTags(c AWSCloud, resourceID string, tags map[string]string) error {
|
|
|
|
|
if len(tags) == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
@ -841,26 +844,26 @@ func deleteTags(c AWSCloud, resourceId string, tags map[string]string) error {
|
|
|
|
|
|
|
|
|
|
request := &ec2.DeleteTagsInput{
|
|
|
|
|
Tags: ec2Tags,
|
|
|
|
|
Resources: []*string{&resourceId},
|
|
|
|
|
Resources: []*string{&resourceID},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.EC2().DeleteTags(request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if isTagsEventualConsistencyError(err) {
|
|
|
|
|
if attempt > DeleteTagsMaxAttempts {
|
|
|
|
|
return fmt.Errorf("Got retryable error while deleting tags on %q, but retried too many times without success: %v", resourceId, err)
|
|
|
|
|
return fmt.Errorf("Got retryable error while deleting tags on %q, but retried too many times without success: %v", resourceID, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (attempt % DeleteTagsLogInterval) == 0 {
|
|
|
|
|
klog.Infof("waiting for eventual consistency while deleting tags on %q", resourceId)
|
|
|
|
|
klog.Infof("waiting for eventual consistency while deleting tags on %q", resourceID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
klog.V(2).Infof("will retry after encountering error deleting tags on %q: %v", resourceId, err)
|
|
|
|
|
klog.V(2).Infof("will retry after encountering error deleting tags on %q: %v", resourceID, err)
|
|
|
|
|
time.Sleep(DeleteTagsRetryInterval)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fmt.Errorf("error deleting tags on %v: %v", resourceId, err)
|
|
|
|
|
return fmt.Errorf("error deleting tags on %v: %v", resourceID, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
@ -908,27 +911,21 @@ func getELBTags(c AWSCloud, loadBalancerName string) (map[string]string, error)
|
|
|
|
|
request := &elb.DescribeTagsInput{
|
|
|
|
|
LoadBalancerNames: []*string{&loadBalancerName},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attempt := 0
|
|
|
|
|
for {
|
|
|
|
|
attempt++
|
|
|
|
|
|
|
|
|
|
response, err := c.ELB().DescribeTags(request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("error listing tags on %v: %v", loadBalancerName, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tagset := range response.TagDescriptions {
|
|
|
|
|
for _, tag := range tagset.Tags {
|
|
|
|
|
tags[aws.StringValue(tag.Key)] = aws.StringValue(tag.Value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tags, nil
|
|
|
|
|
response, err := c.ELB().DescribeTags(request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("error listing tags on %v: %v", loadBalancerName, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tagset := range response.TagDescriptions {
|
|
|
|
|
for _, tag := range tagset.Tags {
|
|
|
|
|
tags[aws.StringValue(tag.Key)] = aws.StringValue(tag.Value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return tags, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateELBTags will add tags to the specified loadBalancer, retrying up to MaxCreateTagsAttempts times if it hits an eventual-consistency type error
|
|
|
|
|
// CreateELBTags will add tags to the specified loadBalancer,
|
|
|
|
|
// retrying up to MaxCreateTagsAttempts times if it hits an eventual-consistency type error
|
|
|
|
|
func (c *awsCloudImplementation) CreateELBTags(loadBalancerName string, tags map[string]string) error {
|
|
|
|
|
return createELBTags(c, loadBalancerName, tags)
|
|
|
|
|
}
|
|
|
|
|
@ -943,22 +940,17 @@ func createELBTags(c AWSCloud, loadBalancerName string, tags map[string]string)
|
|
|
|
|
elbTags = append(elbTags, &elb.Tag{Key: aws.String(k), Value: aws.String(v)})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attempt := 0
|
|
|
|
|
for {
|
|
|
|
|
attempt++
|
|
|
|
|
|
|
|
|
|
request := &elb.AddTagsInput{
|
|
|
|
|
Tags: elbTags,
|
|
|
|
|
LoadBalancerNames: []*string{&loadBalancerName},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.ELB().AddTags(request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("error creating tags on %v: %v", loadBalancerName, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
request := &elb.AddTagsInput{
|
|
|
|
|
Tags: elbTags,
|
|
|
|
|
LoadBalancerNames: []*string{&loadBalancerName},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.ELB().AddTags(request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("error creating tags on %v: %v", loadBalancerName, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RemoveELBTags will remove tags to the specified loadBalancer, retrying up to MaxCreateTagsAttempts times if it hits an eventual-consistency type error
|
|
|
|
|
@ -976,22 +968,17 @@ func removeELBTags(c AWSCloud, loadBalancerName string, tags map[string]string)
|
|
|
|
|
elbTagKeysOnly = append(elbTagKeysOnly, &elb.TagKeyOnly{Key: aws.String(k)})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attempt := 0
|
|
|
|
|
for {
|
|
|
|
|
attempt++
|
|
|
|
|
|
|
|
|
|
request := &elb.RemoveTagsInput{
|
|
|
|
|
Tags: elbTagKeysOnly,
|
|
|
|
|
LoadBalancerNames: []*string{&loadBalancerName},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.ELB().RemoveTags(request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("error creating tags on %v: %v", loadBalancerName, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
request := &elb.RemoveTagsInput{
|
|
|
|
|
Tags: elbTagKeysOnly,
|
|
|
|
|
LoadBalancerNames: []*string{&loadBalancerName},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.ELB().RemoveTags(request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("error creating tags on %v: %v", loadBalancerName, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *awsCloudImplementation) GetELBV2Tags(ResourceArn string) (map[string]string, error) {
|
|
|
|
|
@ -1004,24 +991,18 @@ func getELBV2Tags(c AWSCloud, ResourceArn string) (map[string]string, error) {
|
|
|
|
|
request := &elbv2.DescribeTagsInput{
|
|
|
|
|
ResourceArns: []*string{&ResourceArn},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attempt := 0
|
|
|
|
|
for {
|
|
|
|
|
attempt++
|
|
|
|
|
|
|
|
|
|
response, err := c.ELBV2().DescribeTags(request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("error listing tags on %v: %v", ResourceArn, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tagset := range response.TagDescriptions {
|
|
|
|
|
for _, tag := range tagset.Tags {
|
|
|
|
|
tags[aws.StringValue(tag.Key)] = aws.StringValue(tag.Value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tags, nil
|
|
|
|
|
response, err := c.ELBV2().DescribeTags(request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("error listing tags on %v: %v", ResourceArn, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tagset := range response.TagDescriptions {
|
|
|
|
|
for _, tag := range tagset.Tags {
|
|
|
|
|
tags[aws.StringValue(tag.Key)] = aws.StringValue(tag.Value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tags, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *awsCloudImplementation) CreateELBV2Tags(ResourceArn string, tags map[string]string) error {
|
|
|
|
|
@ -1037,23 +1018,17 @@ func createELBV2Tags(c AWSCloud, ResourceArn string, tags map[string]string) err
|
|
|
|
|
for k, v := range tags {
|
|
|
|
|
elbv2Tags = append(elbv2Tags, &elbv2.Tag{Key: aws.String(k), Value: aws.String(v)})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attempt := 0
|
|
|
|
|
for {
|
|
|
|
|
attempt++
|
|
|
|
|
|
|
|
|
|
request := &elbv2.AddTagsInput{
|
|
|
|
|
Tags: elbv2Tags,
|
|
|
|
|
ResourceArns: []*string{&ResourceArn},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.ELBV2().AddTags(request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("error creating tags on %v: %v", ResourceArn, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
request := &elbv2.AddTagsInput{
|
|
|
|
|
Tags: elbv2Tags,
|
|
|
|
|
ResourceArns: []*string{&ResourceArn},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.ELBV2().AddTags(request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("error creating tags on %v: %v", ResourceArn, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *awsCloudImplementation) BuildTags(name *string) map[string]string {
|
|
|
|
|
|