1
1
/* eslint-disable no-console */
2
2
3
3
// eslint-disable-next-line import/no-extraneous-dependencies
4
- import { ResourceNotFoundException } from '@aws-sdk/client-eks' ;
5
- // eslint-disable-next-line import/no-extraneous-dependencies
6
- import * as aws from 'aws-sdk' ;
4
+ import * as EKS from '@aws-sdk/client-eks' ;
7
5
import { EksClient , ResourceEvent , ResourceHandler } from './common' ;
8
6
import { compareLoggingProps } from './compareLogging' ;
9
7
import { IsCompleteResponse , OnEventResponse } from '../../../custom-resources/lib/provider-framework/types' ;
@@ -19,16 +17,16 @@ export class ClusterResourceHandler extends ResourceHandler {
19
17
return this . physicalResourceId ;
20
18
}
21
19
22
- private readonly newProps : aws . EKS . CreateClusterRequest ;
23
- private readonly oldProps : Partial < aws . EKS . CreateClusterRequest > ;
20
+ private readonly newProps : EKS . CreateClusterCommandInput ;
21
+ private readonly oldProps : Partial < EKS . CreateClusterCommandInput > ;
24
22
25
23
constructor ( eks : EksClient , event : ResourceEvent ) {
26
24
super ( eks , event ) ;
27
25
28
26
this . newProps = parseProps ( this . event . ResourceProperties ) ;
29
27
this . oldProps = event . RequestType === 'Update' ? parseProps ( event . OldResourceProperties ) : { } ;
30
28
// compare newProps and oldProps and update the newProps by appending disabled LogSetup if any
31
- const compared : Partial < aws . EKS . CreateClusterRequest > = compareLoggingProps ( this . oldProps , this . newProps ) ;
29
+ const compared : Partial < EKS . CreateClusterCommandInput > = compareLoggingProps ( this . oldProps , this . newProps ) ;
32
30
this . newProps . logging = compared . logging ;
33
31
}
34
32
@@ -71,7 +69,7 @@ export class ClusterResourceHandler extends ResourceHandler {
71
69
try {
72
70
await this . eks . deleteCluster ( { name : this . clusterName } ) ;
73
71
} catch ( e : any ) {
74
- if ( ! ( e instanceof ResourceNotFoundException ) ) {
72
+ if ( ! ( e instanceof EKS . ResourceNotFoundException ) ) {
75
73
throw e ;
76
74
} else {
77
75
console . log ( `cluster ${ this . clusterName } not found, idempotently succeeded` ) ;
@@ -90,7 +88,7 @@ export class ClusterResourceHandler extends ResourceHandler {
90
88
console . log ( 'describeCluster returned:' , JSON . stringify ( resp , undefined , 2 ) ) ;
91
89
} catch ( e : any ) {
92
90
// see https://aws.amazon.com/blogs/developer/service-error-handling-modular-aws-sdk-js/
93
- if ( e instanceof ResourceNotFoundException ) {
91
+ if ( e instanceof EKS . ResourceNotFoundException ) {
94
92
console . log ( 'received ResourceNotFoundException, this means the cluster has been deleted (or never existed)' ) ;
95
93
return { IsComplete : true } ;
96
94
}
@@ -147,7 +145,7 @@ export class ClusterResourceHandler extends ResourceHandler {
147
145
}
148
146
149
147
if ( updates . updateLogging || updates . updateAccess ) {
150
- const config : aws . EKS . UpdateClusterConfigRequest = {
148
+ const config : EKS . UpdateClusterConfigCommandInput = {
151
149
name : this . clusterName ,
152
150
} ;
153
151
if ( updates . updateLogging ) {
@@ -158,9 +156,9 @@ export class ClusterResourceHandler extends ResourceHandler {
158
156
// https://awscli.amazonaws.com/v2/documentation/api/latest/reference/eks/update-cluster-config.html)
159
157
// will fail, therefore we take only the access fields explicitly
160
158
config . resourcesVpcConfig = {
161
- endpointPrivateAccess : this . newProps . resourcesVpcConfig . endpointPrivateAccess ,
162
- endpointPublicAccess : this . newProps . resourcesVpcConfig . endpointPublicAccess ,
163
- publicAccessCidrs : this . newProps . resourcesVpcConfig . publicAccessCidrs ,
159
+ endpointPrivateAccess : this . newProps . resourcesVpcConfig ? .endpointPrivateAccess ,
160
+ endpointPublicAccess : this . newProps . resourcesVpcConfig ? .endpointPublicAccess ,
161
+ publicAccessCidrs : this . newProps . resourcesVpcConfig ? .publicAccessCidrs ,
164
162
} ;
165
163
}
166
164
const updateResponse = await this . eks . updateClusterConfig ( config ) ;
@@ -241,7 +239,7 @@ export class ClusterResourceHandler extends ResourceHandler {
241
239
OpenIdConnectIssuer : cluster . identity ?. oidc ?. issuer ?. substring ( 8 ) ?? '' , // Strips off https:// from the issuer url
242
240
243
241
// We can safely return the first item from encryption configuration array, because it has a limit of 1 item
244
- // https://docs.aws. amazon.com/eks/latest/APIReference/API_CreateCluster.html#AmazonEKS-CreateCluster-request-encryptionConfig
242
+ // https://docs.amazon.com/eks/latest/APIReference/API_CreateCluster.html#AmazonEKS-CreateCluster-request-encryptionConfig
245
243
EncryptionConfigKeyArn : cluster . encryptionConfig ?. shift ( ) ?. provider ?. keyArn ?? '' ,
246
244
} ,
247
245
} ;
@@ -283,7 +281,7 @@ export class ClusterResourceHandler extends ResourceHandler {
283
281
}
284
282
}
285
283
286
- function parseProps ( props : any ) : aws . EKS . CreateClusterRequest {
284
+ function parseProps ( props : any ) : EKS . CreateClusterCommandInput {
287
285
288
286
const parsed = props ?. Config ?? { } ;
289
287
@@ -317,7 +315,7 @@ interface UpdateMap {
317
315
updateAccess : boolean ; // resourcesVpcConfig.endpointPrivateAccess and endpointPublicAccess
318
316
}
319
317
320
- function analyzeUpdate ( oldProps : Partial < aws . EKS . CreateClusterRequest > , newProps : aws . EKS . CreateClusterRequest ) : UpdateMap {
318
+ function analyzeUpdate ( oldProps : Partial < EKS . CreateClusterCommandInput > , newProps : EKS . CreateClusterCommandInput ) : UpdateMap {
321
319
console . log ( 'old props: ' , JSON . stringify ( oldProps ) ) ;
322
320
console . log ( 'new props: ' , JSON . stringify ( newProps ) ) ;
323
321
0 commit comments