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-v2-alpha): can't delete fargate cluster #33573

Merged
merged 2 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions packages/@aws-cdk/aws-eks-v2-alpha/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,8 @@ export class Cluster extends ClusterBase {

private readonly _kubectlProvider?: IKubectlProvider;

private readonly _clusterAdminAccess?: AccessEntry;

/**
* Initiates an EKS Cluster with the supplied arguments
*
Expand Down Expand Up @@ -1279,11 +1281,7 @@ export class Cluster extends ClusterBase {

// give the handler role admin access to the cluster
// so it can deploy/query any resource.
this.grantAccess('ClusterAdminRoleAccess', this._kubectlProvider?.role!.roleArn, [
AccessPolicy.fromAccessPolicyName('AmazonEKSClusterAdminPolicy', {
accessScopeType: AccessScopeType.CLUSTER,
}),
]);
this._clusterAdminAccess = this.grantClusterAdmin('ClusterAdminRoleAccess', this._kubectlProvider?.role!.roleArn);
}

// do not create a masters role if one is not provided. Trusting the accountRootPrincipal() is too permissive.
Expand Down Expand Up @@ -1351,6 +1349,32 @@ export class Cluster extends ClusterBase {
this.addToAccessEntry(id, principal, accessPolicies);
}

/**
* Grants the specified IAM principal cluster admin access to the EKS cluster.
*
* This method creates an `AccessEntry` construct that grants the specified IAM principal the cluster admin
* access permissions. This allows the IAM principal to perform the actions permitted
* by the cluster admin acces.
*
* @param id - The ID of the `AccessEntry` construct to be created.
* @param principal - The IAM principal (role or user) to be granted access to the EKS cluster.
* @returns the access entry construct
*/
@MethodMetadata()
public grantClusterAdmin(id: string, principal: string): AccessEntry {
const newEntry = new AccessEntry(this, id, {
principal,
cluster: this,
accessPolicies: [
AccessPolicy.fromAccessPolicyName('AmazonEKSClusterAdminPolicy', {
accessScopeType: AccessScopeType.CLUSTER,
}),
],
});
this.accessEntries.set(principal, newEntry);
return newEntry;
}

/**
* Fetch the load balancer address of a service of type 'LoadBalancer'.
*
Expand Down Expand Up @@ -1730,13 +1754,19 @@ export class Cluster extends ClusterBase {
},
});

new KubernetesPatch(this, 'CoreDnsComputeTypePatch', {
const k8sPatch = new KubernetesPatch(this, 'CoreDnsComputeTypePatch', {
cluster: this,
resourceName: 'deployment/coredns',
resourceNamespace: 'kube-system',
applyPatch: renderPatch(CoreDnsComputeType.FARGATE),
restorePatch: renderPatch(CoreDnsComputeType.EC2),
});

// In Patch deletion, it needs to apply the restore patch to the cluster
// So the cluster admin access can only be deleted after the patch
if (this._clusterAdminAccess) {
k8sPatch.node.addDependency(this._clusterAdminAccess);
}
}
}

Expand Down

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,7 @@
"PatchType": "strategic"
},
"DependsOn": [
"FargateTestClusterClusterAdminRoleAccess9EFE9888",
"FargateTestClusterKubectlReadyBarrier724731D5"
],
"UpdateReplacePolicy": "Delete",
Expand Down
Loading