Skip to content

Commit 1a9a18c

Browse files
authored
Filter to OCP4 Anarchy subjects for status update (#37)
1 parent 538bf65 commit 1a9a18c

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

generate-status/collect_info.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
from kubernetes import client, config
22
import gitlab
33

4-
g = gitlab.Gitlab(context["gitlab_url"] , private_token=context["gitlab_private_key"])
4+
g = gitlab.Gitlab(context["gitlab_url"],
5+
private_token=context["gitlab_private_key"])
56
gitlab_group = g.groups.get(context["gitlab_group"])
67

78
config.load_incluster_config()
89
custom_object_api = client.CustomObjectsApi()
910
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",
11+
group="anarchy.gpte.redhat.com",
12+
version="v1",
13+
namespace=context["babylon_namespace"],
14+
plural="anarchysubjects",
1415
)
1516

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
17+
18+
def getOCPAnarchySubject(project_id):
19+
subject = list(filter(lambda x: 'ocp4' in x["metadata"]["annotations"]["poolboy.gpte.redhat.com/resource-claim-name"]
20+
and project_id in x["metadata"]["annotations"]["poolboy.gpte.redhat.com/resource-claim-name"], anarchy_subject_list["items"]))
21+
if len(subject) > 0:
22+
return subject[0]
23+
else:
24+
return None
25+
2226

2327
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"]))
28+
{
29+
"url": project.ssh_url_to_repo,
30+
"directory": str(project.id),
31+
"ocp_anarchy_subject": getOCPAnarchySubject(str(project.id))
32+
}
33+
for project in gitlab_group.projects.list(all=True, include_subgroups=True)]
34+
35+
context["repositories"] = list(
36+
filter(lambda x: x["ocp_anarchy_subject"] is not None, context["repositories"]))
3237

3338
need_to_process = [element["directory"] for element in context["repositories"]]
3439

generate-status/write_status.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@
2828
else:
2929
existing_status = False
3030

31-
if "current_state" not in subject["anarchy_subject"]["spec"]["vars"] or "desired_state" not in subject["anarchy_subject"]["spec"]["vars"]:
31+
if "current_state" not in subject["ocp_anarchy_subject"]["spec"]["vars"] or "desired_state" not in subject["ocp_anarchy_subject"]["spec"]["vars"]:
3232
print(f"Skipping {subject['directory']} - state information not found in the Anarchy subject")
3333
return
3434

3535
if existing_status:
3636
existing_ocp_subsystem = [subsystem for subsystem in existing_status["subsystems"] if subsystem["name"] == "OpenShift"]
3737
if len(existing_ocp_subsystem) > 0:
38-
if subject["anarchy_subject"]["spec"]["vars"]["current_state"] == existing_ocp_subsystem[0]["state"]:
38+
if subject["ocp_anarchy_subject"]["spec"]["vars"]["current_state"] == existing_ocp_subsystem[0]["state"]:
3939
print(f"Skipping {subject['directory']} - state has not changed since last update")
4040
return
4141

42-
current_state = subject["anarchy_subject"]["spec"]["vars"]["current_state"]
43-
desired_state = subject["anarchy_subject"]["spec"]["vars"]["desired_state"]
42+
current_state = subject["ocp_anarchy_subject"]["spec"]["vars"]["current_state"]
43+
desired_state = subject["ocp_anarchy_subject"]["spec"]["vars"]["desired_state"]
4444

4545
region = engagement["engagement_region"].lower() if "engagement_region" in engagement else "na"
4646
region_url = f"{region}-1"

0 commit comments

Comments
 (0)