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

EKS : Cluster destroy failing for Fargate w/ CoreDNS addon #28621

Closed
Howlla opened this issue Jan 8, 2024 · 2 comments
Closed

EKS : Cluster destroy failing for Fargate w/ CoreDNS addon #28621

Howlla opened this issue Jan 8, 2024 · 2 comments
Labels
@aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@Howlla
Copy link

Howlla commented Jan 8, 2024

Describe the bug

When using the CoreDNS addon for a Fargate Cluster, the teardown fails and the resources created are not deleted. The error is caused by CoreDNSComputeType patch which is automatically applied to Fargate clusters.

Screenshot 2024-01-08 at 2 31 52 PM

Expected Behavior

The cluster created by cdk deploy should delete and clean up all resources using cdk destroy

Current Behavior

Delete fails and some of the resources are kept intact
Screenshot 2024-01-08 at 2 35 28 PM

This shows up in the terminal running destroy

2:12:41 PM | DELETE_FAILED        | Custom::AWSCDK-EKS-KubernetesPatch    | HelloEKSCoreDnsComputeTypePatch45115688
Received response status [FAILED] from custom resource. Message returned: Error: b'Error from server (NotFound): deployments.apps "coredns" not found\n'

at invokeUserFunction (/var/task/framework.js:2:6)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async onEvent (/var/task/framework.js:1:369)
at async Runtime.handler (/var/task/cfn-response.js:1:1573) (RequestId: a925b3d0-0e54-4c3e-af1e-07a7dc63ad3c)


 ❌  CdkStack: destroy failed Error: The stack named CdkStack is in a failed state. You may need to delete it from the AWS console : DELETE_FAILED (The following resource(s) failed to delete: [HelloEKSCoreDnsComputeTypePatch45115688]. )
    at destroyStack (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:467:1792)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async CdkToolkit.destroy (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:470:187853)
    at async exec4 (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:525:53102)

The stack named CdkStack is in a failed state. You may need to delete it from the AWS console : DELETE_FAILED (The following resource(s) failed to delete: [HelloEKSCoreDnsComputeTypePatch45115688]. )

Reproduction Steps

In the terminal run cdk init sample-app --language=typescript

Replace lib/cdk-stack.ts with the code below

import * as eks from 'aws-cdk-lib/aws-eks'
import { Construct } from 'constructs';

export class CdkStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    var cluster = new eks.FargateCluster(this, 'HelloEKS', {
      version: eks.KubernetesVersion.V1_27,
    });
    new eks.CfnAddon(this, 'MyCoreDnsAddon', {
      addonName: 'coredns',
      clusterName: cluster.clusterName,
    })
  }
}

run cdk deploy

wait for deployment to complete

run cdk destroy

Possible Solution

Reason for bug:

The k8s-patch for computeType annotations are applied with no dependency on the coreDNS addon themselves.
When we run the cdk destroy command, first the addons are removed. This means that the coredns deployment is deleted first and then the kubectl patch is attempted to be removed. This results in the console output Received response status [FAILED] from custom resource. Message returned: Error: b'Error from server (NotFound): deployments.apps "coredns" not found\n'

Possible Fix

Set removal policy for either the CoreDNSComputeType Patch or the coreDNS addon to RemovalPolicy.Retain

Additional Information/Context

No response

CDK CLI Version

2.100.0(build e1b5c77)

Framework Version

No response

Node.js Version

20.5.0

OS

Mac Sonoma

Language

TypeScript

Language Version

No response

Other information

Related Issue: #14968 - it states that CDK should be using core addons as opposed to relying on some default configuration from EKS.

@Howlla Howlla added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 8, 2024
@github-actions github-actions bot added the @aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service label Jan 8, 2024
@pahud
Copy link
Contributor

pahud commented Jan 9, 2024

I am not sure if we should add any default retain policy on the CoreDnsComputeTypePatch but adding the removal policy from the cfnAddOn as proposed in this PR makes sense to me.

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jan 9, 2024
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jan 11, 2024
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. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants