Skip to content

Use CreateTags instead of TagResources#129

Merged
liwenwu-amazon merged 1 commit intoaws:masterfrom
nckturner:move-to-create-tags
Jul 16, 2018
Merged

Use CreateTags instead of TagResources#129
liwenwu-amazon merged 1 commit intoaws:masterfrom
nckturner:move-to-create-tags

Conversation

@nckturner
Copy link
Copy Markdown
Contributor

@nckturner nckturner commented Jul 9, 2018

Issue #, if available:
Fixes: #76

Description of changes:

  • Switches to CreateTags instead of TagResources.
  • Also introduce two new tags:
    • node.k8s.amazonaws.com/instance_id
    • cluster.k8s.amazonaws.com/name (only tagged if the env var CLUSTER_NAME is present).

Testing:
Created an EKS cluster with a node, which was created with the current CNI. I checked the tag on the ENI, it was the old format. I then applied CNI yaml with a container I built and scaled in and out the autoscaling group to get new nodes. The first time I did this with CLUSTER_NAME set:

tag key tag value
cluster.k8s.amazonaws.com/name wonderful-outfit-1531613390
node.k8s.amazonaws.com/instance_id i-03eb4524c4c96774a

Second time without:

tag key tag value
node.k8s.amazonaws.com/instance_id i-0bf1f4f8e688b70fd

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Copy Markdown
Contributor

@liwenwu-amazon liwenwu-amazon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add how you test your changes? thanks

Copy link
Copy Markdown
Contributor

@vsiddharth vsiddharth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall changes look good. Left minor suggestions.

Could you please add some tests to validate the new changes?

reflect "reflect"

"github.com/aws/aws-sdk-go/service/ec2"
ec2 "github.com/aws/aws-sdk-go/service/ec2"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this autogenerated using a newer version of mockgen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it, due to the slight differences. It was generated with go generate ./pkg/awsutils/...

tags[eniTagKey] = aws.String(tagValue)
log.Debugf("Trying to tag newly created eni: keys=%s, value=%s", eniTagKey, tagValue)
for _, tag := range tags {
log.Debugf("Trying to tag newly created eni: key=%s, value=%s", *tag.Key, *tag.Value)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use aws.StringValue here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

awsAPIErrInc("TagResources", err)
log.Warnf("Fail to tag the newly created eni %s %v", eniID, err)
awsAPIErrInc("CreateTags", err)
log.Warnf("Fail to tag the newly created eni %s: %v", eniID, err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Fail/Failed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, done.

Resource: "network-interface/" + eniID}
arnString := eniARN.String()
arns = append(arns, aws.String(arnString))
tags := []*ec2.Tag{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment with the sample tag keys and values for an ENI??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.

log.Warnf("Fail to tag the newly created eni %s: %v", eniID, err)
} else {
log.Debugf("Tag the newly created eni with arn: %s", arnString)
log.Debugf("Tag the newly created eni: %s", eniID)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please rephrase this message to
"Successfully tagged eni: %s", eniID

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, makes more sense.

@liwenwu-amazon liwenwu-amazon added this to the v1.1 milestone Jul 11, 2018
* Also introduce two new tags:
  - node.k8s.amazonaws.com/instance_id
  - cluster.k8s.amazonaws.com/name (only tagged if the env var CLUSTER_NAME is present).
@nckturner nckturner force-pushed the move-to-create-tags branch from 9d40633 to c82dc6e Compare July 14, 2018 07:44
Copy link
Copy Markdown
Contributor

@vsiddharth vsiddharth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants