Skip to content

Commit 8189c82

Browse files
authored
feat(eks-v2-alpha): use native L1 instead of custom resource for Fargate Profile (#32386)
### Reason for this change It's part of eks rewrite. ### Description of changes Use native L1 `CfnFargateProfile` to replace custom resource for provisioning Fargate Profile. ### Description of how you validated changes unit tests/integration tests ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b30c823 commit 8189c82

File tree

134 files changed

+5140
-1428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+5140
-1428
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export const CLUSTER_RESOURCE_TYPE = 'Custom::AWSCDK-EKS-Cluster';
2-
export const FARGATE_PROFILE_RESOURCE_TYPE = 'Custom::AWSCDK-EKS-FargateProfile';

packages/@aws-cdk/aws-eks-v2-alpha/lib/cluster-resource-handler/fargate.ts

-120
This file was deleted.

packages/@aws-cdk/aws-eks-v2-alpha/lib/cluster-resource-handler/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { ProxyAgent } from 'proxy-agent';
1010
import { ClusterResourceHandler } from './cluster';
1111
import { EksClient } from './common';
1212
import * as consts from './consts';
13-
import { FargateProfileResourceHandler } from './fargate';
1413
import { IsCompleteResponse } from 'aws-cdk-lib/custom-resources/lib/provider-framework/types';
1514

1615
const proxyAgent = new ProxyAgent();
@@ -67,7 +66,6 @@ export async function isComplete(event: AWSLambda.CloudFormationCustomResourceEv
6766
function createResourceHandler(event: AWSLambda.CloudFormationCustomResourceEvent) {
6867
switch (event.ResourceType) {
6968
case consts.CLUSTER_RESOURCE_TYPE: return new ClusterResourceHandler(defaultEksClient, event);
70-
case consts.FARGATE_PROFILE_RESOURCE_TYPE: return new FargateProfileResourceHandler(defaultEksClient, event);
7169
default:
7270
throw new Error(`Unsupported resource type "${event.ResourceType}`);
7371
}

packages/@aws-cdk/aws-eks-v2-alpha/lib/fargate-profile.ts

+16-22
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { Construct } from 'constructs';
22
import { Cluster, AuthenticationMode } from './cluster';
3-
import { FARGATE_PROFILE_RESOURCE_TYPE } from './cluster-resource-handler/consts';
4-
import { ClusterResourceProvider } from './cluster-resource-provider';
53
import * as ec2 from 'aws-cdk-lib/aws-ec2';
64
import * as iam from 'aws-cdk-lib/aws-iam';
7-
import { Annotations, CustomResource, ITaggable, Lazy, TagManager, TagType } from 'aws-cdk-lib/core';
5+
import { CfnFargateProfile } from 'aws-cdk-lib/aws-eks';
6+
import { Annotations, ITaggable, TagManager, TagType } from 'aws-cdk-lib/core';
87

98
/**
109
* Options for defining EKS Fargate Profiles.
@@ -143,10 +142,6 @@ export class FargateProfile extends Construct implements ITaggable {
143142
constructor(scope: Construct, id: string, props: FargateProfileProps) {
144143
super(scope, id);
145144

146-
const provider = ClusterResourceProvider.getOrCreate(this, {
147-
onEventLayer: props.cluster.onEventLayer,
148-
});
149-
150145
this.podExecutionRole = props.podExecutionRole ?? new iam.Role(this, 'PodExecutionRole', {
151146
assumedBy: new iam.ServicePrincipal('eks-fargate-pods.amazonaws.com'),
152147
managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEKSFargatePodExecutionRolePolicy')],
@@ -174,23 +169,22 @@ export class FargateProfile extends Construct implements ITaggable {
174169

175170
this.tags = new TagManager(TagType.MAP, 'AWS::EKS::FargateProfile');
176171

177-
const resource = new CustomResource(this, 'Resource', {
178-
serviceToken: provider.serviceToken,
179-
resourceType: FARGATE_PROFILE_RESOURCE_TYPE,
180-
properties: {
181-
AssumeRoleArn: props.cluster.adminRole.roleArn,
182-
Config: {
183-
clusterName: props.cluster.clusterName,
184-
fargateProfileName: props.fargateProfileName,
185-
podExecutionRoleArn: this.podExecutionRole.roleArn,
186-
selectors: props.selectors,
187-
subnets,
188-
tags: Lazy.any({ produce: () => this.tags.renderTags() }),
189-
},
190-
},
172+
const resource = new CfnFargateProfile(this, 'Resource', {
173+
clusterName: props.cluster.clusterName,
174+
fargateProfileName: props.fargateProfileName,
175+
podExecutionRoleArn: this.podExecutionRole.roleArn,
176+
selectors: props.selectors.map((s) => ({
177+
namespace: s.namespace,
178+
labels: Object.entries(s.labels ?? {}).map((e) => ({
179+
key: e[0],
180+
value: e[1],
181+
})),
182+
})),
183+
subnets,
184+
tags: this.tags.renderTags(),
191185
});
192186

193-
this.fargateProfileArn = resource.getAttString('fargateProfileArn');
187+
this.fargateProfileArn = resource.attrArn;
194188
this.fargateProfileName = resource.ref;
195189

196190
// Fargate profiles must be created sequentially. If other profile(s) already

0 commit comments

Comments
 (0)