Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branch remove token #1711

Merged
merged 2 commits into from
Dec 4, 2018
Merged

Branch remove token #1711

merged 2 commits into from
Dec 4, 2018

Conversation

tommyhahn
Copy link
Contributor

@tommyhahn tommyhahn commented Nov 29, 2018

Summary

Merge Sharanya's RCI idempotency changes and remove the token from the state file in app/agent.go

Implementation details

Testing

  • Builds on Linux (make release)
  • Builds on Windows (go build -out amazon-ecs-agent.exe ./agent)
  • Unit tests on Linux (make test) pass
  • Unit tests on Windows (go test -timeout=25s ./agent/...) pass
  • Integration tests on Linux (make run-integ-tests) pass
  • Integration tests on Windows (.\scripts\run-integ-tests.ps1) pass
  • Functional tests on Linux (make run-functional-tests) pass
  • Functional tests on Windows (.\scripts\run-functional-tests.ps1) pass

New tests cover the changes:

Description for the changelog

Licensing

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

@sharanyad
Copy link
Contributor

you might want to fix your author email in your commits :)

@haikuoliu haikuoliu requested a review from a team November 29, 2018 23:38
@yumex93 yumex93 requested a review from sharanyad November 29, 2018 23:43
@yumex93 yumex93 added bot/test and removed bot/test labels Nov 29, 2018
@yumex93 yumex93 added bot/test and removed bot/test labels Nov 30, 2018
CHANGELOG.md Outdated
@@ -1,5 +1,9 @@
# Changelog

## 1.22.1
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be changed to ##1.23.0-dev, since we are going to bump the major version this time.

@@ -323,7 +325,7 @@ func (agent *ecsAgent) newTaskEngine(containerChangeEventStream *eventstream.Eve
}

// We try to set these values by loading the existing state file first
var previousCluster, previousEC2InstanceID, previousContainerInstanceArn, previousAZ string
var previousCluster, previousEC2InstanceID, previousContainerInstanceArn, previousAZ, previousRegistrationToken string
Copy link
Contributor

@yumex93 yumex93 Nov 30, 2018

Choose a reason for hiding this comment

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

I do not think we still need previousRegistrationToken here, since we remove registrationToken from state file, it will never be initialized here. You may want to double check with @sharanyad

@@ -370,6 +372,7 @@ func (agent *ecsAgent) newTaskEngine(containerChangeEventStream *eventstream.Eve

// Use the values we loaded if there's no issue
agent.containerInstanceARN = previousContainerInstanceArn
agent.registrationToken = previousRegistrationToken
Copy link
Contributor

Choose a reason for hiding this comment

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

previousRegistrationToken will never be initialized here. So the agent.registrationToken will always equal to "". It can be removed

@@ -479,13 +482,18 @@ func (agent *ecsAgent) registerContainerInstance(
tags = mergeTags(tags, ec2Tags)
}

if agent.registrationToken == "" {
agent.registrationToken = uuid.New()
stateManager.Save()
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we no more need to save registrationToken in the state file, we do not need to call stateManager.Save() here, considering at the end of the this 'registerContainerInstance' function, we already call stateManager.Save() to save all saveable options.

@@ -107,6 +108,7 @@ type ecsAgent struct {
terminationHandler sighandlers.TerminationHandler
mobyPlugins mobypkgwrapper.Plugins
resourceFields *taskresource.ResourceFields
registrationToken string
Copy link
Contributor

Choose a reason for hiding this comment

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

since we do not store this on disk, we may not need this field anymore.

@@ -479,13 +482,18 @@ func (agent *ecsAgent) registerContainerInstance(
tags = mergeTags(tags, ec2Tags)
}

if agent.registrationToken == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

this check is not needed -- for each register call, we'll create a new token.

stateManagerFactory.EXPECT().NewStateManager(gomock.Any(),
gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(),
).Return(
stateManagerFactory.EXPECT().NewStateManager(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this can be broken into two lines

@@ -479,13 +482,18 @@ func (agent *ecsAgent) registerContainerInstance(
tags = mergeTags(tags, ec2Tags)
}

if agent.registrationToken == "" {
agent.registrationToken = uuid.New()
stateManager.Save()
Copy link
Contributor

Choose a reason for hiding this comment

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

this should not be needed.

@@ -676,7 +676,7 @@ func TestReregisterContainerInstanceHappyPath(t *testing.T) {
mockMobyPlugins.EXPECT().Scan().AnyTimes().Return([]string{""}, nil),
mockDockerClient.EXPECT().ListPluginsWithFilters(gomock.Any(), gomock.Any(),
gomock.Any(), gomock.Any()).AnyTimes().Return([]string{}, nil),
client.EXPECT().RegisterContainerInstance(containerInstanceARN, gomock.Any(), gomock.Any()).Return(containerInstanceARN, availabilityZone, nil),
client.EXPECT().RegisterContainerInstance(containerInstanceARN, gomock.Any(), gomock.Any(), gomock.Any()).Return(containerInstanceARN, availabilityZone, nil),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this can also break into two lines

Copy link
Contributor

@sharanyad sharanyad left a comment

Choose a reason for hiding this comment

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

code lgtm. Hold off on merging until tests pass. Thanks!

CHANGELOG.md Outdated
@@ -1,5 +1,9 @@
# Changelog

## 1.23.0-dev
* Bug - Fixed a bug where agent can register container instance back to back and gets
assigned two container instance ARNs [#1579](https://github.com/aws/amazon-ecs-agent/pull/1579)
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be changed to this PR link

@tommyhahn tommyhahn force-pushed the branch_remove_token branch from 3418d83 to f8239b1 Compare December 3, 2018 04:15
@tommyhahn tommyhahn force-pushed the branch_remove_token branch from f8239b1 to 0fe43ba Compare December 3, 2018 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants