@@ -11,6 +11,7 @@ import * as cdk8s from 'cdk8s';
11
11
import * as constructs from 'constructs' ;
12
12
import * as YAML from 'yaml' ;
13
13
import * as eks from '../lib' ;
14
+ import { HelmChart } from '../lib' ;
14
15
import { KubectlProvider } from '../lib/kubectl-provider' ;
15
16
import { BottleRocketImage } from '../lib/private/bottlerocket' ;
16
17
import { testFixture , testFixtureNoVpc } from './util' ;
@@ -2422,43 +2423,77 @@ describe('cluster', () => {
2422
2423
2423
2424
} ) ;
2424
2425
2425
- test ( 'kubectl provider passes iam role environment to kube ctl lambda' , ( ) => {
2426
+ describe ( 'kubectl provider passes iam role environment to kube ctl lambda' , ( ) => {
2427
+ test ( 'new cluster' , ( ) => {
2426
2428
2427
- const { stack } = testFixture ( ) ;
2429
+ const { stack } = testFixture ( ) ;
2428
2430
2429
- const kubectlRole = new iam . Role ( stack , 'KubectlIamRole' , {
2430
- assumedBy : new iam . ServicePrincipal ( 'lambda.amazonaws.com' ) ,
2431
- } ) ;
2431
+ const kubectlRole = new iam . Role ( stack , 'KubectlIamRole' , {
2432
+ assumedBy : new iam . ServicePrincipal ( 'lambda.amazonaws.com' ) ,
2433
+ } ) ;
2432
2434
2433
- // using _ syntax to silence warning about _cluster not being used, when it is
2434
- const cluster = new eks . Cluster ( stack , 'Cluster1' , {
2435
- version : CLUSTER_VERSION ,
2436
- prune : false ,
2437
- endpointAccess : eks . EndpointAccess . PRIVATE ,
2438
- kubectlLambdaRole : kubectlRole ,
2439
- } ) ;
2435
+ // using _ syntax to silence warning about _cluster not being used, when it is
2436
+ const cluster = new eks . Cluster ( stack , 'Cluster1' , {
2437
+ version : CLUSTER_VERSION ,
2438
+ prune : false ,
2439
+ endpointAccess : eks . EndpointAccess . PRIVATE ,
2440
+ kubectlLambdaRole : kubectlRole ,
2441
+ } ) ;
2440
2442
2441
- cluster . addManifest ( 'resource' , {
2442
- kind : 'ConfigMap' ,
2443
- apiVersion : 'v1' ,
2444
- data : {
2445
- hello : 'world' ,
2446
- } ,
2447
- metadata : {
2448
- name : 'config-map' ,
2449
- } ,
2450
- } ) ;
2443
+ cluster . addManifest ( 'resource' , {
2444
+ kind : 'ConfigMap' ,
2445
+ apiVersion : 'v1' ,
2446
+ data : {
2447
+ hello : 'world' ,
2448
+ } ,
2449
+ metadata : {
2450
+ name : 'config-map' ,
2451
+ } ,
2452
+ } ) ;
2453
+
2454
+ // the kubectl provider is inside a nested stack.
2455
+ const nested = stack . node . tryFindChild ( '@aws-cdk/aws-eks.KubectlProvider' ) as cdk . NestedStack ;
2456
+ Template . fromStack ( nested ) . hasResourceProperties ( 'AWS::Lambda::Function' , {
2457
+ Role : {
2458
+ Ref : 'referencetoStackKubectlIamRole02F8947EArn' ,
2459
+ } ,
2460
+ } ) ;
2451
2461
2452
- // the kubectl provider is inside a nested stack.
2453
- const nested = stack . node . tryFindChild ( '@aws-cdk/aws-eks.KubectlProvider' ) as cdk . NestedStack ;
2454
- Template . fromStack ( nested ) . hasResourceProperties ( 'AWS::Lambda::Function' , {
2455
- Role : {
2456
- Ref : 'referencetoStackKubectlIamRole02F8947EArn' ,
2457
- } ,
2458
2462
} ) ;
2463
+ test ( 'imported cluster' , ( ) => {
2459
2464
2460
- } ) ;
2465
+ const clusterName = 'my-cluster' ;
2466
+ const stack = new cdk . Stack ( ) ;
2467
+ const kubectlLambdaRole = new iam . Role ( stack , 'KubectlLambdaRole' , {
2468
+ assumedBy : new iam . ServicePrincipal ( 'lambda.amazonaws.com' ) ,
2469
+ } ) ;
2470
+ const cluster = eks . Cluster . fromClusterAttributes ( stack , 'Imported' , {
2471
+ clusterName,
2472
+ kubectlRoleArn : 'arn:aws:iam::1111111:role/iam-role-that-has-masters-access' ,
2473
+ kubectlLambdaRole : kubectlLambdaRole ,
2474
+ } ) ;
2475
+
2476
+ const chart = 'hello-world' ;
2477
+ cluster . addHelmChart ( 'test-chart' , {
2478
+ chart,
2479
+ } ) ;
2461
2480
2481
+ const nested = stack . node . tryFindChild ( 'Imported-KubectlProvider' ) as cdk . NestedStack ;
2482
+ Template . fromStack ( nested ) . hasResourceProperties ( 'AWS::Lambda::Function' , {
2483
+ Role : {
2484
+ Ref : 'referencetoKubectlLambdaRole7D084D94Arn' ,
2485
+ } ,
2486
+ } ) ;
2487
+ Template . fromStack ( stack ) . hasResourceProperties ( HelmChart . RESOURCE_TYPE , {
2488
+ ClusterName : clusterName ,
2489
+ RoleArn : 'arn:aws:iam::1111111:role/iam-role-that-has-masters-access' ,
2490
+ Release : 'importedcharttestchartf3acd6e5' ,
2491
+ Chart : chart ,
2492
+ Namespace : 'default' ,
2493
+ CreateNamespace : true ,
2494
+ } ) ;
2495
+ } ) ;
2496
+ } ) ;
2462
2497
describe ( 'endpoint access' , ( ) => {
2463
2498
2464
2499
test ( 'public restricted' , ( ) => {
0 commit comments