-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathACS::CS::FCRunCommand.yml
462 lines (461 loc) · 16.1 KB
/
ACS::CS::FCRunCommand.yml
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
FormatVersion: OOS-2019-06-01
Description:
name-en: ACS::CS::FCRunCommand
name-zh-cn: 通过函数计算服务在集群节点上执行命令
en: Run command on cluster nodes by FC
zh-cn: 通过函数计算服务在集群节点上执行命令
Parameters:
clusterId:
Description:
en: The ID of cluster
zh-cn: 集群ID
Type: String
commandContent:
Description:
en: The content of command
zh-cn: 命令内容
Type: String
AssociationProperty: Code
Tasks:
- Name: getUserKubeconfig
Action: 'ACS::ExecuteAPI'
Description:
en: Queries the Kubeconfig of specified cluster
zh-cn: 获取指定集群的Kubeconfig
Properties:
Service: CS
API: DescribeClusterV2UserKubeconfig
Method: GET
URI: '/api/v2/k8s/{{clusterId}}/user_config'
Outputs:
kubeconfig:
Type: String
ValueSelector: .config
- Name: getService
Action: 'ACS::ExecuteAPI'
Description:
en: Queries specified service's status
zh-cn: 获取指定服务的状态
OnError: getVPC
OnSuccess: createInvokerStack
Properties:
Service: FC
API: GetService
Method: GET
URI: '/services/OOS-CS-Kubectl-{{clusterId}}'
Headers: Null
Parameters:
AccountId: '{{ ACS::AccountId }}'
Body: Null
- Name: getVPC
Action: 'ACS::ExecuteAPI'
Description:
en: Queries cluster's vpc
zh-cn: 获取集群的VPC
Properties:
Service: CS
API: DescribeClusters
Method: GET
URI: '/clusters/{{clusterId}}'
Outputs:
VPCId:
Type: String
ValueSelector: .vpc_id
securityGroupId:
Type: String
ValueSelector: security_group_id
- Name: getCidrBlock
Action: 'ACS::ExecuteAPI'
Description:
en: Queries VPC's CidrBlock
zh-cn: 获取VPC的网段
Properties:
Service: VPC
API: DescribeVpcAttribute
Parameters:
VpcId: '{{ getVPC.vpcId }}'
Outputs:
cidrBlock:
Type: String
ValueSelector: .CidrBlock
- Name: createVSwitch
Action: 'ACS::ExecuteAPI'
Description:
en: Creates a VSwitch
zh-cn: 创建一个交换机
Properties:
Service: VPC
API: CreateVSwitch
Parameters:
CidrBlock:
'Fn::Join':
- .
- - 'Fn::Select':
- 0
- 'Fn::Split':
- .
- '{{ getCidrBlock.cidrBlock }}'
- 'Fn::Select':
- 1
- 'Fn::Split':
- .
- '{{ getCidrBlock.cidrBlock }}'
- '222'
- 'Fn::Join':
- /
- - 'Fn::Select':
- 0
- 'Fn::Split':
- /
- 'Fn::Select':
- 3
- 'Fn::Split':
- .
- '{{ getCidrBlock.cidrBlock }}'
- '24'
VpcId: '{{ getVPC.vpcId }}'
ZoneId:
'Fn::If':
- 'Fn::Equals':
- cn-hangzhou
- '{{ ACS::RegionId }}'
- cn-hangzhou-g
- 'Fn::If':
- 'Fn::Equals':
- cn-beijing
- '{{ ACS::RegionId }}'
- cn-beijing-c
- 'Fn::If':
- 'Fn::Equals':
- cn-shanghai
- '{{ ACS::RegionId }}'
- cn-shanghai-e
- 'Fn::If':
- 'Fn::Equals':
- cn-zhangjiakou
- '{{ ACS::RegionId }}'
- cn-zhangjiakou-b
- 'Fn::If':
- 'Fn::Equals':
- cn-huhehaote
- '{{ ACS::RegionId }}'
- cn-huhehaote-a
- 'Fn::If':
- 'Fn::Equals':
- cn-shenzhen
- '{{ ACS::RegionId }}'
- cn-shenzhen-d
- 'Fn::If':
- 'Fn::Equals':
- cn-hongkong
- '{{ ACS::RegionId }}'
- cn-hongkong-c
- 'Fn::If':
- 'Fn::Equals':
- ap-southeast-1
- '{{ ACS::RegionId }}'
- ap-southeast-1a
- 'Fn::If':
- 'Fn::Equals':
- ap-southeast-2
- '{{ ACS::RegionId }}'
- ap-southeast-2a
- 'Fn::If':
- 'Fn::Equals':
- ap-southeast-5
- '{{ ACS::RegionId }}'
- ap-southeast-5a
- 'Fn::If':
- 'Fn::Equals':
- ap-northeast-1
- '{{ ACS::RegionId }}'
- ap-northeast-1b
- 'Fn::If':
- 'Fn::Equals':
- eu-central-1
- '{{ ACS::RegionId }}'
- eu-central-1a
- 'Fn::If':
- 'Fn::Equals':
- us-east-1
- '{{ ACS::RegionId }}'
- us-east-1a
- 'Fn::If':
- 'Fn::Equals':
- ap-south-1
- '{{ ACS::RegionId }}'
- ap-south-1a
- ''
Outputs:
vSwitchId:
Type: String
ValueSelector: VSwitchId
- Name: untilVSwitchReady
Action: 'ACS::WaitFor'
Description:
en: Waits for the VSwitch to be available
zh-cn: 等待交换机到达可用状态
Properties:
Service: ECS
API: DescribeVSwitches
Parameters:
VSwitchId: '{{ createVSwitch.vSwitchId }}'
DesiredValues:
- Available
PropertySelector: 'VSwitches.VSwitch[].Status'
- Name: createStack
Action: 'ACS::ExecuteAPI'
Description:
en: Creates a resource stack
zh-cn: 创建资源栈
Properties:
Service: ROS
API: CreateStack
Parameters:
StackName: 'OOS-{{ clusterId }}'
TimeoutInMinutes: 10
DisableRollback: true
Parameters:
- ParameterKey: Event
ParameterValue:
'Fn::Base64Encode':
'Fn::Join':
- '&'
- - '{{ getUserKubeconfig.Kubeconfig }}'
- '{{ commandContent }}'
- 'wget https://oos-fc.oss-cn-beijing.aliyuncs.com/kubectl;export KUBECONFIG=/tmp/kubeconfig;chmod +x /tmp/kubectl;export PATH=$PATH:/tmp;/bin/bash /tmp/script.sh'
TemplateBody: |-
{
"ROSTemplateFormatVersion": "2015-09-01",
"Parameters": {
"ServiceName": {
"Type": "String",
"Default": "OOS-CS-Kubectl-{{ clusterId }}"
},
"FunctionName": {
"Type": "String",
"Default": "OOS-CS-Kubectl-{{ clusterId }}"
},
"ExecuteVersion": {
"Type": "Number",
"Default": 1
},
"Event": {
"Type": "String",
}
},
"Resources": {
"Service": {
"Type": "ALIYUN::FC::Service",
"Properties": {
"ServiceName": {
"Ref": "ServiceName"
},
"VpcConfig": {
"VpcId": "{{ getVPC.VPCId }}",
"SecurityGroupId": "{{ getVPC.securityGroupId }}",
"VSwitchIds": [
"{{ createVSwitch.vSwitchId }}"
]
},
"Role": "acs:ram::{{ACS::AccountId}}:role/OOSServiceRole"
}
},
"Function": {
"Type": "ALIYUN::FC::Function",
"DependsOn": "Service",
"Properties": {
"ServiceName": {
"Ref": "ServiceName"
},
"FunctionName": {
"Ref": "FunctionName"
},
"Code": {
"SourceCode": "# -*- coding: utf-8 -*- \nimport subprocess\nimport os\nimport base64\n\ndef handler(event, context):\n os.chdir('/tmp')\n event = str(base64.b64decode(event), encoding='utf-8')\n events = event.split('&')\n with open('/tmp/kubeconfig', 'w') as f:\n f.write(events[0])\n with open('/tmp/script.sh', 'w') as f:\n f.write(events[1])\n with open('/tmp/invoke.sh', 'w') as f:\n f.write(events[2])\n ret = subprocess.check_output(['bash', '/tmp/invoke.sh'])\n return ret"
},
"Handler": "index.handler",
"Runtime": "python3",
"Timeout": 180
}
},
"FunctionInvoker": {
"Type": "ALIYUN::FC::FunctionInvoker",
"DependsOn": "Function",
"Properties": {
"ServiceName": {
"Ref": "ServiceName"
},
"FunctionName": {
"Ref": "FunctionName"
},
"Async": false,
"Event": {
"Ref": "Event"
},
"ExecuteVersion": {
"Ref": "ExecuteVersion"
}
}
}
},
"Outputs": {
"Result": {
"Description": "Depends on result type:\nNoResult: Async invoke has no result.\nSuccess: The response of run function. It\u2019s in binary format. Users can interpret the data according to their function implementation.\nFailure: Error Message.",
"Value": {
"Fn::GetAtt": [
"FunctionInvoker",
"Result"
]
}
}
}
}
Outputs:
StackId:
Type: String
ValueSelector: StackId
- Name: untilStackReady
Action: 'ACS::WaitFor'
OnSuccess: 'ACS::END'
Description:
en: Waits for the stack status util CREATE_COMPLETE
zh-cn: 等待资源栈创建完成
Properties:
Service: ROS
API: GetStack
Parameters:
StackId: '{{createStack.StackId}}'
DesiredValues:
- CREATE_COMPLETE
StopRetryValues:
- CREATE_FAILED
- CHECK_FAILED
- ROLLBACK_FAILED
- ROLLBACK_COMPLETE
PropertySelector: Status
Outputs:
result:
Type: String
ValueSelector: 'Outputs[].OutputValue'
- Name: createInvokerStack
Action: 'ACS::ExecuteAPI'
Description:
en: Invokes resource stack
zh-cn: 触发执行资源栈
Properties:
Service: ROS
API: CreateStack
Parameters:
StackName: 'OOS-{{ clusterId }}-invoker'
TimeoutInMinutes: 10
DisableRollback: true
Parameters:
- ParameterKey: Event
ParameterValue:
'Fn::Base64Encode':
'Fn::Join':
- '&'
- - '{{ getUserKubeconfig.Kubeconfig }}'
- '{{ commandContent }}'
- 'wget https://oos-fc.oss-cn-beijing.aliyuncs.com/kubectl;export KUBECONFIG=/tmp/kubeconfig;chmod +x /tmp/kubectl;export PATH=$PATH:/tmp;/bin/bash /tmp/script.sh'
TemplateBody: |-
{
"ROSTemplateFormatVersion": "2015-09-01",
"Parameters": {
"ServiceName": {
"Type": "String",
"Default": "OOS-CS-Kubectl-{{ clusterId }}"
},
"FunctionName": {
"Type": "String",
"Default": "OOS-CS-Kubectl-{{ clusterId }}"
},
"ExecuteVersion": {
"Type": "Number",
"Default": 1
},
"Event": {
"Type": "String",
}
},
"Resources": {
"FunctionInvoker": {
"Type": "ALIYUN::FC::FunctionInvoker",
"Properties": {
"ServiceName": {
"Ref": "ServiceName"
},
"FunctionName": {
"Ref": "FunctionName"
},
"Async": false,
"Event": {
"Ref": "Event"
},
"ExecuteVersion": {
"Ref": "ExecuteVersion"
}
}
}
},
"Outputs": {
"Result": {
"Description": "Depends on result type:\nNoResult: Async invoke has no result.\nSuccess: The response of run function. It\u2019s in binary format. Users can interpret the data according to their function implementation.\nFailure: Error Message.",
"Value": {
"Fn::GetAtt": [
"FunctionInvoker",
"Result"
]
}
}
},
"Metadata": {
"ALIYUN::ROS::Interface": {
"TemplateTags": [
"acs:integrate:oos:cs_fc_run_command"
]
}
}
}
Outputs:
StackId:
Type: String
ValueSelector: StackId
- Name: untilInvokerStackReady
Action: 'ACS::WaitFor'
OnError: deleteStack
Description:
en: Waits for the stack status util CREATE_COMPLETE
zh-cn: 等待资源栈到达CREATE_COMPLETE状态
Properties:
Service: ROS
API: GetStack
Parameters:
StackId: '{{createInvokerStack.StackId}}'
DesiredValues:
- CREATE_COMPLETE
StopRetryValues:
- CREATE_FAILED
- CHECK_FAILED
- ROLLBACK_FAILED
- ROLLBACK_COMPLETE
PropertySelector: Status
Outputs:
result:
Type: String
ValueSelector: 'Outputs[].OutputValue'
- Name: deleteStack
Action: 'ACS::ExecuteApi'
Description:
en: Deletes the stack
zh-cn: 删除资源栈
Properties:
Service: ROS
API: DeleteStack
Parameters:
StackId: '{{ createInvokerStack.StackId }}'
Outputs:
invokeResult:
Type: String
Value: '{{ untilInvokerStackReady.result }}'