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

[aws-eks] Cannot call applyRemovalPolicy on KubernetesManifest objects #9921

Closed
otterley opened this issue Aug 23, 2020 · 3 comments · Fixed by #18052
Closed

[aws-eks] Cannot call applyRemovalPolicy on KubernetesManifest objects #9921

otterley opened this issue Aug 23, 2020 · 3 comments · Fixed by #18052
Labels
@aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@otterley
Copy link
Contributor

otterley commented Aug 23, 2020

In an attempt to prevent a Kubernetes resource from being deleted during stack destruction, I tried to use the current tribal-knowledge method:

      const meshResource = cluster.addManifest(`Mesh${clusterName}`, {
        apiVersion: "appmesh.k8s.aws/v1beta2",
        kind: "Mesh",
        metadata: {
          name: "mesh",
        },
        spec: {
          awsName: mesh.meshName,
          namespaceSelector: {
            matchLabels: {
              mesh: mesh.meshName,
            },
          },
        },
      });
      meshResource.node.addDependency(mesh, appMeshController);
      (meshResource.node.defaultChild as cdk.CfnResource).applyRemovalPolicy(cdk.RemovalPolicy.RETAIN);

This did not work:

$ npm run cdk synth       
...
meshResource.node.defaultChild.applyRemovalPolicy is not a function
Subprocess exited with error 1

Environment

  • CLI Version : 1.60.0
  • Framework Version: 1.60.0
  • Node.js Version: 12.18.2
  • OS : MacOS Catalina
  • Language (Version): TypeScript

This is 🐛 Bug Report

@otterley otterley added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 23, 2020
@github-actions github-actions bot added the @aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service label Aug 23, 2020
@otterley
Copy link
Contributor Author

Interestingly, it also appears that addPropertyOverride doesn't work either:

(meshResource.node.defaultChild as cdk.CfnResource).addPropertyOverride('UpdateReplacePolicy', 'Retain');
(meshResource.node.defaultChild as cdk.CfnResource).addPropertyOverride('DeletionPolicy', 'Retain');
$ npm run cdk synth       

meshResource.node.defaultChild.addPropertyOverride is not a function

@iliapolo iliapolo added effort/small Small work item – less than a day of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Aug 25, 2020
@iliapolo iliapolo added this to the [GA] @aws-cdk/aws-eks milestone Oct 4, 2020
@iliapolo
Copy link
Contributor

iliapolo commented Dec 1, 2020

The defaultChild of KubernetesManifest resources is not setup to retrieve the underlying cdk.CfnResource, but rather returns a core.CustomResource construct.

Workaround:

(meshResource.node.defaultChild?.node.defaultChild as cdk.CfnResource).addPropertyOverride(...)

@iliapolo iliapolo removed this from the [GA] @aws-cdk/aws-eks milestone Dec 1, 2020
@iliapolo iliapolo removed their assignment Jun 27, 2021
@mergify mergify bot closed this as completed in #18052 Dec 16, 2021
mergify bot pushed a commit that referenced this issue Dec 16, 2021
…esource` (#18052)

The type of `node.defaultChild` is `KubernetesManifest` and not a `CfnResource`, preventing users from using escape hatches in the standard way.

Fixes #9921.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
…esource` (aws#18052)

The type of `node.defaultChild` is `KubernetesManifest` and not a `CfnResource`, preventing users from using escape hatches in the standard way.

Fixes aws#9921.

----

*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
@aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants