-
Notifications
You must be signed in to change notification settings - Fork 12
/
datamodel.kubernetes.xml
6780 lines (6647 loc) · 201 KB
/
datamodel.kubernetes.xml
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8"?>
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">
<constants>
</constants>
<classes>
<class id="Kubernetes" _delta="define">
<parent>cmdbAbstractObject</parent>
<properties>
<category>bizmodel,searchable</category>
<abstract>true</abstract>
<key_type>autoincrement</key_type>
<db_table>kubernetes</db_table>
<db_key_field>id</db_key_field>
<db_final_class_field>finalclass</db_final_class_field>
<naming>
<attributes>
<attribute id="k8snamespace_name"/>
<attribute id="applicationsolution_name"/>
</attributes>
</naming>
<display_template/>
<icon>images/kubernetes.png</icon>
<reconciliation>
<attributes>
<attribute id="org_id"/>
<attribute id="organization_name"/>
<attribute id="finalclass"/>
<attribute id="friendlyname"/>
</attributes>
</reconciliation>
</properties>
<fields>
<field id="k8snamespace_id" xsi:type="AttributeExternalKey">
<sql>k8snamespace_id</sql>
<target_class>K8sNamespace</target_class>
<is_null_allowed>false</is_null_allowed>
<on_target_delete>DEL_MANUAL</on_target_delete>
<allow_target_creation>false</allow_target_creation>
</field>
<field id="k8snamespace_name" xsi:type="AttributeExternalField">
<extkey_attcode>k8snamespace_id</extkey_attcode>
<target_attcode>name</target_attcode>
</field>
<field id="k8snamespace_type" xsi:type="AttributeExternalField">
<extkey_attcode>k8snamespace_id</extkey_attcode>
<target_attcode>lbtype</target_attcode>
</field>
<field id="applicationsolution_id" xsi:type="AttributeExternalKey">
<sql>applicationsolution_id</sql>
<target_class>ApplicationSolution</target_class>
<is_null_allowed>false</is_null_allowed>
<filter>SELECT ApplicationSolution AS app JOIN lnkContactToApplicationSolution AS l ON l.applicationsolution_id = app.id WHERE app.status='production' AND l.contact_id = :current_contact_id</filter>
<on_target_delete>DEL_MANUAL</on_target_delete>
<allow_target_creation>false</allow_target_creation>
</field>
<field id="applicationsolution_name" xsi:type="AttributeExternalField">
<extkey_attcode>applicationsolution_id</extkey_attcode>
<target_attcode>name</target_attcode>
</field>
<field id="applicationsolution_contact" xsi:type="AttributeExternalField">
<extkey_attcode>applicationsolution_id</extkey_attcode>
<target_attcode>contacts</target_attcode>
</field>
<field id="applicationsolution_business" xsi:type="AttributeExternalField">
<extkey_attcode>applicationsolution_id</extkey_attcode>
<target_attcode>businessprocess_id</target_attcode>
</field>
<field id="status" xsi:type="AttributeEnum">
<values>
<value id="new">new</value>
<value id="production">production</value>
<value id="error">error</value>
<value id="stock">stock</value>
</values>
<sql>status</sql>
<default_value>new</default_value>
<is_null_allowed>false</is_null_allowed>
<display_style>list</display_style>
</field>
<field id="flag_kubestatus" xsi:type="AttributeString">
<sql>flag_kubestatus</sql>
<default_value>MANUAL</default_value>
<is_null_allowed>true</is_null_allowed>
<tracking_level>none</tracking_level>
</field>
<field id="description" xsi:type="AttributeText">
<sql>description</sql>
<default_value/>
<is_null_allowed>true</is_null_allowed>
</field>
<field id="org_id" xsi:type="AttributeExternalKey">
<sql>org_id</sql>
<target_class>Organization</target_class>
<is_null_allowed>false</is_null_allowed>
<on_target_delete>DEL_MANUAL</on_target_delete>
<filter>SELECT Organization WHERE id = :current_contact->org_id</filter>
</field>
<field id="organization_name" xsi:type="AttributeExternalField">
<extkey_attcode>org_id</extkey_attcode>
<target_attcode>name</target_attcode>
</field>
<field id="move2production" xsi:type="AttributeDate">
<sql>move2production</sql>
<default_value/>
<is_null_allowed>true</is_null_allowed>
</field>
<field id="person_list" xsi:type="AttributeLinkedSetIndirect">
<linked_class>lnkPersonToKubernetes</linked_class>
<ext_key_to_me>kubernetes_id</ext_key_to_me>
<count_min>0</count_min>
<count_max>0</count_max>
<ext_key_to_remote>person_id</ext_key_to_remote>
<duplicates/>
</field>
<field id="update" xsi:type="AttributeString">
<sql>update</sql>
<default_value/>
<is_null_allowed>true</is_null_allowed>
</field>
<field id="change_log" xsi:type="AttributeText">
<sql>change_log</sql>
<default_value/>
<is_null_allowed>true</is_null_allowed>
</field>
</fields>
<methods>
<method id="ComputeValues" _delta="define">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<code><![CDATA[
public function ComputeValues()
{
$aChanges = $this->ListChanges();
// 点击更新,如果不变更任何属性,aChanges为空,可以根据这里决定是否更新update字段,达到 1.避免联系人更新时错误的更新部署 2. 使更新功能正常使用
// 注意这段代码位置不能更改,因为下面设置person_list的代码总会导致aChanges包含 person_list
if(!(count($aChanges) == 1 && array_key_exists("person_list", $aChanges))) {
$this->Set("update", date("Y-m-d H:i:s"));
}
if(MetaModel::IsValidKeyAttCode($this->Get('finalclass'), 'applicationsolution_id') && $this->Get('applicationsolution_id') > 0)
{
$app = MetaModel::GetObject('ApplicationSolution', $this->Get('applicationsolution_id'));
$this->Set("org_id", $app->Get("org_id"));
// 根据关联的APP自动填充联系人字段
$list = $app->Get('contact_list_custom');
// ormLinkSet需要设置oOriginalSet
$oOriginalSet = DBObjectSet::FromScratch('lnkPersonToKubernetes');
$c = new ormLinkSet('Kubernetes', 'person_list', $oOriginalSet);
foreach($list as $v)
{
$p = new lnkPersonToKubernetes();
$p->Set('person_id', $v->Get('contact_id'));
$p->Set('kubernetes_id', $this->GetKey());
$c->AddItem($p);
}
$this->Set('person_list', $c);
}
else {
$this->Set("org_id", UserRights::GetContactObject()->Get('org_id'));
}
return parent::ComputeValues();
}
]]>
</code>
</method>
<method id="isAllowedModifyCustom" _delta="define">
<static>false</static>
<access>public</access>
<type>Custom</type>
<code><![CDATA[
public function isAllowedModifyCustom()
{
if($this->IsNew()) {
return true;
}
$myContactId = UserRights::GetContactId();
// Deployment和Ingress使用lnkPersonToKubernetes的person_list会有延迟(依赖UpdateKubernetesContacts的执行间隔),因此使用ApplicationSolution的contact_list)
// Secret, SideCar, AppTemplate使用 person_list 做权限判断
$useList = ['Secret', 'SideCar', 'AppTemplate', 'SideCarVer', 'AppTemplateVer'];
if(!in_array($this->Get('finalclass'), $useList))
{
$app = MetaModel::GetObject('ApplicationSolution', $this->Get('applicationsolution_id'));
$person_list = $app->Get('contact_list_custom');
$key = 'contact_id';
}
else
{
$person_list = $this->Get('person_list');
$key = 'person_id';
}
$contacts = array();
foreach($person_list as $v) {
$contacts[] = $v->Get($key);
}
if(!in_array($myContactId, $contacts) && !UserRights::IsAdministrator())
{
return false;
}
else
{
return(true);
}
}
]]>
</code>
</method>
<method id="ReloadAndDisplayCustom" _delta="define">
<static>false</static>
<access>public</access>
<type>Custom</type>
<code><![CDATA[
function ReloadAndDisplayCustom($oPage, $oObj, $sMessageId = '', $sMessage = '', $sSeverity = null)
{
$oAppContext = new ApplicationContext();
if ($sMessageId != '')
{
cmdbAbstractObject::SetSessionMessage(get_class($oObj), $oObj->GetKey(), $sMessageId, $sMessage, $sSeverity, 0, true /* must not exist */);
}
$oId = $oObj->getKey();
$oPage->add_header('Location: '.utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=details&class='.get_class($oObj).'&id='.$oId.'&'.$oAppContext->GetForLink());
}
]]>
</code>
</method>
<method id="DisplayDetails" _delta="define">
<static>false</static>
<access>public</access>
<type>Overload-cmdbAbstractObject</type>
<code><![CDATA[
public function DisplayDetails(WebPage $oPage, $bEditMode = false) {
$sAppRoot = utils::GetAbsoluteUrlAppRoot();
$sHighlightTheme = MetaModel::GetModuleSetting('kubernetes', 'highlight_theme', 'vs2015');
$oPage->add_linked_script($sAppRoot . 'env-production/kubernetes/js/functions.js');
$oPage->add_linked_script($sAppRoot . 'env-production/kubernetes/js/highlightjs/highlight.pack.js');
$oPage->add_linked_stylesheet($sAppRoot . 'env-production/kubernetes/js/highlightjs/styles/' . $sHighlightTheme . '.css');
$oPage->add_ready_script("KubernetesHighlight();");
$sStatus = Dict::S("Class:Kubernetes/Attribute:status/Value:production");
$oPage->add_ready_script("KubernetesStatusHighlight('$sStatus');");
parent::DisplayDetails($oPage, $bEditMode);
}
]]></code>
</method>
<method id="AceEditor" _delta="define">
<static>false</static>
<access>public</access>
<type>Custom</type>
<code><![CDATA[
public function AceEditor($oPage) {
$sAppRoot = utils::GetAbsoluteUrlAppRoot();
$sAceMinHeight = MetaModel::GetModuleSetting('kubernetes', 'ace_editor_minHeight', '300px');
$sAceTheme = MetaModel::GetModuleSetting('kubernetes', 'ace_editor_theme', 'xcode');
$oPage->add_linked_script($sAppRoot . 'env-production/kubernetes/js/ace/ace.js');
$oPage->add_linked_script($sAppRoot . 'env-production/kubernetes/js/ace/mode-yaml.js');
$oPage->add_linked_script($sAppRoot . 'env-production/kubernetes/js/ace/theme-' . $sAceTheme . '.js');
$oPage->add_linked_script($sAppRoot . 'env-production/kubernetes/js/functions.js');
$oPage->add_linked_script($sAppRoot . 'env-production/kubernetes/js/jquery.fullscreen-min.js');
// 需在parent::DisplayModifyForm之后执行,否则无法取消原fullscreen事件
$oPage->add_ready_script("KubernetesAceInit('$sAceMinHeight','$sAceTheme');");
}
]]>
</code>
</method>
<method id="DisplayModifyForm" _delta="define">
<static>false</static>
<access>public</access>
<type>Overload-cmdbAbstractObject</type>
<code><![CDATA[
public function DisplayModifyForm(WebPage $oPage, $aExtraParams = array())
{
if(!$this->isAllowedModifyCustom())
{
$sMesg = Dict::Format("Class:Kubernetes/Error:CanOnlyUpdateK8SObjYourself", $this->Get('friendlyname'));
self::ReloadAndDisplayCustom($oPage, $this, 'k8s-modify-not-allowd', $sMesg, 'info');
}
else
{
parent::DisplayModifyForm($oPage, $aExtraParams);
}
self::AceEditor($oPage);
}
]]>
</code>
</method>
<method id="DisplayStimulusForm" _delta="define">
<static>false</static>
<access>public</access>
<type>Overload-cmdbAbstractObject</type>
<code><![CDATA[
public function DisplayStimulusForm(WebPage $oPage, $sStimulus, $aPrefillFormParam = null)
{
parent::DisplayStimulusForm($oPage, $sStimulus, $aPrefillFormParam);
self::AceEditor($oPage);
}
]]>
</code>
</method>
<method id="DoCheckToWrite" _delta="define">
<static>false</static>
<access>protected</access>
<type>Overload-DBObject</type>
<code><![CDATA[ public function DoCheckToWrite()
{
parent::DoCheckToWrite();
// 不允许修改非自己名下的对象
if(!$this->isAllowedModifyCustom())
{
$this->m_aCheckIssues[] = Dict::Format("Class:Kubernetes/Error:CanOnlyUpdateK8SObjYourself", $this->Get('friendlyname'));
}
// friendlyname has to be unique! Currently it' not possible to define this in datamodel (xml)
$finalclass = $this->Get('finalclass');
$nameSpec = MetaModel::GetNameSpec(get_class($this));
$sFormat = preg_replace('/%[1-9]\$s/', '%s', $nameSpec['0']);
$sArg = $nameSpec['1'];
$oArg = array();
/*
* 如果组成friendlyname的所有attribute都没有发生变化,那么不进行检查
* 如果不监听变化就进行检查,将导致对象无法更新
*/
$aChanges = $this->ListChanges();
$isChanges = false;
foreach($aChanges as $key=>$value)
{
if(in_array($key, $sArg))
{
$isChanges = true;
}
}
foreach($sArg as $value) {
array_push($oArg, $this->Get($value));
}
$sTypology = vsprintf("$sFormat", $oArg);
if($isChanges) {
$oSearch = DBObjectSearch::FromOQL_AllData("SELECT $finalclass WHERE friendlyname=:friendlyname");
$oSet = new DBObjectSet($oSearch, array(), array('friendlyname' => $sTypology));
if ($oSet->Count() > 0)
{
$this->m_aCheckIssues[] = Dict::Format("Class:Kubernetes/Error:MustBeUnique", $sTypology, Dict::S("Class:$finalclass"));
}
}
// kubernetes action如果执行报错,将kubestatus设置为对应颜色代码,并设置 flag_kubestatus 为大于1的值
// 如果 kubestatus 和 flag_kubestatus 都没有被更新,说明是人工操作,那么将 flag_kubestatus 还原为 0
// flag_kubestatus 用来防止循环执行Kubernetes对象更新action,如果 flag_kubestatus 大于0,那么kubernetes action将直接退出
if(!array_key_exists("flag_kubestatus", $aChanges)) {
$this->Set('flag_kubestatus', 'MANUAL');
}
}]]></code>
</method>
<method id="CheckToDelete" _delta="define">
<static>false</static>
<access>protected</access>
<type>Overload-DBObject</type>
<code><![CDATA[
public function CheckToDelete(&$oDeletionPlan)
{
if($this->Get('status') != "stock") {
// 不允许删除非下线状态的对象
$oDeletionPlan->AddToDelete($this, null);
$oDeletionPlan->SetDeletionIssues($this, array('在线状态的对象不允许直接删除'), true);
$oDeletionPlan->ComputeResults();
return false;
}
if(!$this->isAllowedModifyCustom()) {
// 普通用户不允许删除非自己名下的Kubernetes对象
$oDeletionPlan->AddToDelete($this, null);
$oDeletionPlan->SetDeletionIssues($this, array('只能删除自己名下的对象'), true);
$oDeletionPlan->ComputeResults();
return false;
}
return parent::CheckToDelete($oDeletionPlan);
}
]]></code>
</method>
</methods>
<presentation>
<details>
<items>
<item id="org_id">
<rank>10</rank>
</item>
</items>
</details>
<search>
<items>
<item id="org_id">
<rank>10</rank>
</item>
</items>
</search>
<list>
<items>
<item id="org_id">
<rank>10</rank>
</item>
</items>
</list>
</presentation>
</class>
<class id="Controller" _delta="define">
<parent>Kubernetes</parent>
<properties>
<category>bizmodel,searchable</category>
<abstract>true</abstract>
<key_type>autoincrement</key_type>
<db_table>controller</db_table>
<db_key_field>id</db_key_field>
<db_final_class_field>finalclass</db_final_class_field>
<naming>
<attributes>
<attribute id="k8snamespace_name"/>
<attribute id="applicationsolution_name"/>
</attributes>
</naming>
<display_template/>
<icon>images/deployment.png</icon>
<reconciliation>
<attributes>
<attribute id="k8snamespace_id"/>
<attribute id="applicationsolution_id"/>
<attribute id="friendlyname"/>
</attributes>
</reconciliation>
</properties>
<fields>
<field id="image" xsi:type="AttributeString">
<sql>image</sql>
<default_value/>
<validation_pattern>^[a-z0-9\./\-]+$</validation_pattern>
<is_null_allowed>false</is_null_allowed>
</field>
<field id="image_tag" xsi:type="AttributeString">
<sql>image_tag</sql>
<default_value/>
<is_null_allowed>true</is_null_allowed>
</field>
<field id="repo" xsi:type="AttributeString">
<sql>repo</sql>
<default_value/>
<is_null_allowed>true</is_null_allowed>
</field>
<field id="containerport" xsi:type="AttributeString">
<sql>containerport</sql>
<default_value>80</default_value>
<is_null_allowed>false</is_null_allowed>
</field>
<field id="replicas" xsi:type="AttributeInteger">
<sql>replicas</sql>
<default_value>3</default_value>
<is_null_allowed>false</is_null_allowed>
</field>
<field id="fix_replicas" xsi:type="AttributeEnum">
<values>
<value id="true">true</value>
<value id="false">false</value>
</values>
<sql>fix_replicas</sql>
<default_value>false</default_value>
<is_null_allowed>false</is_null_allowed>
<display_style>list</display_style>
</field>
<field id="secret" xsi:type="AttributeText">
<sql>secret</sql>
<is_null_allowed>true</is_null_allowed>
<default_value/>
<tracking_level>all</tracking_level>
</field>
<field id="cpu_request" xsi:type="AttributeDecimal">
<sql>cpu_request</sql>
<default_value>0.1</default_value>
<is_null_allowed>false</is_null_allowed>
<digits>4</digits>
<decimals>2</decimals>
</field>
<field id="cpu_limit" xsi:type="AttributeDecimal">
<sql>cpu_limit</sql>
<default_value>0.1</default_value>
<is_null_allowed>false</is_null_allowed>
<digits>4</digits>
<decimals>2</decimals>
</field>
<field id="mem_request" xsi:type="AttributeInteger">
<sql>mem_request</sql>
<default_value>128</default_value>
<is_null_allowed>false</is_null_allowed>
</field>
<field id="affinity_list" xsi:type="AttributeLinkedSetIndirect">
<linked_class>lnkK8sAffinityToController</linked_class>
<ext_key_to_me>controller_id</ext_key_to_me>
<count_min>0</count_min>
<count_max>0</count_max>
<ext_key_to_remote>k8saffinity_id</ext_key_to_remote>
<duplicates/>
</field>
<field id="volume_list" xsi:type="AttributeLinkedSetIndirect">
<linked_class>lnkK8sVolumeToController</linked_class>
<ext_key_to_me>controller_id</ext_key_to_me>
<count_min>0</count_min>
<count_max>0</count_max>
<ext_key_to_remote>k8svolume_id</ext_key_to_remote>
<duplicates/>
</field>
<field id="probe_list" xsi:type="AttributeLinkedSetIndirect">
<linked_class>lnkK8sProbeToController</linked_class>
<ext_key_to_me>controller_id</ext_key_to_me>
<count_min>0</count_min>
<count_max>0</count_max>
<ext_key_to_remote>k8sprobe_id</ext_key_to_remote>
<duplicates/>
</field>
<field id="hostnetwork" xsi:type="AttributeEnum">
<values>
<value id="true">true</value>
<value id="false">false</value>
</values>
<sql>hostnetwork</sql>
<default_value>false</default_value>
<is_null_allowed>false</is_null_allowed>
<display_style>list</display_style>
</field>
<field id="rolling_strategy" xsi:type="AttributeString">
<sql>rolling_strategy</sql>
<default_value/>
<validation_pattern>^[0-9]+%?:[0-9]+%?$</validation_pattern>
<is_null_allowed>true</is_null_allowed>
</field>
<field id="hostaliases" xsi:type="AttributeText">
<sql>hostaliases</sql>
<default_value/>
<is_null_allowed>true</is_null_allowed>
</field>
<field id="command" xsi:type="AttributeString">
<sql>command</sql>
<default_value/>
<is_null_allowed>true</is_null_allowed>
</field>
<field id="args" xsi:type="AttributeString">
<sql>args</sql>
<default_value/>
<is_null_allowed>true</is_null_allowed>
</field>
<field id="prestop" xsi:type="AttributeInteger">
<sql>prestop</sql>
<default_value>45</default_value>
<is_null_allowed>true</is_null_allowed>
</field>
<field id="sidecar_list" xsi:type="AttributeLinkedSetIndirect">
<linked_class>lnkSideCarVerToController</linked_class>
<ext_key_to_me>controller_id</ext_key_to_me>
<count_min>0</count_min>
<count_max>0</count_max>
<ext_key_to_remote>sidecarver_id</ext_key_to_remote>
<duplicates/>
</field>
</fields>
<methods>
<method id="RecordAttChange" _delta="define">
<static>false</static>
<access>protected</access>
<type>Overload-DBObject</type>
<code><![CDATA[
protected function RecordAttChange($sAttCode, $original, $value) {
if($sAttCode == "secret") {
require_once dirname(__FILE__) . "/composer/vendor/autoload.php";
$differ = new SebastianBergmann\Diff\Differ;
$oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
if ($oAttDef->IsExternalField()) return;
if ($oAttDef->IsLinkSet()) return;
if ($oAttDef->GetTrackingLevel() == ATTRIBUTE_TRACKING_NONE) return;
$oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeHTML");
$oMyChangeOp->Set("objclass", get_class($this));
$oMyChangeOp->Set("objkey", $this->GetKey());
$oMyChangeOp->Set("attcode", $sAttCode);
if (!is_null($original) && ($original instanceof ormCaseLog))
{
$original = $original->GetText();
}
$prevdata = $differ->diff($original, $value);
$prevdata = '<pre><code class="diff">' . $prevdata . '</code></pre>';
$oMyChangeOp->Set("prevdata", $prevdata);
$iId = $oMyChangeOp->DBInsertNoReload();
} else {
parent::RecordAttChange($sAttCode, $original, $value);
}
}
]]>
</code>
</method>
<method id="DoCheckToWrite" _delta="define">
<static>false</static>
<access>protected</access>
<type>Overload-DBObject</type>
<code><![CDATA[
public function DoCheckToWrite()
{
// 保留名称
$default_reserve = array($this->Get('k8snamespace_name') . "-router", 'default-http-backend');
$reserve = MetaModel::GetModuleSetting('kubernetes', 'reserve', $default_reserve);
$reserve = array_merge($default_reserve, $reserve);
if(in_array($this->Get('applicationsolution_name'), $reserve)) {
$this->m_aCheckIssues[] = Dict::Format("Class:Controller/Error:ReservedAppNameNotAllowed", $this->Get('applicationsolution_name'));
}
// 检查secret是否是yaml格式
$yaml = $this->Get('secret');
if($yaml) {
$parsed = @yaml_parse($yaml);
if(!is_array($parsed)) {
$this->m_aCheckIssues[] = Dict::Format("Class:Controller/Error:SecretShouldBeYamlFormat", $this->Get('applicationsolution_name'));
}
}
// 检查command args格式
if($this->Get('command')) {
if(!is_array(json_decode($this->Get('command'), true))) {
$this->m_aCheckIssues[] = Dict::Format("Class:Controller/Error:CommandAndArgsShouldBeArray", 'e.g ["command", "-c", "config.ini"]');
}
}
if($this->Get('args')) {
if(!is_array(json_decode($this->Get('args'), true))) {
$this->m_aCheckIssues[] = Dict::Format("Class:Controller/Error:CommandAndArgsShouldBeArray", 'e.g ["command", "-c", "config.ini"]');
}
}
// 检查hostaliases
$hosts = $this->Get('hostaliases');
if($hosts) {
$parsed = @yaml_parse($hosts);
if(!is_array($parsed)) {
$this->m_aCheckIssues[] = Dict::Format("Class:Controller/Error:hostaliasesShouldBeYamlFormat", $this->Get('hostaliases'));
} else {
// k8s hostaliases域名校验正则为:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*
foreach($parsed as $domain => $ip) {
if(!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$this->m_aCheckIssues[] = Dict::Format("Class:Controller/Error:IpIsInvalid", $ip);
}
if(!preg_match('/^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$/', $domain)) {
$this->m_aCheckIssues[] = Dict::Format("Class:Controller/Error:DomainIsInvalid", $domain);
}
}
}
}
// cpu_limit >= cpu_request
if($this->Get('cpu_limit') < $this->Get('cpu_request')) {
$this->m_aCheckIssues[] = Dict::Format("Class:Controller/Error:CpuLimitCanNotLessThanCpuRequest", $this->Get('cpu_limit'));
}
// maxSurge maxUnavailable不能同时为0
$strategy = $this->Get("rolling_strategy");
if($strategy) {
$s = str_replace("%", "", $strategy);
$arr = explode(":",$s);
if($arr[0] == 0 && $arr[1] == 0) {
$this->m_aCheckIssues[] = Dict::Format("Class:Controller/Error:maxSurgeAndmaxUnavailableCannotBeZeroBoth", $this->Get('rolling_strategy'));
}
}
// 检查probe
foreach($this->Get('probe_list') as $probe) {
$probe->DoCheckToWrite();
$probeArray = get_object_vars($probe);
if(!$probeArray['m_aCheckIssues']) continue;
foreach($probeArray['m_aCheckIssues'] as $issue) {
$this->m_aCheckIssues[] = $issue;
}
}
// 检查volume
foreach($this->Get('volume_list') as $volume) {
$volume->DoCheckToWrite();
$volumeArray = get_object_vars($volume);
if(!$volumeArray['m_aCheckIssues']) continue;
foreach($volumeArray['m_aCheckIssues'] as $issue) {
$this->m_aCheckIssues[] = $issue;
}
}
// 检查sidecar_list,production的namespace不允许链接非production的sidecar
foreach($this->Get('sidecar_list') as $sidecar) {
$check = $sidecar->checkStatus($this->Get('k8snamespace_id'));
if($check) {
$this->m_aCheckIssues[] = $check;
}
}
// 检查containerport是否为数字
$ports = explode(",", $this->Get('containerport'));
foreach($ports as $val) {
if(!ctype_digit($val)) {
$this->m_aCheckIssues[] = Dict::Format("Class:Controller/Error:ContainerPortMustBeInteger", $val);
}
$port = (int) $val;
if($port < 1 || $port > 65535) {
$this->m_aCheckIssues[] = Dict::Format("Class:Controller/Error:ContainerPortRange", $val);
}
}
parent::DoCheckToWrite();
}
]]>
</code>
</method>
<method id="GetAttributeFlags" _delta="define">
<static>false</static>
<access>public</access>
<type>Overload-iDisplay</type>
<code><![CDATA[
// 不允许修改组成friendlyname的属性
public function GetAttributeFlags($sAttCode, &$aReasons = array(), $sTargetState = '')
{
// 权限控制,不允许查看非自己名下Controller的Secret数据
if(!$this->IsNew() && $sAttCode == 'secret')
{
$myContactId = UserRights::GetContactId();
$person_list = $this->Get('person_list');
$contacts = array();
foreach($person_list as $v) {
$contacts[] = $v->Get('person_id');
}
if(!in_array($myContactId, $contacts) && !UserRights::IsAdministrator())
{
return OPT_ATT_HIDDEN;
}
}
// hostnetwork 只允许管理员配置
if(!UserRights::IsAdministrator() && $sAttCode == 'hostnetwork') {
return OPT_ATT_READONLY;
}
$sArg = array('k8snamespace_id','applicationsolution_id');
if (!$this->IsNew() && in_array($sAttCode, $sArg))
{
return OPT_ATT_READONLY;
}
else
{
return parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState);
}
}
]]>
</code>
</method>
<method id="DisplayBareHistory" _delta="define">
<static>false</static>
<access>public</access>
<type>Overload-iDisplay</type>
<code><![CDATA[
// 不允许修改组成friendlyname的属性
public function DisplayBareHistory(WebPage $oPage, $bEditMode = false, $iLimitCount = 0, $iLimitStart = 0)
{
// SideCarVer 和 AppTemplateVer 没有使用 person_list,不限制查看历史记录
$whitelist = ["SideCarVer", "AppTemplateVer"];
// 权限控制,不允许查看非自己名下对象的history table
if(!$this->IsNew() && !in_array($this->Get('finalclass'), $whitelist))
{
$myContactId = UserRights::GetContactId();
$person_list = $this->Get('person_list');
$contacts = array();
foreach($person_list as $v) {
$contacts[] = $v->Get('person_id');
}
if(!in_array($myContactId, $contacts) && !UserRights::IsAdministrator())
{
return "";
}
}
$oPage->add_ready_script('$("code.diff").each(function(i,block){hljs.configure({useBR: false, languages: ["diff"]});hljs.highlightBlock(block);});');
parent::DisplayBareHistory($oPage, $bEditMode, $iLimitCount, $iLimitStart);
$oPage->add_ready_script("$('.history_truncated_toggler').click()");
}
]]>
</code>
</method>
<method id="DisplayBareRelations" _delta="define">
<static>false</static>
<access>public</access>
<type>Overload-cmdbAbstractObject</type>
<code><![CDATA[ public function DisplayBareRelations(WebPage $oPage, $bEditMode = false)
{
parent::DisplayBareRelations($oPage, $bEditMode);
$kubedash = trim(MetaModel::GetModuleSetting('kubernetes', 'kubernetes_dashboard_url', 'http://localhost/'));
$iframeHeight = trim(MetaModel::GetModuleSetting('kubernetes', 'iframe_height', '600px'));
$app = $this->Get('applicationsolution_name');
$ns = $this->Get('k8snamespace_name');
// Fix me! 除deployment之外还有其他类型
$tabUrl = "";
if($this->Get('finalclass') == "Deployment") {
$tabUrl = $kubedash . "/#!/deployment/" . $ns . "/" . $app . "?namespace=" . $ns;
}
$iframe_start = '<iframe style="border:0;padding:0;margin:0;width:100%;height:' . $iframeHeight . ';overflow:auto" ';
$iframe_end = '</iframe></div>';
$addStr = $iframe_start . 'src=' . '"' . $tabUrl . '"' . '>' . $iframe_end;
if (!$bEditMode && $tabUrl)
{
$oPage->SetCurrentTab(Dict::S('Class:Controller/Tab:Debug'));
$oPage->add('<div id="kubernetes_dashboard_url" style="width:100%;height:' . $iframeHeight . ';">');
$oPage->add($addStr);
}
}]]></code>
</method>
</methods>
<presentation>
<default_search>
<items>
<item id="status">
<rank>1</rank>
</item>
<item id="k8snamespace_id">
<rank>5</rank>
</item>
<item id="applicationsolution_name">
<rank>10</rank>
</item>
<item id="applicationsolution_contact">
<rank>70</rank>
</item>
<item id="applicationsolution_business">
<rank>80</rank>
</item>
<item id="replicas">
<rank>60</rank>
</item>
</items>
</default_search>
<details>
<items>
<item id="col:col1">
<rank>10</rank>
<items>
<item id="fieldset:Deployment:baseinfo">
<rank>10</rank>
<items>
<item id="k8snamespace_id">
<rank>10</rank>
</item>
<item id="applicationsolution_id">
<rank>15</rank>
</item>
<item id="status">
<rank>30</rank>
</item>
<item id="image">
<rank>40</rank>
</item>
<item id="image_tag">
<rank>42</rank>
</item>
<item id="repo">
<rank>45</rank>
</item>
<item id="replicas">
<rank>50</rank>
</item>
<item id="cpu_request">
<rank>52</rank>
</item>
<item id="cpu_limit">
<rank>54</rank>
</item>
<item id="mem_request">
<rank>56</rank>
</item>
<item id="containerport">
<rank>60</rank>
</item>
<item id="hostnetwork">
<rank>65</rank>
</item>
<item id="org_id">
<rank>70</rank>
</item>
<item id="move2production">
<rank>80</rank>
</item>
<item id="description">
<rank>90</rank>
</item>
</items>
</item>
</items>
</item>
<item id="person_list">
<rank>60</rank>
</item>
<item id="affinity_list">
<rank>120</rank>
</item>
<item id="volume_list">
<rank>130</rank>
</item>
<item id="col:col2">
<rank>200</rank>
<items>
<item id="fieldset:Controller:secret">
<rank>210</rank>
<items>
<item id="secret">
<rank>220</rank>
</item>
</items>
</item>
</items>
</item>
<item id="col:col3">
<rank>300</rank>
<items>
<item id="fieldset:Controller:other">
<rank>310</rank>
<items>
<item id="change_log">
<rank>320</rank>
</item>
<item id="rolling_strategy">
<rank>330</rank>
</item>
<item id="hostaliases">
<rank>340</rank>
</item>
</items>
</item>
</items>
</item>
</items>
</details>
<search>
<items>
<item id="k8snamespace_id">
<rank>10</rank>
</item>
<item id="applicationsolution_id">
<rank>15</rank>
</item>
<item id="status">
<rank>30</rank>
</item>
<item id="image">
<rank>40</rank>
</item>
<item id="replicas">
<rank>50</rank>
</item>
<item id="cpu_request">
<rank>52</rank>
</item>
<item id="cpu_limit">
<rank>54</rank>
</item>
<item id="mem_request">
<rank>56</rank>
</item>
<item id="containerport">
<rank>60</rank>
</item>
<item id="org_id">
<rank>70</rank>
</item>
<item id="move2production">
<rank>80</rank>
</item>
<item id="description">
<rank>90</rank>
</item>
</items>
</search>
<list>
<items>
<item id="k8snamespace_id">
<rank>10</rank>
</item>