File tree Expand file tree Collapse file tree 2 files changed +87
-0
lines changed Expand file tree Collapse file tree 2 files changed +87
-0
lines changed Original file line number Diff line number Diff line change
1
+ from kubernetes import client , config
2
+ import gitlab
3
+
4
+ g = gitlab .Gitlab (context ["gitlab_url" ] , private_token = context ["gitlab_private_key" ])
5
+ gitlab_group = g .groups .get (context ["gitlab_group" ])
6
+
7
+ config .load_incluster_config ()
8
+ custom_object_api = client .CustomObjectsApi ()
9
+ anarchy_subject_list = custom_object_api .list_namespaced_custom_object (
10
+ group = "anarchy.gpte.redhat.com" ,
11
+ version = "v1" ,
12
+ namespace = context ["babylon_namespace" ],
13
+ plural = "anarchysubjects" ,
14
+ )
15
+
16
+ def getAnarchySubject (project_id ):
17
+ subject = list (filter (lambda x : project_id in x ["metadata" ]["annotations" ]["poolboy.gpte.redhat.com/resource-claim-name" ], anarchy_subject_list ["items" ]))
18
+ if len (subject ) > 0 :
19
+ return subject [0 ]
20
+ else :
21
+ return None
22
+
23
+ context ["repositories" ] = [
24
+ {
25
+ "url" : project .ssh_url_to_repo ,
26
+ "directory" : str (project .id ),
27
+ "anarchy_subject" : getAnarchySubject (str (project .id ))
28
+ }
29
+ for project in gitlab_group .projects .list (all = True , include_subgroups = True )]
30
+
31
+ context ["repositories" ] = list (filter (lambda x : x ["anarchy_subject" ] is not None , context ["repositories" ]))
32
+
33
+ need_to_process = [element ["directory" ] for element in context ["repositories" ]]
34
+
35
+ print (f"Will update status for repositories: { need_to_process } " )
Original file line number Diff line number Diff line change
1
+ import json
2
+ import datetime
3
+
4
+ subject = context ["repositories" ]
5
+
6
+ status = {
7
+ "overall_status" : "" ,
8
+ "messages" : [],
9
+ "subsystems" : []
10
+ }
11
+ ocp_subsystem = {
12
+ "name" : "openshift" ,
13
+ "status" : "" ,
14
+ "state" : "" ,
15
+ "info" : "" ,
16
+ "updated" : "" ,
17
+ "access_urls" : [],
18
+ "messages" : []
19
+ }
20
+
21
+ with open (f"../../{ subject ['directory' ]} /engagement.json" , "r" ) as read_file :
22
+ engagement = json .load (read_file )
23
+
24
+ current_state = subject ["anarchy_subject" ]["spec" ]["vars" ]["current_state" ]
25
+ desired_state = subject ["anarchy_subject" ]["spec" ]["vars" ]["desired_state" ]
26
+
27
+ ocp_subsystem ["state" ] = current_state
28
+ ocp_subsystem ["updated" ] = str (datetime .datetime .utcnow ().replace (tzinfo = datetime .timezone .utc , microsecond = 0 ).isoformat ())
29
+ ocp_subsystem ["access_urls" ] = [
30
+ {
31
+ "Web Console" : f"https://console-openshift-console.apps.{ engagement ['ocp_sub_domain' ]} .{ context ["ocp_base_url" ]} "
32
+ },
33
+ {
34
+ "API" : f"https://api.{ engagement ['ocp_sub_domain' ]} .{ context ["ocp_base_url" ]} :6443"
35
+ }
36
+ ]
37
+
38
+ if current_state == "provisioning" :
39
+ ocp_subsystem ["status" ] = "yellow"
40
+ ocp_subsystem ["info" ] = "Building cluster"
41
+ elif current_state == desired_state :
42
+ ocp_subsystem ["status" ] = "green"
43
+ ocp_subsystem ["info" ] = "Working as expected"
44
+ else :
45
+ ocp_subsystem ["status" ] = "yellow"
46
+ ocp_subsystem ["info" ] = "Contact SRE team"
47
+
48
+ status ["overall_status" ] = ocp_subsystem ["status" ]
49
+ status ["subsystems" ].append (ocp_subsystem )
50
+
51
+ with open (f"../../{ subject ['directory' ]} /status.json" , 'w' ) as fp :
52
+ json .dump (status , fp )
You can’t perform that action at this time.
0 commit comments