Skip to content

Commit b831188

Browse files
committed
Add coverage/integ test & refactor using EKS L2 Construct
1 parent fb639aa commit b831188

File tree

7 files changed

+1691
-79
lines changed

7 files changed

+1691
-79
lines changed

packages/@aws-cdk/aws-stepfunctions-tasks/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,11 +678,20 @@ The service integration APIs correspond to Amazon EKS APIs.
678678
Read and write Kubernetes resource objects via a Kubernetes API endpoint.
679679
Corresponds to the [`call`](https://docs.aws.amazon.com/step-functions/latest/dg/connect-eks.html) API in Step Functions Connector.
680680

681+
The following code snippet includes a Task state that uses eks:call to list the pods.
682+
681683
```ts
684+
import * as eks from '@aws-cdk/aws-eks';
685+
import * as sfn from '@aws-cdk/aws-stepfunctions';
686+
import * as tasks from '@aws-cdk/aws-stepfunctions-tasks';
687+
688+
const myEksCluster = new eks.Cluster(this, 'my sample cluster', {
689+
version: eks.KubernetesVersion.V1_18,
690+
clusterName: 'myEksCluster',
691+
});
692+
682693
new tasks.EksCall(stack, 'Call a EKS Endpoint', {
683-
clusterName: 'clusterName',
684-
certificateAuthority: 'certificateAuthority',
685-
endpoint: 'https://apiid.gr7.us-east-1.eks.amazonaws.com',
694+
cluster: myEksCluster,
686695
httpMethod: MethodType.GET,
687696
path: '/api/v1/namespaces/default/pods',
688697
});

packages/@aws-cdk/aws-stepfunctions-tasks/lib/eks/call.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
1+
import * as eks from '@aws-cdk/aws-eks';
12
import * as iam from '@aws-cdk/aws-iam';
23
import * as sfn from '@aws-cdk/aws-stepfunctions';
34
import { Construct } from 'constructs';
45
import { integrationResourceArn, validatePatternSupported } from '../private/task-utils';
56

67
/**
78
* Properties for calling a EKS endpoint with EksCall
9+
* @experimental
810
*/
911
export interface EksCallProps extends sfn.TaskStateBaseProps {
1012

1113
/**
12-
* Name of the cluster
14+
* The EKS cluster
1315
*/
14-
readonly clusterName: string;
15-
16-
/**
17-
* Base 64 encoded certificate data required to communicate with your cluster
18-
*/
19-
readonly certificateAuthority: string;
20-
21-
/**
22-
* API endpoint to communicate with your cluster
23-
*/
24-
readonly endpoint: string;
16+
readonly cluster: eks.ICluster;
2517

2618
/**
2719
* HTTP method ("GET", "POST", "PUT", ...) part of HTTP request
2820
*/
29-
readonly httpMethod: MethodType;
21+
readonly httpMethod: HttpMethods;
3022

3123
/**
32-
* Path of cluster
24+
* HTTP path of the Kubernetes REST API operation
3325
*/
34-
readonly path: string;
26+
readonly httpPath: string;
3527

3628
/**
3729
* Query Parameters part of HTTP request
@@ -50,6 +42,7 @@ export interface EksCallProps extends sfn.TaskStateBaseProps {
5042
* Call a EKS endpoint as a Task
5143
*
5244
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-eks.html
45+
* @experimental
5346
*/
5447
export class EksCall extends sfn.TaskStateBase {
5548

@@ -77,11 +70,11 @@ export class EksCall extends sfn.TaskStateBase {
7770
return {
7871
Resource: integrationResourceArn('eks', 'call', this.integrationPattern),
7972
Parameters: sfn.FieldUtils.renderObject({
80-
ClusterName: this.props.clusterName,
81-
CertificateAuthority: this.props.certificateAuthority,
82-
Endpoint: this.props.endpoint,
73+
ClusterName: this.props.cluster.clusterName,
74+
CertificateAuthority: this.props.cluster.clusterCertificateAuthorityData,
75+
Endpoint: this.props.cluster.clusterEndpoint,
8376
Method: this.props.httpMethod,
84-
Path: this.props.path,
77+
Path: this.props.httpPath,
8578
QueryParameters: this.props.queryParameters,
8679
RequestBody: this.props.requestBody,
8780
}),
@@ -92,7 +85,7 @@ export class EksCall extends sfn.TaskStateBase {
9285
/**
9386
* Method type of a EKS call
9487
*/
95-
export enum MethodType {
88+
export enum HttpMethods {
9689
/**
9790
* Retrieve data from a server at the specified resource
9891
*/

packages/@aws-cdk/aws-stepfunctions-tasks/lib/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export * from './dynamodb/update-item';
3939
export * from './dynamodb/delete-item';
4040
export * from './dynamodb/shared-types';
4141
export * from './codebuild/start-build';
42-
export * from './eks/call';
4342
export * from './athena/start-query-execution';
4443
export * from './athena/stop-query-execution';
4544
export * from './athena/get-query-execution';

packages/@aws-cdk/aws-stepfunctions-tasks/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"@aws-cdk/aws-ecr": "0.0.0",
8282
"@aws-cdk/aws-ecr-assets": "0.0.0",
8383
"@aws-cdk/aws-ecs": "0.0.0",
84+
"@aws-cdk/aws-eks": "0.0.0",
8485
"@aws-cdk/aws-glue": "0.0.0",
8586
"@aws-cdk/aws-iam": "0.0.0",
8687
"@aws-cdk/aws-kms": "0.0.0",
@@ -103,6 +104,7 @@
103104
"@aws-cdk/aws-ecr": "0.0.0",
104105
"@aws-cdk/aws-ecr-assets": "0.0.0",
105106
"@aws-cdk/aws-ecs": "0.0.0",
107+
"@aws-cdk/aws-eks": "0.0.0",
106108
"@aws-cdk/aws-glue": "0.0.0",
107109
"@aws-cdk/aws-iam": "0.0.0",
108110
"@aws-cdk/aws-kms": "0.0.0",
Lines changed: 92 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,103 @@
1+
import * as eks from '@aws-cdk/aws-eks';
12
import * as sfn from '@aws-cdk/aws-stepfunctions';
2-
import * as cdk from '@aws-cdk/core';
3-
import { EksCall, MethodType } from '../../lib/eks/call';
3+
import { Stack } from '@aws-cdk/core';
4+
import { EksCall, HttpMethods } from '../../lib/eks/call';
45

5-
describe('Call an EKS endpoint', () => {
6+
let stack: Stack;
7+
let cluster: eks.Cluster;
68

7-
test('default settings', () => {
8-
// GIVEN
9-
const stack = new cdk.Stack();
9+
beforeEach(() => {
10+
//GIVEN
11+
stack = new Stack();
12+
cluster = new eks.Cluster(stack, 'Cluster', {
13+
version: eks.KubernetesVersion.V1_18,
14+
clusterName: 'eksCluster',
15+
});
16+
});
1017

11-
// WHEN
12-
const task = new EksCall(stack, 'Call', {
13-
clusterName: 'clusterName',
14-
certificateAuthority: 'certificateAuthority',
15-
endpoint: 'endpoint',
16-
httpMethod: MethodType.GET,
17-
path: 'path',
18-
requestBody: sfn.TaskInput.fromObject({
19-
RequestBody: 'requestBody',
20-
}),
21-
});
18+
test('Call an EKS endpoint', () => {
19+
// WHEN
20+
const task = new EksCall(stack, 'Call', {
21+
cluster: cluster,
22+
httpMethod: HttpMethods.GET,
23+
httpPath: 'path',
24+
requestBody: sfn.TaskInput.fromObject({
25+
RequestBody: 'requestBody',
26+
}),
27+
});
2228

23-
// THEN
24-
expect(stack.resolve(task.toStateJson())).toEqual({
25-
Type: 'Task',
26-
Resource: {
27-
'Fn::Join': [
28-
'',
29-
[
30-
'arn:',
31-
{
32-
Ref: 'AWS::Partition',
33-
},
34-
':states:::eks:call',
35-
],
29+
// THEN
30+
expect(stack.resolve(task.toStateJson())).toEqual({
31+
Type: 'Task',
32+
Resource: {
33+
'Fn::Join': [
34+
'',
35+
[
36+
'arn:',
37+
{
38+
Ref: 'AWS::Partition',
39+
},
40+
':states:::eks:call',
3641
],
42+
],
43+
},
44+
End: true,
45+
Parameters: {
46+
ClusterName: {
47+
Ref: 'Cluster9EE0221C',
3748
},
38-
End: true,
39-
Parameters: {
40-
ClusterName: 'clusterName',
41-
CertificateAuthority: 'certificateAuthority',
42-
Endpoint: 'endpoint',
43-
Method: 'GET',
44-
Path: 'path',
45-
RequestBody: {
46-
type: 1,
47-
value: {
48-
RequestBody: 'requestBody',
49-
},
49+
CertificateAuthority: {
50+
'Fn::GetAtt': [
51+
'Cluster9EE0221C',
52+
'CertificateAuthorityData',
53+
],
54+
},
55+
Endpoint: {
56+
'Fn::GetAtt': [
57+
'Cluster9EE0221C',
58+
'Endpoint',
59+
],
60+
},
61+
Method: 'GET',
62+
Path: 'path',
63+
RequestBody: {
64+
type: 1,
65+
value: {
66+
RequestBody: 'requestBody',
5067
},
5168
},
52-
});
69+
},
5370
});
71+
});
72+
73+
test('Task throws if RUN_JOB is supplied as service integration pattern', () => {
74+
expect(() => {
75+
new EksCall(stack, 'Call', {
76+
cluster: cluster,
77+
httpMethod: HttpMethods.GET,
78+
httpPath: 'path',
79+
requestBody: sfn.TaskInput.fromObject({
80+
RequestBody: 'requestBody',
81+
}),
82+
integrationPattern: sfn.IntegrationPattern.RUN_JOB,
83+
});
84+
}).toThrow(
85+
/Unsupported service integration pattern. Supported Patterns: REQUEST_RESPONSE. Received: RUN_JOB/,
86+
);
87+
});
88+
89+
test('Task throws if WAIT_FOR_TASK_TOKEN is supplied as service integration pattern', () => {
90+
expect(() => {
91+
new EksCall(stack, 'Call', {
92+
cluster: cluster,
93+
httpMethod: HttpMethods.GET,
94+
httpPath: 'path',
95+
requestBody: sfn.TaskInput.fromObject({
96+
RequestBody: 'requestBody',
97+
}),
98+
integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN,
99+
});
100+
}).toThrow(
101+
/Unsupported service integration pattern. Supported Patterns: REQUEST_RESPONSE. Received: WAIT_FOR_TASK_TOKEN/,
102+
);
54103
});

0 commit comments

Comments
 (0)