Skip to content

Commit

Permalink
fix(eks): missing question marks cause update cluster setting failure
Browse files Browse the repository at this point in the history
introduced by aws#21185

Fixes: aws#21436
  • Loading branch information
guessi committed Aug 3, 2022
1 parent 48178ac commit 2a5f339
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand Down
108 changes: 107 additions & 1 deletion packages/@aws-cdk/aws-eks/test/cluster-resource-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 2a5f339

Please sign in to comment.