-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy patheks-blueprint-stack.ts
88 lines (75 loc) · 3.21 KB
/
eks-blueprint-stack.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as spi from '../spi';
import * as utils from '../utils';
import {BlueprintConstructBuilder, EksBlueprintConstruct, EksBlueprintProps} from "./eks-blueprint-construct";
/**
* Blueprint builder implements a builder pattern that improves readability (no bloated constructors)
* and allows creating a blueprint in an abstract state that can be applied to various instantiations
* in accounts and regions.
*/
export class BlueprintBuilder extends BlueprintConstructBuilder implements spi.AsyncStackBuilder {
constructor() {
super();
this.props = { ...this.props, ...{ compatibilityMode: true } };
}
public clone(region?: string, account?: string): BlueprintBuilder {
return new BlueprintBuilder().withBlueprintProps(this.props)
.account(account ?? this.env.account).region(region ?? this.env.region);
}
public build(scope: Construct, id: string, stackProps?: cdk.StackProps): EksBlueprint {
return new EksBlueprint(scope, { ...this.props, ...{ id } },
{ ...{ env: this.env }, ...stackProps });
}
/**
* Sets compatibility mode
* @param compatibilityMode if true will attach blueprints resources directly to the stack.
* @returns
*/
public compatibilityMode(compatibilityMode: boolean): BlueprintBuilder {
this.props = { ...this.props, ...{ compatibilityMode } };
return this;
}
public async buildAsync(scope: Construct, id: string, stackProps?: cdk.StackProps): Promise<EksBlueprint> {
return this.build(scope, id, stackProps).waitForAsyncTasks();
}
}
/**
* Entry point to the platform provisioning. Creates a CFN stack based on the provided configuration
* and orchestrates provisioning of add-ons, teams and post deployment hooks.
*/
export class EksBlueprint extends cdk.Stack {
static readonly USAGE_ID = "qs-1s1r465hk";
private asyncTasks: Promise<void | Construct[]>;
private clusterInfo: spi.ClusterInfo;
public static builder(): BlueprintBuilder {
return new BlueprintBuilder();
}
constructor(scope: Construct, blueprintProps: EksBlueprintProps, props?: cdk.StackProps) {
super(scope, blueprintProps.id, utils.withUsageTracking(EksBlueprint.USAGE_ID, props));
const eksBlueprintConstruct = new EksBlueprintConstruct(this, blueprintProps);
this.clusterInfo = eksBlueprintConstruct.getClusterInfo();
this.asyncTasks = eksBlueprintConstruct.getAsyncTasks();
}
/**
* Since constructor cannot be marked as async, adding a separate method to wait
* for async code to finish.
* @returns Promise that resolves to the blueprint
*/
public async waitForAsyncTasks(): Promise<EksBlueprint> {
if (this.asyncTasks) {
return this.asyncTasks.then(() => {
return this;
});
}
return Promise.resolve(this);
}
/**
* This method returns all the constructs produced by during the cluster creation (e.g. add-ons).
* May be used in testing for verification.
* @returns cluster info object
*/
getClusterInfo(): spi.ClusterInfo {
return this.clusterInfo;
}
}