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

fix(eks): KubernetesPatch and FargateCluster creates a circular dependency and breaks deployment #10536

Merged
merged 3 commits into from
Sep 25, 2020

Conversation

iliapolo
Copy link
Contributor

@iliapolo iliapolo commented Sep 25, 2020

In version 1.62.0 we introduced the ability to run kubectl commands on imported clusters. (See #9802).

Part of this change included some refactoring with regards to how we use and create the KubectlProvider.
Looks like we didn't consistently apply the same logic across all constructs that use it.

Case in point:

const provider = KubectlProvider.getOrCreate(this, props.cluster);

Notice that here we use this as the scope to the getOrCreate call. Same goes for:

const provider = KubectlProvider.getOrCreate(this, props.cluster);

However, KubernetesPatch use scope instead.

const provider = KubectlProvider.getOrCreate(scope, props.cluster);

This means that the entire scope of the KubernetesPatch now depends, among others, on the kubectlBarrier.
The scope will usually be either the cluster itself (when using FargateCluster), or the entire stack (when using new KubernetesPatch). In any case, the scope will most likely contain the cluster VPC.

This creates the following dependency cycle: Cluster => ClusterVpc => KubectlBarrier => Cluster.

The fix aligns the KubernetesPatch behavior to all other kubectl constructs and uses this as the scope, which will only add dependency on the barrier to the custom resource representing the patch.

Fixes #10528
Fixes #10537


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

@mergify
Copy link
Contributor

mergify bot commented Sep 25, 2020

Title does not follow the guidelines of Conventional Commits. Please adjust title before merge.

@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Sep 25, 2020
@eladb
Copy link
Contributor

eladb commented Sep 25, 2020

Oops

@iliapolo iliapolo changed the title fix(eks): KubernetesPatch creates a circular dependency and break deployment fix(eks): KubernetesPatch and FargateCluster creates a circular dependency and breaks deployment Sep 25, 2020
@iliapolo iliapolo marked this pull request as ready for review September 25, 2020 13:53
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 7cf6b5d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Sep 25, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit b23ce03 into master Sep 25, 2020
@mergify mergify bot deleted the epolon/eks-fix-k8s-patch branch September 25, 2020 14:19
iliapolo added a commit that referenced this pull request Sep 25, 2020
…ependency and breaks deployment (#10536)

In version [`1.62.0`](https://github.com/aws/aws-cdk/releases/tag/v1.62.0) we introduced the ability to run `kubectl` commands on imported clusters. (See #9802).

Part of this change included some refactoring with regards to how we use and create the `KubectlProvider`.
Looks like we didn't consistently apply the same logic across all constructs that use it.

Case in point:

https://github.com/aws/aws-cdk/blob/e349004a522e2123c1e93bd3402dd7c3f9c5c17c/packages/%40aws-cdk/aws-eks/lib/k8s-manifest.ts#L58

Notice that here we use `this` as the scope to the `getOrCreate` call. Same goes for:

https://github.com/aws/aws-cdk/blob/e349004a522e2123c1e93bd3402dd7c3f9c5c17c/packages/%40aws-cdk/aws-eks/lib/k8s-object-value.ts#L64

However, `KubernetesPatch` use `scope` instead.

https://github.com/aws/aws-cdk/blob/e349004a522e2123c1e93bd3402dd7c3f9c5c17c/packages/%40aws-cdk/aws-eks/lib/k8s-patch.ts#L74

This means that the entire `scope` of the `KubernetesPatch` now depends, among others, on the `kubectlBarrier`. 
The scope will usually be either the cluster itself (when using `FargateCluster`), or the entire stack (when using `new KubernetesPatch`). In any case, the scope will most likely contain the cluster VPC.

This creates the following dependency cycle: `Cluster => ClusterVpc => KubectlBarrier => Cluster`.

The fix aligns the `KubernetesPatch` behavior to all other `kubectl` constructs and uses `this` as the scope, which will only add dependency on the barrier to the custom resource representing the patch.

Fixes #10528
Fixes #10537

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
3 participants