-
Notifications
You must be signed in to change notification settings - Fork 619
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
Branch remove token #1711
Conversation
you might want to fix your author email in your commits :) |
9372674
to
d90140a
Compare
d90140a
to
8375d2a
Compare
8375d2a
to
d457705
Compare
CHANGELOG.md
Outdated
@@ -1,5 +1,9 @@ | |||
# Changelog | |||
|
|||
## 1.22.1 |
There was a problem hiding this comment.
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.
agent/app/agent.go
Outdated
@@ -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 |
There was a problem hiding this comment.
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
agent/app/agent.go
Outdated
@@ -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 |
There was a problem hiding this comment.
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
agent/app/agent.go
Outdated
@@ -479,13 +482,18 @@ func (agent *ecsAgent) registerContainerInstance( | |||
tags = mergeTags(tags, ec2Tags) | |||
} | |||
|
|||
if agent.registrationToken == "" { | |||
agent.registrationToken = uuid.New() | |||
stateManager.Save() |
There was a problem hiding this comment.
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.
agent/app/agent.go
Outdated
@@ -107,6 +108,7 @@ type ecsAgent struct { | |||
terminationHandler sighandlers.TerminationHandler | |||
mobyPlugins mobypkgwrapper.Plugins | |||
resourceFields *taskresource.ResourceFields | |||
registrationToken string |
There was a problem hiding this comment.
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.
agent/app/agent.go
Outdated
@@ -479,13 +482,18 @@ func (agent *ecsAgent) registerContainerInstance( | |||
tags = mergeTags(tags, ec2Tags) | |||
} | |||
|
|||
if agent.registrationToken == "" { |
There was a problem hiding this comment.
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.
agent/app/agent_test.go
Outdated
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( |
There was a problem hiding this comment.
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
agent/app/agent.go
Outdated
@@ -479,13 +482,18 @@ func (agent *ecsAgent) registerContainerInstance( | |||
tags = mergeTags(tags, ec2Tags) | |||
} | |||
|
|||
if agent.registrationToken == "" { | |||
agent.registrationToken = uuid.New() | |||
stateManager.Save() |
There was a problem hiding this comment.
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.
2e64f34
to
b8d52d5
Compare
agent/app/agent_test.go
Outdated
@@ -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), |
There was a problem hiding this comment.
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
b8d52d5
to
3418d83
Compare
There was a problem hiding this 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) |
There was a problem hiding this comment.
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
3418d83
to
f8239b1
Compare
f8239b1
to
0fe43ba
Compare
Summary
Merge Sharanya's RCI idempotency changes and remove the token from the state file in app/agent.go
Implementation details
Testing
make release
)go build -out amazon-ecs-agent.exe ./agent
)make test
) passgo test -timeout=25s ./agent/...
) passmake run-integ-tests
) pass.\scripts\run-integ-tests.ps1
) passmake run-functional-tests
) pass.\scripts\run-functional-tests.ps1
) passNew 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.