Skip to content

fix: preserve existing service discovery endpoint#3949

Merged
mergify[bot] merged 6 commits intoaws:mainlinefrom
Lou1415926:fix/service-discovery-endpoint
Aug 29, 2022
Merged

fix: preserve existing service discovery endpoint#3949
mergify[bot] merged 6 commits intoaws:mainlinefrom
Lou1415926:fix/service-discovery-endpoint

Conversation

@Lou1415926
Copy link
Copy Markdown
Contributor

The bug

Back in v1.9.0, we introduced “multiple environment per VPC”. This feature is shipped with upgrading the service discovery endpoint, from app.local to env.app.local. Since during env upgrade, we preserve all the old parameters, app.local has always been preserved for old environments.

However, env deploy didn’t account for this. It will try to use env.app.local for all environments, old or new. When env deploy is executed against an environment that was created pre-v1.9.0, it results in an attempt to update app.local to env.app.local. This will be breaking for environments that already have services in it, because the service discovery endpoint is exported and imported by the service stack, thus not updatable.

The fix

The fix simply preserves the value of the he existing ServiceDiscoveryEndpoint parameter. It also accounts for the scenario where ServiceDiscoveryEndpoint is not yet in the parameter (pre-v1.9.0 environment that has never been upgraded), and use app.local for those environment.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.

@Lou1415926 Lou1415926 requested a review from a team as a code owner August 25, 2022 19:03
@Lou1415926 Lou1415926 requested review from dannyrandall and removed request for a team August 25, 2022 19:03
@Lou1415926 Lou1415926 force-pushed the fix/service-discovery-endpoint branch from 241bc3d to 61e39b2 Compare August 25, 2022 19:03
Comment thread internal/pkg/deploy/cloudformation/stack/env.go Outdated
Comment thread internal/pkg/deploy/cloudformation/stack/env.go Outdated
Comment thread internal/pkg/deploy/cloudformation/stack/env.go Outdated
if old == nil { // The ParamKey doesn't exist in the old stack, use the new value.
return &new
// transformEnvControllerParameters transforms an env-controller managed parameter.
// If the parameter exists in the old template, it uses its previous value. Otherwise, it returns its new default 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.

Suggested change
// If the parameter exists in the old template, it uses its previous value. Otherwise, it returns its new default value.
// If the parameter exists in the old template, it uses its previous value. Otherwise, it returns its new value.

Comment thread internal/pkg/deploy/cloudformation/stack/env.go Outdated
// The parameter`transformFunc` are functions that transform a parameter, given its value in the new template and the old template.
// Each transform functions should keep the following in mind:
// 1. It should return `nil` if the parameter should be removed.
// 2. The transform functions are applied in a convolutional manner.
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.

Sorry-- what does this mean?

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.

that the second filter is applied on the result of the first filter, and the third filter is applied on the result of the second filter, etc...
any suggestion on better wordings?

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.

🤔 I dunno...maybe "sequential"?

if old == nil {
return &cloudformation.Parameter{
ParameterKey: new.ParameterKey,
ParameterValue: aws.String(fmt.Sprintf(`%s.local`, e.in.App.Name)),
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.

wait, isn't the new default env.app.local?

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.

Yes but we want to use the old default in this case. Otherwise we'd be trying to update app.local to env.app.local which is the bug in the first place

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.

Ah, gotcha gotcha-- I missed the second part of "the fix."

Copy link
Copy Markdown
Contributor

@dannyrandall dannyrandall left a comment

Choose a reason for hiding this comment

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

great fix 👏!

Comment thread internal/pkg/deploy/cloudformation/stack/env.go Outdated
@huanjani huanjani added the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Aug 29, 2022
Copy link
Copy Markdown
Contributor

@huanjani huanjani left a comment

Choose a reason for hiding this comment

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

Looks good! Adding label in case you want to address nits on comments.

@Lou1415926 Lou1415926 removed the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Aug 29, 2022
@mergify mergify Bot merged commit 6e8846d into aws:mainline Aug 29, 2022
mergify Bot pushed a commit that referenced this pull request Aug 30, 2022
…k with bootstrap stack (#3966)

Previously, we have two fixes:
1. #3956 which patches the S3 permissions to the environment manager role if it's needed.
2. #3949 which preserves service discovery endpoint namespace from a previously deployed env stack.

Fix 1 performs an environment template version check to infer whether the necessary permissions are present. This version check fails to take into account the `"bootstrap"` version, which is present when the environment is only bootstrapped (by running `env init` and not having run `env deploy`)

Fix 2 grabs the old parameter from a deployed environment stack. It fails to take into consideration that, while an env stack that's on `"bootstrap"` version is not considered a "deployed environment" in Copilot, it is a deployed stack in CFN.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
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