From 2a5f3392e53f40098e88c0b5b6b57a372dc96c81 Mon Sep 17 00:00:00 2001 From: guessi Date: Wed, 3 Aug 2022 23:56:07 +0800 Subject: [PATCH] fix(eks): missing question marks cause update cluster setting failure introduced by #21185 Fixes: #21436 --- .../lib/cluster-resource-handler/cluster.ts | 4 +- .../test/cluster-resource-provider.test.ts | 108 +++++++++++++++++- 2 files changed, 109 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-eks/lib/cluster-resource-handler/cluster.ts b/packages/@aws-cdk/aws-eks/lib/cluster-resource-handler/cluster.ts index d7e66c7c79961..dfafd02d4c291 100644 --- a/packages/@aws-cdk/aws-eks/lib/cluster-resource-handler/cluster.ts +++ b/packages/@aws-cdk/aws-eks/lib/cluster-resource-handler/cluster.ts @@ -286,11 +286,11 @@ function parseProps(props: any): aws.EKS.CreateClusterRequest { parsed.resourcesVpcConfig.endpointPublicAccess = parsed.resourcesVpcConfig.endpointPublicAccess === 'true'; } - if (typeof (parsed.logging?.clusterLogging[0].enabled) === 'string') { + if (typeof (parsed.logging?.clusterLogging[0]?.enabled) === 'string') { parsed.logging.clusterLogging[0].enabled = parsed.logging.clusterLogging[0].enabled === 'true'; } - if (typeof (parsed.logging?.clusterLogging[1].enabled) === 'string') { + if (typeof (parsed.logging?.clusterLogging[1]?.enabled) === 'string') { parsed.logging.clusterLogging[1].enabled = parsed.logging.clusterLogging[1].enabled === 'false'; } diff --git a/packages/@aws-cdk/aws-eks/test/cluster-resource-provider.test.ts b/packages/@aws-cdk/aws-eks/test/cluster-resource-provider.test.ts index 7a486cc67600f..53f3c15285579 100644 --- a/packages/@aws-cdk/aws-eks/test/cluster-resource-provider.test.ts +++ b/packages/@aws-cdk/aws-eks/test/cluster-resource-provider.test.ts @@ -558,7 +558,41 @@ describe('cluster resource provider', () => { }); describe('logging or access change', () => { - test('from undefined to partial logging enabled', async () => { + test('from undefined to partial logging enabled case 1', async () => { + const handler = new ClusterResourceHandler(mocks.client, mocks.newRequest('Update', { + logging: { + clusterLogging: [ + { + types: ['api'], + enabled: true, + }, + ], + }, + }, { + logging: undefined, + })); + const resp = await handler.onEvent(); + expect(resp).toEqual({ EksUpdateId: mocks.MOCK_UPDATE_STATUS_ID }); + expect(mocks.actualRequest.updateClusterConfigRequest!).toEqual({ + name: 'physical-resource-id', + logging: { + clusterLogging: [ + { + types: ['api'], + enabled: true, + }, + { + types: ['audit', 'authenticator', 'controllerManager', 'scheduler'], + enabled: false, + }, + ], + }, + }); + expect(mocks.actualRequest.createClusterRequest).toEqual(undefined); + + }); + + test('from undefined to partial logging enabled case 2', async () => { const handler = new ClusterResourceHandler(mocks.client, mocks.newRequest('Update', { logging: { clusterLogging: [ @@ -596,6 +630,78 @@ describe('cluster resource provider', () => { }); + test('from undefined to partial logging enabled case 3', async () => { + const handler = new ClusterResourceHandler(mocks.client, mocks.newRequest('Update', { + logging: { + clusterLogging: [ + { + types: ['api', 'audit'], + enabled: true, + }, + { + types: ['authenticator', 'controllerManager', 'scheduler'], + enabled: false, + }, + ], + }, + }, { + logging: undefined, + })); + const resp = await handler.onEvent(); + expect(resp).toEqual({ EksUpdateId: mocks.MOCK_UPDATE_STATUS_ID }); + expect(mocks.actualRequest.updateClusterConfigRequest!).toEqual({ + name: 'physical-resource-id', + logging: { + clusterLogging: [ + { + types: ['api', 'audit'], + enabled: true, + }, + { + types: ['authenticator', 'controllerManager', 'scheduler'], + enabled: false, + }, + ], + }, + }); + expect(mocks.actualRequest.createClusterRequest).toEqual(undefined); + + }); + + test('from undefined to partial logging enabled case 4', async () => { + const handler = new ClusterResourceHandler(mocks.client, mocks.newRequest('Update', { + logging: { + clusterLogging: [ + { + types: ['api', 'audit'], + enabled: true, + }, + ], + }, + }, { + logging: undefined, + })); + const resp = await handler.onEvent(); + expect(resp).toEqual({ EksUpdateId: mocks.MOCK_UPDATE_STATUS_ID }); + expect(mocks.actualRequest.updateClusterConfigRequest!).toEqual({ + name: 'physical-resource-id', + logging: { + clusterLogging: [ + { + types: ['api', 'audit'], + enabled: true, + }, + { + types: ['authenticator', 'controllerManager', 'scheduler'], + enabled: false, + }, + ], + }, + }); + expect(mocks.actualRequest.createClusterRequest).toEqual(undefined); + + }); + test('from partial vpc configuration to only private access enabled', async () => { const handler = new ClusterResourceHandler(mocks.client, mocks.newRequest('Update', { resourcesVpcConfig: {