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

Pass clusterARN in task state change struct to account for Fargate FC tasks. #4107

Merged
merged 2 commits into from
Mar 12, 2024

Conversation

RichaGangwar
Copy link
Contributor

Summary

This PR fixes an issue in SubmitTaskStateChange API where the clusterARN populated in change request is incorrect. For one specific platform, the clusterARN is different for different tasks.

Implementation details

  1. Add clusterarn to taskstatechange struct.
  2. In submitStatechange api, check if the clusterarn in taskstatechange struct is not nil. If not nil, then use the passed clusterarn instead of clusterarn from configaccessor.

Testing

New tests cover the changes:

Description for the changelog

Pass clusterARN in task state change struct.
Does this PR include breaking model changes? If so, Have you added transformation functions?

Licensing

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

@RichaGangwar RichaGangwar marked this pull request as ready for review March 11, 2024 15:58
@RichaGangwar RichaGangwar requested a review from a team as a code owner March 11, 2024 15:58
@@ -124,6 +126,9 @@ func (c *ContainerStateChange) String() string {
// String returns a human readable string representation of a TaskStateChange.
func (change *TaskStateChange) String() string {
res := fmt.Sprintf("%s -> %s", change.TaskARN, change.Status.String())
if len(change.ClusterARN) != 0 {
res += fmt.Sprintf(", ClusterARN: %s", change.ClusterARN)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit(non-blocking): can we follow the format on L128 "%s -> %s" here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Will fix it if there is any blocking comment.

@@ -507,8 +507,10 @@ func (client *ecsClient) SubmitTaskStateChange(change ecs.TaskStateChange) error

func (client *ecsClient) submitTaskStateChange(change ecs.TaskStateChange) error {

clusterARN := convertTaskToClusterARN(change.TaskARN)

clusterARN := client.configAccessor.Cluster()
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like the problem here is the cluster arn changing in between tasks, and that does not get updated in the config accessor. Wouldn't this be accessible from the config accessor so long as that were kept up to date? Why do we need an additional field on the TaskStateChange?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Firecracker can host multiple tasks on the same instance. So, clusterARN for different tasks will be different since we use task account's clusterARN. We cannot update the configaccessor as we would need to keep updating the member variable every time the API is called for the respective task. It's not that the config accessor is kept up to date in the lifecycle of the task, its just that it would keep differing for different tasks.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, thanks for explaining!

@@ -124,6 +126,9 @@ func (c *ContainerStateChange) String() string {
// String returns a human readable string representation of a TaskStateChange.
func (change *TaskStateChange) String() string {
Copy link
Contributor

@danehlim danehlim Mar 11, 2024

Choose a reason for hiding this comment

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

nit: Can we update task state change string unit testing to account for case where ClusterARN is populated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Will add in a follow-up CR.

@@ -506,6 +506,11 @@ func (client *ecsClient) SubmitTaskStateChange(change ecs.TaskStateChange) error
}

func (client *ecsClient) submitTaskStateChange(change ecs.TaskStateChange) error {

clusterARN := client.configAccessor.Cluster()
if len(change.ClusterARN) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Prefer to use change.ClusterARN != "" in favor of len(change.ClusterARN) != 0 for readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Will change in a follow-up CR.

@@ -506,6 +506,11 @@ func (client *ecsClient) SubmitTaskStateChange(change ecs.TaskStateChange) error
}

func (client *ecsClient) submitTaskStateChange(change ecs.TaskStateChange) error {

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Unnecessary newline added here - not blocking to this pull request, but please make sure this is removed in a followup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

@@ -519,7 +524,7 @@ func (client *ecsClient) submitTaskStateChange(change ecs.TaskStateChange) error
}

_, err := client.submitStateChangeClient.SubmitTaskStateChange(&ecsmodel.SubmitTaskStateChangeInput{
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Let's look into adding a unit test for STSC that has as input a TaskStateChange with ClusterARN field populated. I understand that there is a level of urgency to merging the underlying change of this pull request, so this can be done in a followup pull request if not done in this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

@RichaGangwar RichaGangwar merged commit 37d421c into aws:dev Mar 12, 2024
36 checks passed
@mye956 mye956 mentioned this pull request Mar 19, 2024
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.

4 participants