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

feat: allow multiple environments per VPC via new service discovery namespace #2515

Merged
merged 21 commits into from
Jul 12, 2021

Conversation

bvtujo
Copy link
Contributor

@bvtujo bvtujo commented Jun 24, 2021

This PR modifies the default service discovery namespace for new environments to the form {env}.{app}.local. This change allows customers to place multiple environments in the same VPC.

The PR also creates an upgrade path for older environments. Those upgraded environments will retain the default app.local namespace to avoid a backward breaking change for services deployed there, but new environments will use env.app.local.

Screen Shot 2021-06-24 at 3 56 02 PM

In the image above, I have deployed the same service to 3 environments.
legacy was created at environment version 1.4.0. and upgraded to 1.5.0.
new was created at version 1.5.0
shared-with-legacy was created at 1.5.0 and shares a vpc and subnets with legacy.

There currently is not an upgrade path for existing environments to switch to new service discovery. This should not be an issue in most cases, however, as the environment variable points to the correct namespace in all cases and new+old environments can coexist in the same VPC.

This change does not disrupt any existing environments. If we eventually add an "environment v2.0.0," we can force migration to the new discovery service by removing the UseLegacyServiceDiscoveryIfBlank parameter and updating our workloads to remove the LegacyServiceDiscovery bool from the template package.

Updated integ tests to reflect new endpoints. Manually tested the above by running copilot svc exec -n fe -e $ENV for each of the three environments, then running curl fe.$COPILOT_SVC_DISCOVERY_ENDPOINT from within the container. Each time, I received the expected HTML content.

Related #2377

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@bvtujo bvtujo requested a review from a team as a code owner June 24, 2021 21:57
@bvtujo bvtujo requested review from huanjani and removed request for a team June 24, 2021 21:57
Copy link
Contributor

@iamhopaul123 iamhopaul123 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 to me! Would you add e2e and maybe update the doc accordingly (and merge conflict again sorry)? Thank you!

internal/pkg/cli/job_package.go Show resolved Hide resolved
@bvtujo bvtujo requested a review from toricls as a code owner June 28, 2021 18:05
Copy link
Contributor

@efekarakus efekarakus 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 to me! Mostly just a few questions

Comment on lines 165 to 166
// If the service discovery param is set (meaning the stack is not upgraded), use the provided value
if v != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this mean that the stack is actually upgraded? i.e. we are at least on v1.5.0

if v != "" {
return v, nil
}
// if the param exists but is empty, use the legacy endpoint.
Copy link
Contributor

Choose a reason for hiding this comment

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

When can this happen? (not against the code or anything) but it might be worthwhile writing it.

My understanding is that when upgrading we always set a value for this parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't set a value when upgrading. If the stack is created at version 1.5.0 or higher, it's set to env.app.local. If the stack is upgraded from before that version, it's set to empty, which causes the template to use app.local.

site/content/docs/developing/service-discovery.en.md Outdated Show resolved Hide resolved

Prior to Copilot v1.8.0 and environment version 1.5.0, the service discovery namespace used the format _{app name}.local_, without including the environment. This limitation made it impossible to deploy multiple environments in the same VPC. Any environments created with Copilot v1.8.0 and newer can share a VPC with any other environment.

When your environments are upgraded, Copilot will honor the service discovery namespace that the environment was created with. That means that the endpoint your services are reachable at will not change. Any new environments created with Copilot v1.8.0 and above will use the _{env name}.{app name}.local_ format for service discovery, and can share VPCs with older environments.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we create an issue and pin that in our repository so that folks are aware of this change.
Ideally if they use only the env variable then we are good. However, if folks have app.local hardcoded in their code and deploy to a new env then their code will fail mysteriously. (Which I think is ok since we provide the env variable)

templates/environment/versions/cf-v1.5.0.yml Outdated Show resolved Hide resolved
@iamhopaul123 iamhopaul123 added the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Jun 29, 2021
@@ -262,6 +263,14 @@ func (o *deploySvcOpts) configureClients() error {
// CF client against env account profile AND target environment region
o.svcCFN = cloudformation.New(envSession)

o.endpointGetter, err = describe.NewEnvDescriber(describe.NewEnvDescriberConfig{
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to update cli/deploy.go as well? I couldn't find it in the list of files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, since there are no flag changes and deploy under the hood just invokes svc or job deploy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The endpointGetter func is initialized during Execute for both svc init and job init by the configureClients() method on the initSvcProps and initJobProps structs.

internal/pkg/describe/env.go Outdated Show resolved Hide resolved
@iamhopaul123 iamhopaul123 removed the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Jul 8, 2021
@efekarakus efekarakus changed the title fix: allow multiple environments per VPC via new service discovery namespace feat: allow multiple environments per VPC via new service discovery namespace Jul 9, 2021
Co-authored-by: Efe Karakus <efekarakus@gmail.com>
@bvtujo
Copy link
Contributor Author

bvtujo commented Jul 12, 2021

Screen Shot 2021-07-12 at 11 23 15 AM

Success. Tested that the given endpoint is reachable from each environment by using `copilot svc exec`.

Copy link
Contributor

@efekarakus efekarakus left a comment

Choose a reason for hiding this comment

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

Woohooo 🚀

Copy link
Contributor

@iamhopaul123 iamhopaul123 left a comment

Choose a reason for hiding this comment

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

Awesome 🚢

@mergify mergify bot merged commit 64920a0 into aws:mainline Jul 12, 2021
Sprint 🏃‍♀️ automation moved this from In review to Pending release Jul 12, 2021
thrau pushed a commit to localstack/copilot-cli-local that referenced this pull request Dec 9, 2022
…amespace (aws#2515)

This PR modifies the default service discovery namespace for new environments to the form {env}.{app}.local. This change allows customers to place multiple environments in the same VPC.

The PR also creates an upgrade path for older environments. Those upgraded environments will retain the default app.local namespace to avoid a backward breaking change for services deployed there, but new environments will use env.app.local.

<img width="761" alt="Screen Shot 2021-06-24 at 3 56 02 PM" src="https://user-images.githubusercontent.com/25392995/123342814-50146a00-d505-11eb-8749-41e409150999.png">


In the image above, I have deployed the same service to 3 environments.
legacy was created at environment version 1.4.0. and upgraded to 1.5.0.
new was created at version 1.5.0
shared-with-legacy was created at 1.5.0 and shares a vpc and subnets with legacy.

There currently is not an upgrade path for existing environments to switch to new service discovery. This should not be an issue in most cases, however, as the environment variable points to the correct namespace in all cases and new+old environments can coexist in the same VPC.

This change does not disrupt any existing environments. If we eventually add an "environment v2.0.0," we can force migration to the new discovery service by removing the UseLegacyServiceDiscoveryIfBlank parameter and updating our workloads to remove the LegacyServiceDiscovery bool from the template package.

Updated integ tests to reflect new endpoints. Manually tested the above by running `copilot svc exec -n fe -e $ENV` for each of the three environments, then running `curl fe.$COPILOT_SVC_DISCOVERY_ENDPOINT` from within the container. Each time, I received the expected HTML content. 

Related aws#2377

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Sprint 🏃‍♀️
  
Pending release
Development

Successfully merging this pull request may close these issues.

None yet

3 participants