Skip to content

Commit fc8e6cf

Browse files
authored
Fixing automation/status broken based on supporting a list of hosting environments (#42)
* Fixing automation/status broken based on supporting a list of hosting environments * Fixing automation/status broken based on supporting a list of hosting environments * Fixing automation/status broken based on supporting a list of hosting environments * Fixing automation/status broken based on supporting a list of hosting environments * Fixing automation/status broken based on supporting a list of hosting environments * Fixing automation/status broken based on supporting a list of hosting environments
1 parent 3461491 commit fc8e6cf

File tree

2 files changed

+102
-84
lines changed

2 files changed

+102
-84
lines changed

generate-status/write_status.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
}
1212
ocp_subsystem = {
1313
"name": "OpenShift",
14-
"status": "",
14+
"status": "yellow",
1515
"state": "",
16-
"info": "",
16+
"info": "No status available. Please check back later.",
1717
"updated": "",
1818
"access_urls": [],
1919
"messages": []
@@ -42,33 +42,40 @@
4242
current_state = subject["ocp_anarchy_subject"]["spec"]["vars"]["current_state"]
4343
desired_state = subject["ocp_anarchy_subject"]["spec"]["vars"]["desired_state"] if "desired_state" in subject["ocp_anarchy_subject"]["spec"]["vars"] else None
4444

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

48-
ocp_subsystem["state"] = current_state
49-
ocp_subsystem["updated"] = str(datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc, microsecond=0).isoformat())
50-
ocp_subsystem["access_urls"] = [
51-
{
52-
"title": "Web Console",
53-
"url": f"https://console-openshift-console.apps.{engagement['ocp_sub_domain']}.{region_url}.{context['ocp_base_url']}"
54-
},
55-
{
56-
"title": "API",
57-
"url": f"https://api.{engagement['ocp_sub_domain']}.{region_url}.{context['ocp_base_url']}:6443"
58-
}
59-
]
48+
#####################################################################################################################
49+
# Right now, the only supported configuration is a list of one hosting environment.
50+
# In the near future, this should be updated to support more than one, and this comment (and the code below)
51+
# should be updated to support this. For now, this checking is just looking for more than zero hosting environments,
52+
# but will default to use the value(s) from the first one.
6053

61-
if current_state == "provisioning":
62-
ocp_subsystem["status"] = "yellow"
63-
ocp_subsystem["info"] = "Building Cluster. This normally takes about ~45 min from launch. Please check back later for an updated status."
64-
elif current_state == desired_state or (current_state == "started" and desired_state is None):
65-
ocp_subsystem["status"] = "green"
66-
ocp_subsystem["info"] = "Working as expected"
67-
else:
68-
ocp_subsystem["status"] = "yellow"
69-
ocp_subsystem["info"] = "Contact SRE team"
54+
if 'hosting_environments' in engagement and len(engagement['hosting_environments']) > 0:
55+
ocp_subsystem["state"] = current_state
56+
ocp_subsystem["updated"] = str(datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc, microsecond=0).isoformat())
57+
ocp_subsystem["access_urls"] = [
58+
{
59+
"title": "Web Console",
60+
"url": f"https://console-openshift-console.apps.{engagement['hosting_environments'][0]['ocp_sub_domain']}.{region_url}.{context['ocp_base_url']}"
61+
},
62+
{
63+
"title": "API",
64+
"url": f"https://api.{engagement['hosting_environments'][0]['ocp_sub_domain']}.{region_url}.{context['ocp_base_url']}:6443"
65+
}
66+
]
67+
68+
if current_state == "provisioning":
69+
ocp_subsystem["status"] = "yellow"
70+
ocp_subsystem["info"] = "Building Hosting Environment. This normally takes about 45-60 min from launch. Please check back later for an updated status."
71+
elif current_state == desired_state or (current_state == "started" and desired_state is None):
72+
ocp_subsystem["status"] = "green"
73+
ocp_subsystem["info"] = "Working as expected"
74+
else:
75+
ocp_subsystem["status"] = "yellow"
76+
ocp_subsystem["info"] = "Contact SRE team"
7077

71-
status["overall_status"] = ocp_subsystem["status"]
78+
status["overall_status"] = ocp_subsystem["status"]
7279
status["subsystems"].append(ocp_subsystem)
7380

7481
with open(f"../../{subject['directory']}/status.json", 'w') as fp:

inventory-generation/identity-management/main.yml

Lines changed: 70 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -58,63 +58,74 @@
5858
set_fact:
5959
cc_list: "{{ ', '.join(( '{{ engagement_lead_email }}', '{{ technical_lead_email }}' )) }}"
6060

61-
- name: "Set IDM facts"
62-
set_fact:
63-
ipa_host: "{{ 'ipa.apps.' + (ocp_sub_domain | lower) + '.' + engagement_region | default('dev-1') + '.' + ocp_base_url }}"
64-
ipa_admin_user: "{{ ocp_admin_username }}"
65-
ipa_admin_password: "{{ ocp_admin_password }}"
66-
ipa_validate_certs: "{{ ipa_validate_certs | default(true) }}"
67-
68-
- name: "Assemble inventory"
69-
set_fact:
70-
claim_content:
71-
env_end_date: "{{ (archive_date | regex_replace('^(.*)T.*$', '\\1') | to_datetime('%Y-%m-%d')).strftime('%d %b %Y') }}"
72-
end_date: "{{ (end_date | regex_replace('^(.*)T.*$', '\\1') | to_datetime('%Y-%m-%d')).strftime('%d %b %Y') }}"
73-
start_date: "{{ (start_date | regex_replace('^(.*)T.*$', '\\1') | to_datetime('%Y-%m-%d')).strftime('%d %b %Y') }}"
74-
customer_name: "{{ customer_name }}"
75-
project_name: "{{ project_name }}"
76-
ipa_validate_certs: "{{ ipa_validate_certs }}"
77-
ipa_host: "{{ ipa_host }}"
78-
ipa_admin_user: "{{ ipa_admin_user }}"
79-
ipa_admin_password: "{{ ipa_admin_password }}"
80-
list_of_mail_cc: "{{ cc_list }}"
81-
lodestar_identities:
82-
users: "{{ users }}"
83-
groups: "{{ usrgrp }}"
84-
85-
- name: "Check For Existing Inventory File"
86-
stat:
87-
path: "{{ directory }}/iac/inventories/identity-management/inventory/group_vars/all.yml"
88-
register: existing_inv
89-
90-
- name: "Pull existing inventory vars"
91-
include_vars:
92-
file: "{{ directory }}/iac/inventories/identity-management/inventory/group_vars/all.yml"
93-
name: existing_inv_contents
94-
when:
95-
- existing_inv.stat.exists
96-
97-
- name: "Diff existing vars with new inventory"
98-
set_fact:
99-
inv_has_diff: true
100-
when:
101-
- existing_inv.stat.exists
102-
- existing_inv_contents is defined
103-
- existing_inv_contents != (claim_content | from_yaml)
104-
105-
- name: "Write inventory to file"
106-
copy:
107-
content: "{{ claim_content | to_nice_yaml(indent=2) }}"
108-
dest: "{{ directory }}/iac/inventories/identity-management/inventory/group_vars/all.yml"
109-
110-
- name: "Create hosts file"
111-
copy:
112-
content: "[identity-hosts]\nlocalhost"
113-
dest: "{{ directory }}/iac/inventories/identity-management/inventory/hosts"
114-
115-
- name: "Create ResourceClaim"
116-
copy:
117-
content: "{{ lookup('template', inventory_dir + '/../files/templates/resourceclaim.yaml.j2') }}"
118-
dest: "{{ directory }}/ocp-init/id-mgmt-{{ inv_ts | trim }}.yaml"
61+
#####################################################################################################################
62+
# Right now, the only supported configuration is a list of one hosting environment.
63+
# In the near future, this should be updated to support more than one, and this comment (and the code below)
64+
# should be updated to support this. For now, this checking is just looking for more than zero hosting environments,
65+
# but will default to use the value(s) from the first one.
66+
67+
- block:
68+
- name: "Set IDM facts"
69+
set_fact:
70+
ipa_host: "{{ 'ipa.apps.' + (hosting_environments[0].ocp_sub_domain | lower) + '.' + engagement_region | default('dev-1') + '.' + ocp_base_url }}"
71+
ipa_admin_user: "{{ ocp_admin_username }}"
72+
ipa_admin_password: "{{ ocp_admin_password }}"
73+
ipa_validate_certs: "{{ ipa_validate_certs | default(true) }}"
74+
75+
- name: "Assemble inventory"
76+
set_fact:
77+
claim_content:
78+
env_end_date: "{{ (archive_date | regex_replace('^(.*)T.*$', '\\1') | to_datetime('%Y-%m-%d')).strftime('%d %b %Y') }}"
79+
end_date: "{{ (end_date | regex_replace('^(.*)T.*$', '\\1') | to_datetime('%Y-%m-%d')).strftime('%d %b %Y') }}"
80+
start_date: "{{ (start_date | regex_replace('^(.*)T.*$', '\\1') | to_datetime('%Y-%m-%d')).strftime('%d %b %Y') }}"
81+
customer_name: "{{ customer_name }}"
82+
project_name: "{{ project_name }}"
83+
ipa_validate_certs: "{{ ipa_validate_certs }}"
84+
ipa_host: "{{ ipa_host }}"
85+
ipa_admin_user: "{{ ipa_admin_user }}"
86+
ipa_admin_password: "{{ ipa_admin_password }}"
87+
list_of_mail_cc: "{{ cc_list }}"
88+
lodestar_identities:
89+
users: "{{ users }}"
90+
groups: "{{ usrgrp }}"
91+
92+
- name: "Check For Existing Inventory File"
93+
stat:
94+
path: "{{ directory }}/iac/inventories/identity-management/inventory/group_vars/all.yml"
95+
register: existing_inv
96+
97+
- name: "Pull existing inventory vars"
98+
include_vars:
99+
file: "{{ directory }}/iac/inventories/identity-management/inventory/group_vars/all.yml"
100+
name: existing_inv_contents
101+
when:
102+
- existing_inv.stat.exists
103+
104+
- name: "Diff existing vars with new inventory"
105+
set_fact:
106+
inv_has_diff: true
107+
when:
108+
- existing_inv.stat.exists
109+
- existing_inv_contents is defined
110+
- existing_inv_contents != (claim_content | from_yaml)
111+
112+
- name: "Write inventory to file"
113+
copy:
114+
content: "{{ claim_content | to_nice_yaml(indent=2) }}"
115+
dest: "{{ directory }}/iac/inventories/identity-management/inventory/group_vars/all.yml"
116+
117+
- name: "Create hosts file"
118+
copy:
119+
content: "[identity-hosts]\nlocalhost"
120+
dest: "{{ directory }}/iac/inventories/identity-management/inventory/hosts"
121+
122+
- name: "Create ResourceClaim"
123+
copy:
124+
content: "{{ lookup('template', inventory_dir + '/../files/templates/resourceclaim.yaml.j2') }}"
125+
dest: "{{ directory }}/ocp-init/id-mgmt-{{ inv_ts | trim }}.yaml"
126+
when:
127+
- (inv_has_diff is defined and inv_has_diff is true) or not existing_inv.stat.exists
119128
when:
120-
- (inv_has_diff is defined and inv_has_diff is true) or not existing_inv.stat.exists
129+
- hosting_environments is defined
130+
- hosting_environments|length > 0
131+
- hosting_environments[0].ocp_sub_domain is defined

0 commit comments

Comments
 (0)