Skip to content

Commit ba2dfd1

Browse files
authoredMar 5, 2025
fix(eks): cluster deployment issue when the authentication mode is not changing (#33680)
### Reason for this change The issue happens in a very small edge case: 1. create a eks.Cluster like this ``` new eks.Cluster(this, 'Cluster', { version: eks.KubernetesVersion.V1_32, kubectlLayer: new KubectlV32Layer(this, 'KubectlLayer'), }); ``` 2. In EKS console, modify the Auth model from CONFIG_MAP to API_AND_CONFIG_MAP, wait a few minutes until it completes. 3. Again, update from API_AND_CONFIG_MAP to API from console, wait until it completes 4. Now in CDK, add ``` authenticationMode: eks.AuthenticationMode.API, ``` 5. When we re-deploy, CDK would have a validation error: ``` Received response status [FAILED] from custom resource. Message returned: Cannot update from undefined(CONFIG_MAP) to API ``` It is because in local template, the auth mode is `Config_Map` while the actual resource is using `API` mode. In this case, cdk deployment should ignore the update instead of throwing an error. ### Description of changes Move the code order a little bit. Basically check if the updated auth mode is the same as existing mode first then do some validations. ### Description of how you validated changes Existing unit tests/integration tests passed. I removed 2 unit tests which are not applicable because `DescribeCluster` api call will always return auth mode. Manually tested the change in the edge case. ### Checklist - [ ] 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 50ba3ef commit ba2dfd1

File tree

3 files changed

+13
-41
lines changed

3 files changed

+13
-41
lines changed
 

‎packages/@aws-cdk/custom-resource-handlers/lib/aws-eks/cluster-resource-handler/cluster.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,18 @@ export class ClusterResourceHandler extends ResourceHandler {
218218
}
219219

220220
if (updates.updateAuthMode) {
221+
// update-authmode will fail if we try to update to the same mode,
222+
// so skip in this case.
223+
try {
224+
const cluster = (await this.eks.describeCluster({ name: this.clusterName })).cluster;
225+
if (cluster?.accessConfig?.authenticationMode === this.newProps.accessConfig?.authenticationMode) {
226+
console.log(`cluster already at ${cluster?.accessConfig?.authenticationMode}, skipping authMode update`);
227+
return;
228+
}
229+
} catch (e: any) {
230+
throw e;
231+
}
232+
221233
// the update path must be
222234
// `undefined or CONFIG_MAP` -> `API_AND_CONFIG_MAP` -> `API`
223235
// and it's one way path.
@@ -247,17 +259,6 @@ export class ClusterResourceHandler extends ResourceHandler {
247259
this.newProps.accessConfig?.authenticationMode === 'API') {
248260
throw new Error('Cannot update from CONFIG_MAP to API');
249261
}
250-
// update-authmode will fail if we try to update to the same mode,
251-
// so skip in this case.
252-
try {
253-
const cluster = (await this.eks.describeCluster({ name: this.clusterName })).cluster;
254-
if (cluster?.accessConfig?.authenticationMode === this.newProps.accessConfig?.authenticationMode) {
255-
console.log(`cluster already at ${cluster?.accessConfig?.authenticationMode}, skipping authMode update`);
256-
return;
257-
}
258-
} catch (e: any) {
259-
throw e;
260-
}
261262
config.accessConfig = this.newProps.accessConfig;
262263
}
263264

‎packages/@aws-cdk/custom-resource-handlers/test/aws-eks/cluster-resource-handler-mocks.ts

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export const client: EksClient = {
9090
arn: 'arn:cluster-arn',
9191
certificateAuthority: { data: 'certificateAuthority-data' },
9292
endpoint: 'http://endpoint',
93+
accessConfig: { authenticationMode: 'CONFIG_MAP' },
9394
status: simulateResponse.describeClusterResponseMockStatus || 'ACTIVE',
9495
},
9596
};

‎packages/@aws-cdk/custom-resource-handlers/test/aws-eks/cluster-resource-provider.test.ts

-30
Original file line numberDiff line numberDiff line change
@@ -590,21 +590,6 @@ describe('cluster resource provider', () => {
590590

591591
expect(error.message).toEqual('Cannot fallback authenticationMode from defined to undefined');
592592
});
593-
test('fails from API_AND_CONFIG_MAP to CONFIG_MAP', async () => {
594-
const handler = new ClusterResourceHandler(mocks.client, mocks.newRequest('Update', {
595-
accessConfig: { authenticationMode: 'CONFIG_MAP' },
596-
}, {
597-
accessConfig: { authenticationMode: 'API_AND_CONFIG_MAP' },
598-
}));
599-
let error: any;
600-
try {
601-
await handler.onEvent();
602-
} catch (e) {
603-
error = e;
604-
}
605-
606-
expect(error.message).toEqual('Cannot fallback authenticationMode from API_AND_CONFIG_MAP to CONFIG_MAP');
607-
});
608593
test('fails from API to undefined', async () => {
609594
const handler = new ClusterResourceHandler(mocks.client, mocks.newRequest('Update', {
610595
accessConfig: { authenticationMode: undefined },
@@ -635,21 +620,6 @@ describe('cluster resource provider', () => {
635620

636621
expect(error.message).toEqual('Cannot fallback authenticationMode from API to API_AND_CONFIG_MAP');
637622
});
638-
test('fails from API to CONFIG_MAP', async () => {
639-
const handler = new ClusterResourceHandler(mocks.client, mocks.newRequest('Update', {
640-
accessConfig: { authenticationMode: 'CONFIG_MAP' },
641-
}, {
642-
accessConfig: { authenticationMode: 'API' },
643-
}));
644-
let error: any;
645-
try {
646-
await handler.onEvent();
647-
} catch (e) {
648-
error = e;
649-
}
650-
651-
expect(error.message).toEqual('Cannot fallback authenticationMode from API to CONFIG_MAP');
652-
});
653623
test('fails from undefined to API', async () => {
654624
const handler = new ClusterResourceHandler(mocks.client, mocks.newRequest('Update', {
655625
accessConfig: { authenticationMode: 'API' },

0 commit comments

Comments
 (0)
Failed to load comments.