1
+ import * as cdk from 'aws-cdk-lib' ;
2
+ import * as eks from 'aws-cdk-lib/aws-eks' ;
3
+ import { IConstruct } from 'constructs' ;
4
+ import { Easy_EKS_Config_Data } from "./Easy_EKS_Config_Data" ;
5
+
6
+ export interface Podinfo_Helm_Config {
7
+ helm_chart_version : string ,
8
+ helm_chart_release : string ,
9
+ helm_chart_values ?: Record < string , any > | undefined ,
10
+ }
11
+
12
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
13
+ export class Podinfo_HELM_Generator {
14
+
15
+ config : Easy_EKS_Config_Data ;
16
+ cluster : eks . Cluster ;
17
+ release : string ;
18
+
19
+ // Plausible Values to expect:
20
+ constructor ( input_parmeters : Partial < Podinfo_HELM_Generator > ) {
21
+ Object . assign ( this , input_parmeters ) ;
22
+ }
23
+
24
+ generate_manifests ( ) : Podinfo_Helm_Config {
25
+ let config = this . config ;
26
+ let cluster = this . cluster ;
27
+
28
+ const array_of_yaml_manifests_to_return = {
29
+ helm_chart_release : this . release ,
30
+ }
31
+
32
+ return array_of_yaml_manifests_to_return as Podinfo_Helm_Config ;
33
+ } //end generate_manifests
34
+
35
+ } //end class Podinfo_YAML_Generator
36
+
37
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
38
+ const Podinfo_Http_Ingress_Yaml_Generator = ( serviceName : string , servicePort : number ) : Record < string , any > => {
39
+ return {
40
+ "apiVersion" : "networking.k8s.io/v1" ,
41
+ "kind" : "Ingress" ,
42
+ "metadata" : {
43
+ "name" : `${ serviceName } -ingress` ,
44
+ "namespace" : "default" ,
45
+ "annotations" : {
46
+ "kubernetes.io/ingress.class" : "alb" ,
47
+ "alb.ingress.kubernetes.io/scheme" : "internet-facing" ,
48
+ "alb.ingress.kubernetes.io/target-type" : "ip" ,
49
+ "alb.ingress.kubernetes.io/group.name" : serviceName ,
50
+ "alb.ingress.kubernetes.io/ip-address-type" : "dualstack" ,
51
+ "alb.ingress.kubernetes.io/listen-ports" : '[{"HTTP": 80}]' ,
52
+ "alb.ingress.kubernetes.io/backend-protocol" : "HTTP" ,
53
+
54
+ } ,
55
+ "labels" : {
56
+ "app" : `${ serviceName } -ingress`
57
+ }
58
+ } ,
59
+ "spec" : {
60
+ "rules" : [
61
+ {
62
+ "http" : {
63
+ "paths" : [
64
+ {
65
+ "path" : "/" ,
66
+ "pathType" : "Prefix" ,
67
+ "backend" : {
68
+ "service" : {
69
+ "name" : serviceName ,
70
+ "port" : {
71
+ "number" : servicePort ,
72
+ }
73
+ } ,
74
+ }
75
+ }
76
+ ]
77
+ }
78
+ }
79
+ ]
80
+ }
81
+ } as Record < string , any > ;
82
+ }
83
+
84
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85
+ const Podinfo_Https_Ingress_Yaml_Generator = ( serviceName : string , servicePort : number , certificateArn : string , host : string ) : Record < string , any > => {
86
+ return {
87
+ "apiVersion" : "networking.k8s.io/v1" ,
88
+ "kind" : "Ingress" ,
89
+ "metadata" : {
90
+ "name" : `${ serviceName } -ingress` ,
91
+ "namespace" : "default" ,
92
+ "annotations" : {
93
+ "kubernetes.io/ingress.class" : "alb" ,
94
+ "alb.ingress.kubernetes.io/scheme" : "internet-facing" ,
95
+ "alb.ingress.kubernetes.io/target-type" : "ip" ,
96
+ "alb.ingress.kubernetes.io/group.name" : serviceName ,
97
+ "alb.ingress.kubernetes.io/ip-address-type" : "dualstack" ,
98
+ "alb.ingress.kubernetes.io/listen-ports" : '[{"HTTP": 80}, {"HTTPS": 443}]' ,
99
+ "alb.ingress.kubernetes.io/backend-protocol" : "HTTP" ,
100
+ "alb.ingress.kubernetes.io/actions.ssl-redirect" : '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}' ,
101
+ "alb.ingress.kubernetes.io/certificate-arn" : certificateArn
102
+ } ,
103
+ "labels" : {
104
+ "app" : `${ serviceName } -ingress`
105
+ }
106
+ } ,
107
+ "spec" : {
108
+ "rules" : [
109
+ {
110
+ "host" : host ,
111
+ "http" : {
112
+ "paths" : [
113
+ {
114
+ "path" : "/" ,
115
+ "pathType" : "Prefix" ,
116
+ "backend" : {
117
+ "service" : {
118
+ "name" : serviceName ,
119
+ "port" : {
120
+ "number" : servicePort ,
121
+ }
122
+ } ,
123
+ }
124
+ }
125
+ ]
126
+ }
127
+ }
128
+ ]
129
+ }
130
+ } as Record < string , any > ;
131
+ }
132
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
133
+ const Apply_Podinfo_YAMLs = ( stack : cdk . Stack , cluster : eks . Cluster ,
134
+ config : Easy_EKS_Config_Data ,
135
+ podinfo_helm_config : Podinfo_Helm_Config ,
136
+ readiness_dependency : IConstruct | undefined = undefined ) => {
137
+ if ( readiness_dependency ) {
138
+ cluster . node . addDependency ( readiness_dependency ) ;
139
+ }
140
+
141
+ cluster . addHelmChart ( `podinfo_${ podinfo_helm_config . helm_chart_release } ` , {
142
+ repository : "https://stefanprodan.github.io/podinfo" ,
143
+ chart : "podinfo" ,
144
+ release : podinfo_helm_config . helm_chart_release ,
145
+ version : podinfo_helm_config . helm_chart_version || "6.9.0" ,
146
+ values : {
147
+ ...podinfo_helm_config . helm_chart_values ,
148
+ } ,
149
+ } )
150
+
151
+ } //end function Apply_Podinfo_YAMLs
152
+
153
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
154
+ export function Apply_Podinfo_Http_YAMLs ( stack : cdk . Stack , cluster : eks . Cluster ,
155
+ config : Easy_EKS_Config_Data ,
156
+ podinfo_helm_config : Podinfo_Helm_Config ,
157
+ readiness_dependency : IConstruct | undefined = undefined ) {
158
+
159
+
160
+ Apply_Podinfo_YAMLs ( stack , cluster , config , podinfo_helm_config , readiness_dependency ) ;
161
+ const apply_podinfo_ingress_YAML = new eks . KubernetesManifest ( stack , `${ podinfo_helm_config . helm_chart_release } -podinfo-ingress` ,
162
+ {
163
+ cluster : cluster ,
164
+ manifest : [ Podinfo_Http_Ingress_Yaml_Generator ( `${ podinfo_helm_config . helm_chart_release } -podinfo` , 9898 ) ] ,
165
+ overwrite : true ,
166
+ prune : true ,
167
+ }
168
+ ) ;
169
+ if ( readiness_dependency ) {
170
+ apply_podinfo_ingress_YAML . node . addDependency ( readiness_dependency ) ;
171
+ }
172
+ apply_podinfo_ingress_YAML . node . addDependency ( cluster . awsAuth ) ;
173
+ } //end function Apply_Podinfo_Http_YAMLs
174
+
175
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
176
+ export function Apply_Podinfo_Https_YAMLs ( stack : cdk . Stack , cluster : eks . Cluster ,
177
+ config : Easy_EKS_Config_Data ,
178
+ podinfo_helm_config : Podinfo_Helm_Config ,
179
+ readiness_dependency : IConstruct | undefined = undefined ) {
180
+
181
+ Apply_Podinfo_YAMLs ( stack , cluster , config , podinfo_helm_config , readiness_dependency ) ;
182
+ const apply_podinfo_ingress_YAML = new eks . KubernetesManifest ( stack , `${ podinfo_helm_config . helm_chart_release } -podinfo-ingress` ,
183
+ {
184
+ cluster : cluster ,
185
+ manifest : [
186
+ Podinfo_Https_Ingress_Yaml_Generator (
187
+ `${ podinfo_helm_config . helm_chart_release } -podinfo` ,
188
+ 9898 ,
189
+ "arn:aws:acm:ap-southeast-2:092464092456:certificate/a2e016d5-58fb-4308-b894-f7a21f7df0b8" ,
190
+ "kefeng-easyeks.gcp.au-pod-1.cs.doit-playgrounds.dev" ) ] ,
191
+ overwrite : true ,
192
+ prune : true ,
193
+ }
194
+ ) ;
195
+ if ( readiness_dependency ) {
196
+ apply_podinfo_ingress_YAML . node . addDependency ( readiness_dependency ) ;
197
+ }
198
+ apply_podinfo_ingress_YAML . node . addDependency ( cluster . awsAuth ) ;
199
+ } //end function Apply_Podinfo_Https_YAMLs
200
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
0 commit comments