File tree Expand file tree Collapse file tree 2 files changed +79
-0
lines changed Expand file tree Collapse file tree 2 files changed +79
-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 : x ["metadata" ]["annotations" ]["poolboy.gpte.redhat.com/resource-claim-name" ] == f"labs.ocp4.na-{ project_id } " , 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 ["status" ] = "green" if current_state == desired_state else "yellow"
28
+ ocp_subsystem ["state" ] = current_state
29
+ ocp_subsystem ["info" ] = "Working as expected" if current_state == desired_state else "Contact SRE team"
30
+ ocp_subsystem ["updated" ] = str (datetime .datetime .utcnow ().replace (tzinfo = datetime .timezone .utc , microsecond = 0 ).isoformat ())
31
+ ocp_subsystem ["access_urls" ] = [
32
+ {
33
+ "Web Console" : ""
34
+ },
35
+ {
36
+ "API" : ""
37
+ }
38
+ ]
39
+
40
+ status ["overall_status" ] = ocp_subsystem ["status" ]
41
+ status ["subsystems" ].append (ocp_subsystem )
42
+
43
+ with open (f"../../{ subject ['directory' ]} /status.json" , 'w' ) as fp :
44
+ json .dump (status , fp )
You can’t perform that action at this time.
0 commit comments