From 397baf522787a7213e099135ff04dc6980395810 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Fri, 13 Dec 2024 18:32:35 +0500 Subject: [PATCH 01/60] Add owner label as a prefix while creating integration --- .../tasks/grafana_oncall_hub_spoke.yml | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 96f519bd..36497068 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -43,9 +43,9 @@ kind: ManagedCluster register: managed_clusters_raw -- name: Extract the list of ManagedCluster CRs +- name: Extract ManagedCluster details with owner label ansible.builtin.set_fact: - managed_clusters: "{{ managed_clusters | default([]) + [{'name': item.metadata.name}] }}" + managed_clusters: "{{ managed_clusters | default([]) + [{'name': item.metadata.name, 'owner': item.metadata.labels.owner }}" loop: "{{ managed_clusters_raw.resources }}" loop_control: loop_var: item @@ -100,19 +100,19 @@ {{ { "type": "alertmanager", - "name": item.name, + "name": (item.owner + '-' + item.name), "default_route": { - "slack": { - "channel_id": slack_channel_validated[loop_index].slack_id, - "enabled": slack_cond - } + "slack": { + "channel_id": slack_channel_validated[loop_index].slack_id, + "enabled": slack_cond } - } if slack_channel_validated is defined and - slack_channel_validated | length > loop_index and - slack_channel_validated[loop_index].slack_id | length > 0 - else { - "type": "alertmanager", - "name": item.name + } + } if slack_channel_validated is defined and + slack_channel_validated | length > loop_index and + slack_channel_validated[loop_index].slack_id | length > 0 + else { + "type": "alertmanager", + "name": (item.owner + '-' + item.name) } }} status_code: [200, 201] From 5a9749ce3edc0f60374736a8a6778ab350483b22 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Fri, 13 Dec 2024 18:43:37 +0500 Subject: [PATCH 02/60] fix --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 36497068..130de74a 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -45,7 +45,7 @@ - name: Extract ManagedCluster details with owner label ansible.builtin.set_fact: - managed_clusters: "{{ managed_clusters | default([]) + [{'name': item.metadata.name, 'owner': item.metadata.labels.owner }}" + managed_clusters: "{{ managed_clusters | default([]) + [{'name': item.metadata.name, 'owner': item.metadata.labels.owner}] }}" loop: "{{ managed_clusters_raw.resources }}" loop_control: loop_var: item From f859b3bd80cc219696b9fc044edbf0e0354a7f80 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 31 Dec 2024 17:51:03 +0500 Subject: [PATCH 03/60] update --- .../tasks/grafana_oncall_hub_spoke.yml | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 130de74a..fd447f5a 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -43,20 +43,51 @@ kind: ManagedCluster register: managed_clusters_raw -- name: Extract ManagedCluster details with owner label +- name: Extract ManagedCluster details with name label ansible.builtin.set_fact: - managed_clusters: "{{ managed_clusters | default([]) + [{'name': item.metadata.name, 'owner': item.metadata.labels.owner}] }}" + managed_clusters_create: "{{ managed_clusters_create | default([]) + [{'name': item.metadata.name}] }}" loop: "{{ managed_clusters_raw.resources }}" loop_control: loop_var: item -- name: Remove duplicate entries from managed_clusters +- name: Extract ManagedCluster names with prefix ansible.builtin.set_fact: - managed_clusters: "{{ managed_clusters | unique(attribute='name') }}" + managed_cluster_names: "{{ managed_cluster_names | default([]) + ['name: ' ~ item.metadata.name] }}" + loop: "{{ managed_clusters_raw.resources }}" + loop_control: + loop_var: item + +- name: Extract ManagedCluster owners with prefix + ansible.builtin.set_fact: + managed_cluster_owners: "{{ managed_cluster_owners | default([]) + ['owner: ' ~ item.metadata.labels.owner | default('unknown')] }}" + loop: "{{ managed_clusters_raw.resources }}" + loop_control: + loop_var: item + +- name: Combine managed_cluster_names and managed_cluster_owners into a dictionary + set_fact: + managed_clusters: >- + {{ + dict(managed_cluster_names | zip(managed_cluster_owners)) + }} - name: Determine which ManagedCluster CRs don't have integrations ansible.builtin.set_fact: - create_integration_for: "{{ managed_clusters | rejectattr('name', 'in', existing_integration_names) | list }}" + create_integration_for: "{{ managed_clusters_create | rejectattr('name', 'in', existing_integration_names) | list }}" + +- name: Add 'name:' prefix to integration_names + set_fact: + integration_names: "{{ create_integration_for | map(attribute='name') | map('regex_replace', '^', 'name: ') | list }}" + +- name: Filter common clusters for integration by name + set_fact: + common_clusters: >- + {{ + managed_clusters + | dict2items + | selectattr('key', 'in', integration_names) + | items2dict + }} - name: Integration creation block: @@ -100,7 +131,7 @@ {{ { "type": "alertmanager", - "name": (item.owner + '-' + item.name), + "name": (item.key | regex_replace('^name: ', '') + '-' + item.value | regex_replace('^owner: ', '')), "default_route": { "slack": { "channel_id": slack_channel_validated[loop_index].slack_id, @@ -112,20 +143,19 @@ slack_channel_validated[loop_index].slack_id | length > 0 else { "type": "alertmanager", - "name": (item.owner + '-' + item.name) + "name": (item.key | regex_replace('^name: ', '') + '-' + item.value | regex_replace('^owner: ', '')) } }} status_code: [200, 201] register: grafana_integration_response - loop: "{{ create_integration_for }}" + loop: "{{ common_clusters | dict2items }}" loop_control: - label: "{{ item.name }}" + label: "{{ item.key }}" index_var: loop_index retries: 5 delay: 6 until: grafana_integration_response.status in [200, 201] failed_when: false - - name: Update status with ManagedCluster field operator_sdk.util.k8s_status: api_version: grafanacloud.stakater.com/v1alpha1 From 76ca029c16dd89f75a14a2868a265930e3522dc1 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 31 Dec 2024 17:52:22 +0500 Subject: [PATCH 04/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index fd447f5a..1025f480 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -156,6 +156,7 @@ delay: 6 until: grafana_integration_response.status in [200, 201] failed_when: false + - name: Update status with ManagedCluster field operator_sdk.util.k8s_status: api_version: grafanacloud.stakater.com/v1alpha1 From bb6b879282baaf62b8d3cd272df0af2deb5e798c Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 31 Dec 2024 17:58:23 +0500 Subject: [PATCH 05/60] update --- .../tasks/grafana_oncall_hub_spoke.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 1025f480..2ba7bcae 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -65,7 +65,7 @@ loop_var: item - name: Combine managed_cluster_names and managed_cluster_owners into a dictionary - set_fact: + ansible.builtin.set_fact: managed_clusters: >- {{ dict(managed_cluster_names | zip(managed_cluster_owners)) @@ -76,11 +76,11 @@ create_integration_for: "{{ managed_clusters_create | rejectattr('name', 'in', existing_integration_names) | list }}" - name: Add 'name:' prefix to integration_names - set_fact: + ansible.builtin.set_fact: integration_names: "{{ create_integration_for | map(attribute='name') | map('regex_replace', '^', 'name: ') | list }}" - name: Filter common clusters for integration by name - set_fact: + ansible.builtin.set_fact: common_clusters: >- {{ managed_clusters From 216a83c13a07a29d39da77ce2be64ba49c3bc115 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 31 Dec 2024 19:07:20 +0500 Subject: [PATCH 06/60] update --- .../grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 2ba7bcae..c558ff95 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -43,7 +43,7 @@ kind: ManagedCluster register: managed_clusters_raw -- name: Extract ManagedCluster details with name label +- name: Extract ManagedCluster details with name ansible.builtin.set_fact: managed_clusters_create: "{{ managed_clusters_create | default([]) + [{'name': item.metadata.name}] }}" loop: "{{ managed_clusters_raw.resources }}" @@ -75,7 +75,7 @@ ansible.builtin.set_fact: create_integration_for: "{{ managed_clusters_create | rejectattr('name', 'in', existing_integration_names) | list }}" -- name: Add 'name:' prefix to integration_names +- name: Adds name as prefix to integration_names ansible.builtin.set_fact: integration_names: "{{ create_integration_for | map(attribute='name') | map('regex_replace', '^', 'name: ') | list }}" From d80869f568b53c9e6165649f87f52cbf3c012985 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 31 Dec 2024 21:14:05 +0500 Subject: [PATCH 07/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index c558ff95..31a3b8a3 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -176,7 +176,7 @@ - name: Set fact for list of ManagedCluster names ansible.builtin.set_fact: - managed_cluster_names: "{{ managed_clusters | map(attribute='name') | list }}" + managed_cluster_names: "{{ managed_cluster_owners | map(attribute='name') | list }}" when: create_integration_for | length == grafana_integration_response.results | length - name: Merge existing ManagedCluster names with new ones From 316825fed10553f271201923ec40a14e88c941bc Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 31 Dec 2024 21:20:59 +0500 Subject: [PATCH 08/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 31a3b8a3..ea74ed05 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -176,7 +176,7 @@ - name: Set fact for list of ManagedCluster names ansible.builtin.set_fact: - managed_cluster_names: "{{ managed_cluster_owners | map(attribute='name') | list }}" + managed_cluster_names: "{{ managed_clusters_create | map(attribute='name') | list }}" when: create_integration_for | length == grafana_integration_response.results | length - name: Merge existing ManagedCluster names with new ones From 5bba315e2e8b19e38a8dd6b40a99e90123968e8d Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 31 Dec 2024 21:46:42 +0500 Subject: [PATCH 09/60] update --- .../tasks/delete_grafana_oncall_hub_spoke.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml index 68448fff..8c7a3bff 100644 --- a/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml @@ -34,6 +34,10 @@ kind: ManagedCluster register: managed_clusters_raw +- name: Initialize managed_clusters as an empty list + ansible.builtin.set_fact: + managed_clusters: [] + - name: Extract list of ManagedCluster CRs ansible.builtin.set_fact: managed_clusters: "{{ managed_clusters | default([]) + [{'name': item.metadata.name}] }}" From bb371a907539ae8050e2c9d480187a9fbedd9314 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 13:37:54 +0500 Subject: [PATCH 10/60] update --- .../tasks/grafana_oncall_hub_spoke.yml | 51 +++++++++++++------ 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index ea74ed05..692f46d9 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -43,13 +43,6 @@ kind: ManagedCluster register: managed_clusters_raw -- name: Extract ManagedCluster details with name - ansible.builtin.set_fact: - managed_clusters_create: "{{ managed_clusters_create | default([]) + [{'name': item.metadata.name}] }}" - loop: "{{ managed_clusters_raw.resources }}" - loop_control: - loop_var: item - - name: Extract ManagedCluster names with prefix ansible.builtin.set_fact: managed_cluster_names: "{{ managed_cluster_names | default([]) + ['name: ' ~ item.metadata.name] }}" @@ -68,16 +61,19 @@ ansible.builtin.set_fact: managed_clusters: >- {{ - dict(managed_cluster_names | zip(managed_cluster_owners)) + dict( + managed_cluster_names + | map('regex_replace', '^name: ', '') + | zip( + managed_cluster_owners + | map('regex_replace', '^owner: ', '') + ) + ) }} -- name: Determine which ManagedCluster CRs don't have integrations - ansible.builtin.set_fact: - create_integration_for: "{{ managed_clusters_create | rejectattr('name', 'in', existing_integration_names) | list }}" - - name: Adds name as prefix to integration_names ansible.builtin.set_fact: - integration_names: "{{ create_integration_for | map(attribute='name') | map('regex_replace', '^', 'name: ') | list }}" + integration_names: "{{ existing_integration_names | map('regex_replace', '^', 'name: ') | list }}" - name: Filter common clusters for integration by name ansible.builtin.set_fact: @@ -89,6 +85,31 @@ | items2dict }} +- name: Determine which ManagedCluster CRs don't have integrations (case-insensitive) + ansible.builtin.set_fact: + create_integration_for: >- + {{ + managed_clusters + | dict2items + | map(attribute='key') + | zip( + managed_clusters | dict2items | map(attribute='value') + ) + | map('join', '-') + | reject('in', integration_names + | map('regex_replace', '^name: ', '') + | map('lower') + | list) + | list + }} + +- name: Transform create_integration_for into a list of dictionaries + ansible.builtin.set_fact: + create_integration_for_dict: "{{ create_integration_for_dict | default([]) + [{'name': item}] }}" + loop: "{{ create_integration_for }}" + loop_control: + loop_var: item + - name: Integration creation block: - name: Fetch Slack Channel from ManagedCluster namespace @@ -97,7 +118,7 @@ kind: Channel namespace: "{{ item.name }}" register: slack_channel_info - loop: "{{ create_integration_for }}" + loop: "{{ create_integration_for_dict }}" loop_control: label: "{{ item.name }}" @@ -176,7 +197,7 @@ - name: Set fact for list of ManagedCluster names ansible.builtin.set_fact: - managed_cluster_names: "{{ managed_clusters_create | map(attribute='name') | list }}" + managed_cluster_names: "{{ managed_clusters | map(attribute='name') | list }}" when: create_integration_for | length == grafana_integration_response.results | length - name: Merge existing ManagedCluster names with new ones From a68b36ffb91245608772862f080904ea6d31e7f5 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 15:18:35 +0500 Subject: [PATCH 11/60] update --- .../tasks/grafana_oncall_hub_spoke.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 692f46d9..341ddf5d 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -116,7 +116,10 @@ kubernetes.core.k8s_info: api_version: slack.stakater.com/v1alpha1 kind: Channel - namespace: "{{ item.name }}" + # Strip everything from the last dash to the end. + # e.g., "local-cluster-unknown" -> "local-cluster" + # "2d23wd4e-epical" -> "2d23wd4e" + namespace: "{{ item.name | regex_replace('^(.+)-[^-]+$', '\\1') }}" register: slack_channel_info loop: "{{ create_integration_for_dict }}" loop_control: From 4f4ba5839cfb8f2113c0c1903eaebf100b456e28 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 15:22:41 +0500 Subject: [PATCH 12/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 341ddf5d..351f63bf 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -116,7 +116,7 @@ kubernetes.core.k8s_info: api_version: slack.stakater.com/v1alpha1 kind: Channel - # Strip everything from the last dash to the end. + # Strip everything from the last dash to the end. # e.g., "local-cluster-unknown" -> "local-cluster" # "2d23wd4e-epical" -> "2d23wd4e" namespace: "{{ item.name | regex_replace('^(.+)-[^-]+$', '\\1') }}" From 6993d794404b7b1d63a3a9f900e64b31556d5796 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 16:09:27 +0500 Subject: [PATCH 13/60] update --- .../grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 351f63bf..57fde3a5 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -116,9 +116,6 @@ kubernetes.core.k8s_info: api_version: slack.stakater.com/v1alpha1 kind: Channel - # Strip everything from the last dash to the end. - # e.g., "local-cluster-unknown" -> "local-cluster" - # "2d23wd4e-epical" -> "2d23wd4e" namespace: "{{ item.name | regex_replace('^(.+)-[^-]+$', '\\1') }}" register: slack_channel_info loop: "{{ create_integration_for_dict }}" From 04d450ac127194a0510ebed943b4eca268ece2e2 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 17:52:40 +0500 Subject: [PATCH 14/60] update --- .../tasks/grafana_oncall_hub_spoke.yml | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 57fde3a5..4d99c917 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -152,7 +152,7 @@ {{ { "type": "alertmanager", - "name": (item.key | regex_replace('^name: ', '') + '-' + item.value | regex_replace('^owner: ', '')), + "name": item.name, "default_route": { "slack": { "channel_id": slack_channel_validated[loop_index].slack_id, @@ -160,16 +160,16 @@ } } } if slack_channel_validated is defined and - slack_channel_validated | length > loop_index and - slack_channel_validated[loop_index].slack_id | length > 0 + slack_channel_validated | length > loop_index and + slack_channel_validated[loop_index].slack_id | length > 0 else { "type": "alertmanager", - "name": (item.key | regex_replace('^name: ', '') + '-' + item.value | regex_replace('^owner: ', '')) + "name": item.name } }} status_code: [200, 201] register: grafana_integration_response - loop: "{{ common_clusters | dict2items }}" + loop: "{{ create_integration_for_dict }}" loop_control: label: "{{ item.key }}" index_var: loop_index @@ -192,21 +192,35 @@ - name: Extract existing ManagedCluster names from current status ansible.builtin.set_fact: - existing_managed_cluster_names: "{{ current_config_cr.resources[0].status.managedClusters | list | default([]) }}" - when: create_integration_for | length == grafana_integration_response.results | length + existing_managed_cluster_names: >- + {{ + current_config_cr.resources[0].status.managed_clusters + | default([]) + }} - - name: Set fact for list of ManagedCluster names + - name: Extract new ManagedCluster names ansible.builtin.set_fact: - managed_cluster_names: "{{ managed_clusters | map(attribute='name') | list }}" - when: create_integration_for | length == grafana_integration_response.results | length + managed_cluster_names: >- + {{ + managed_clusters + | dict2items + | map(attribute='key') + | zip( + managed_clusters + | dict2items + | map(attribute='value') + ) + | map('join', '-') + | list + }} + - name: Merge existing ManagedCluster names with new ones - name: Merge existing ManagedCluster names with new ones ansible.builtin.set_fact: updated_managed_cluster_names: >- {{ (existing_managed_cluster_names + managed_cluster_names) | unique }} - when: create_integration_for | length == grafana_integration_response.results | length - name: Update CR status to IntegrationsCreated operator_sdk.util.k8s_status: @@ -222,7 +236,7 @@ type: "Successful" reason: "IntegrationsCreated" message: "Grafana integrations created for all ManagedClusters." - when: create_integration_for | length == grafana_integration_response.results | length + when: managed_cluster_names | length > 0 - name: Inform user if Grafana integration creation was skipped or failed when: grafana_integration_response is skipped or (grafana_integration_response.results | rejectattr('status', 'in', [200, 201]) | list | length > 0) From fb5a916b2ca5670279bb1e8ba5fed943a64ee51e Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 18:21:16 +0500 Subject: [PATCH 15/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 4d99c917..60ba3972 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -214,7 +214,6 @@ | list }} - - name: Merge existing ManagedCluster names with new ones - name: Merge existing ManagedCluster names with new ones ansible.builtin.set_fact: updated_managed_cluster_names: >- From 1155d1af252e5ee4f5e5de9cc885f63ee304edf6 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 18:41:15 +0500 Subject: [PATCH 16/60] update --- .../tasks/grafana_oncall_hub_spoke.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 60ba3972..063580cd 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -131,12 +131,19 @@ - name: Populate List with spaces if any vars: - slack_id_fetched: "{{ slack_channel_ids | selectattr('name', 'contains', item.name) | map(attribute='slack_id') | join(',') }}" + slack_id_fetched: >- + {{ + slack_channel_ids + | default([]) + | selectattr('name', 'contains', item) + | map(attribute='slack_id') + | join(',') + }} ansible.builtin.set_fact: - slack_channel_validated: "{{ slack_channel_validated | default([]) + [{'name': item.name, 'slack_id': slack_id_fetched}] }}" + slack_channel_validated: "{{ slack_channel_validated | default([]) + [{'name': item, 'slack_id': slack_id_fetched}] }}" loop: "{{ create_integration_for }}" loop_control: - label: "{{ item.name }}" + label: "{{ item }}" when: slack_channel_ids is defined - name: Create a new integration in Grafana OnCall integration for each ManagedClusters that does not have one From ba4159074a80602b4bf851aa9b3c31931a3c7ce8 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 18:55:04 +0500 Subject: [PATCH 17/60] update --- .../grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 063580cd..336b753c 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -121,6 +121,7 @@ loop: "{{ create_integration_for_dict }}" loop_control: label: "{{ item.name }}" + when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 - name: Extract Channel id from slack channel ansible.builtin.set_fact: @@ -204,6 +205,7 @@ current_config_cr.resources[0].status.managed_clusters | default([]) }} + when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 - name: Extract new ManagedCluster names ansible.builtin.set_fact: @@ -220,6 +222,7 @@ | map('join', '-') | list }} + when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 - name: Merge existing ManagedCluster names with new ones ansible.builtin.set_fact: @@ -227,6 +230,7 @@ {{ (existing_managed_cluster_names + managed_cluster_names) | unique }} + when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 - name: Update CR status to IntegrationsCreated operator_sdk.util.k8s_status: From ee54ea81f2616944cc4c2cd64486a05f13bc7b3c Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 19:03:37 +0500 Subject: [PATCH 18/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 336b753c..9c3fe3e9 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -129,6 +129,7 @@ loop: "{{ slack_channel_info.results | map(attribute='resources') | flatten }}" loop_control: label: "{{ item.metadata.name }}" + when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 - name: Populate List with spaces if any vars: From 755288b614081be4c1c126b736f594d5d7fd7ac1 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 19:10:47 +0500 Subject: [PATCH 19/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 9c3fe3e9..41a64258 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -186,6 +186,7 @@ delay: 6 until: grafana_integration_response.status in [200, 201] failed_when: false + when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 - name: Update status with ManagedCluster field operator_sdk.util.k8s_status: From f1f85c92094d27a363bcf46f0a159e6a7c3acc7d Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 19:18:22 +0500 Subject: [PATCH 20/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 41a64258..f549ccc6 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -248,7 +248,7 @@ type: "Successful" reason: "IntegrationsCreated" message: "Grafana integrations created for all ManagedClusters." - when: managed_cluster_names | length > 0 + when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 - name: Inform user if Grafana integration creation was skipped or failed when: grafana_integration_response is skipped or (grafana_integration_response.results | rejectattr('status', 'in', [200, 201]) | list | length > 0) From 649725296ad82e450d9a1afe8733e70550216998 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 19:27:19 +0500 Subject: [PATCH 21/60] update --- .../tasks/grafana_oncall_hub_spoke.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index f549ccc6..b8b739a5 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -271,7 +271,9 @@ reason: "IntegrationCreationFailed" message: "Failed to create Grafana integration for ManagedClusters." loop: "{{ grafana_integration_response.results }}" - when: item.status not in [200, 201] + when: + - item.status not in [200, 201] + - create_integration_for_dict is defined and create_integration_for_dict | length > 0 - name: Start deletion for hubAndSpoke mode ansible.builtin.include_tasks: delete_grafana_oncall_hub_spoke.yml @@ -280,6 +282,7 @@ ansible.builtin.set_fact: mapped_integrations: "{{ mapped_integrations | default([]) + [{'cluster': item.item, 'grafana_details': item.json}] }}" loop: "{{ grafana_integration_response.results }}" + when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 # Following tasks will execute only if Grafana integration was created successfully - name: Modify Alertmanager secret From dddfba014c0530a4c554e365792f550fd7a19ac5 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 19:29:23 +0500 Subject: [PATCH 22/60] update --- .../tasks/grafana_oncall_hub_spoke.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index b8b739a5..1a9e3813 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -271,9 +271,9 @@ reason: "IntegrationCreationFailed" message: "Failed to create Grafana integration for ManagedClusters." loop: "{{ grafana_integration_response.results }}" - when: - - item.status not in [200, 201] - - create_integration_for_dict is defined and create_integration_for_dict | length > 0 + when: + - item.status not in [200, 201] + - create_integration_for_dict is defined and create_integration_for_dict | length > 0 - name: Start deletion for hubAndSpoke mode ansible.builtin.include_tasks: delete_grafana_oncall_hub_spoke.yml From ad85cee486a72aefefd5354e9b5bd24b584b79f2 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 19:31:08 +0500 Subject: [PATCH 23/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 1a9e3813..601ff190 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -198,7 +198,7 @@ managedClusters: [] when: - "'managedClusters' not in current_config_cr.resources[0].status" - - create_integration_for | length == grafana_integration_response.results | length + - create_integration_for_dict is defined and create_integration_for_dict | length > 0 - name: Extract existing ManagedCluster names from current status ansible.builtin.set_fact: From 83b7b1e7e8237d3e35393e0ef567f5ce74a08d95 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 19:36:19 +0500 Subject: [PATCH 24/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 601ff190..26b5a46d 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -186,7 +186,6 @@ delay: 6 until: grafana_integration_response.status in [200, 201] failed_when: false - when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 - name: Update status with ManagedCluster field operator_sdk.util.k8s_status: From 50b22c22bd596d8911f26cebcb784c3fad3bcf1c Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 19:46:53 +0500 Subject: [PATCH 25/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 26b5a46d..601ff190 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -186,6 +186,7 @@ delay: 6 until: grafana_integration_response.status in [200, 201] failed_when: false + when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 - name: Update status with ManagedCluster field operator_sdk.util.k8s_status: From a707fc0b991ef73536509e500e0af20ed1832ca4 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 19:57:28 +0500 Subject: [PATCH 26/60] update --- .../grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 601ff190..d97192c2 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -180,13 +180,12 @@ register: grafana_integration_response loop: "{{ create_integration_for_dict }}" loop_control: - label: "{{ item.key }}" + label: "{{ item.name }}" index_var: loop_index retries: 5 delay: 6 until: grafana_integration_response.status in [200, 201] failed_when: false - when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 - name: Update status with ManagedCluster field operator_sdk.util.k8s_status: From ac800a4ac35a992b6a333c5b22e7d7a64de42e47 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 20:01:52 +0500 Subject: [PATCH 27/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index d97192c2..8d35e59b 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -186,6 +186,7 @@ delay: 6 until: grafana_integration_response.status in [200, 201] failed_when: false + when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 - name: Update status with ManagedCluster field operator_sdk.util.k8s_status: From 9796f9032adb93e3ae5e5768db6f09a16ce7103b Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Tue, 7 Jan 2025 20:09:51 +0500 Subject: [PATCH 28/60] update --- .../grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 8d35e59b..638588fd 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -257,6 +257,10 @@ ansible.builtin.debug: msg: "Checking if Grafana integration for the cluster was skipped or failed." + - name: Debug grafana_integration_response + ansible.builtin.debug: + var: grafana_integration_response + - name: Update CR status to Failure for failed integrations operator_sdk.util.k8s_status: api_version: grafanacloud.stakater.com/v1alpha1 From b3dd087949f38becba027a3a280569ec64b7e0da Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 09:59:29 +0500 Subject: [PATCH 29/60] update --- .../grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 638588fd..dd9c9277 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -276,8 +276,10 @@ message: "Failed to create Grafana integration for ManagedClusters." loop: "{{ grafana_integration_response.results }}" when: + - grafana_integration_response is defined + - grafana_integration_response.results is defined + - grafana_integration_response.results | length > 0 - item.status not in [200, 201] - - create_integration_for_dict is defined and create_integration_for_dict | length > 0 - name: Start deletion for hubAndSpoke mode ansible.builtin.include_tasks: delete_grafana_oncall_hub_spoke.yml From 70f8d42861c60ef34d0f393394b89086838ff21d Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 10:37:53 +0500 Subject: [PATCH 30/60] update --- .../tasks/delete_grafana_oncall_hub_spoke.yml | 36 +++++++++---------- .../tasks/grafana_oncall_hub_spoke.yml | 4 --- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml index 8c7a3bff..e6dd64ab 100644 --- a/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml @@ -38,16 +38,19 @@ ansible.builtin.set_fact: managed_clusters: [] -- name: Extract list of ManagedCluster CRs +- name: Extract list of ManagedCluster CRs with owners ansible.builtin.set_fact: - managed_clusters: "{{ managed_clusters | default([]) + [{'name': item.metadata.name}] }}" - loop: "{{ managed_clusters_raw.resources }}" - loop_control: - loop_var: item - -- name: Determine which ManagedCluster CR doesn't have integrations - ansible.builtin.set_fact: - create_integration_for: "{{ managed_clusters | rejectattr('name', 'in', existing_integration_names) | list }}" + managed_clusters: >- + {{ + managed_clusters_raw.resources + | map(attribute='metadata.name') + | zip( + managed_clusters_raw.resources + | map(attribute='metadata.labels.owner' | default('unknown')) + ) + | map('join', '-') + | list + }} - name: Fetch current status of Config CR kubernetes.core.k8s_info: @@ -61,13 +64,9 @@ ansible.builtin.set_fact: previous_managed_clusters: "{{ config_cr.resources[0].status.managedClusters | default([]) }}" -- name: Extract current ManagedCluster names - ansible.builtin.set_fact: - current_managed_clusters: "{{ managed_clusters | map(attribute='name') | list }}" - - name: Determine integrations to delete in Grafana Cloud ansible.builtin.set_fact: - delete_integration_for: "{{ previous_managed_clusters | difference(current_managed_clusters) }}" + delete_integration_for: "{{ previous_managed_clusters | difference(managed_clusters) }}" - name: Delete integrations and dashboards when there are integrations to delete when: delete_integration_for | length > 0 @@ -147,7 +146,7 @@ name: "{{ cr_name }}" namespace: "{{ cr_namespace }}" status: - managedClusters: "{{ current_managed_clusters }}" + managedClusters: "{{ managed_clusters }}" conditions: - lastTransitionTime: "{{ ansible_date_time.iso8601 }}" status: "True" @@ -164,7 +163,7 @@ kind: ManifestWork metadata: name: "{{ item.name }}-manifestwork-grafana-oncall" - namespace: "{{ item.name }}" + namespace: "{{ item.name | regex_replace('^(.+)-[^-]+$', '\\1') }}" spec: workload: manifests: @@ -173,11 +172,10 @@ metadata: name: alertmanager-main namespace: openshift-monitoring - loop: "{{ integrations_to_delete }}" # Ensure you have a loop here + loop: "{{ integrations_to_delete }}" loop_control: label: "{{ item.name }}" - when: - - delete_integration_for | length > 0 + when: delete_integration_for | length > 0 register: manifestwork_deletion_results - name: End play if any integrations failed or were skipped diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index dd9c9277..302bbe81 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -257,10 +257,6 @@ ansible.builtin.debug: msg: "Checking if Grafana integration for the cluster was skipped or failed." - - name: Debug grafana_integration_response - ansible.builtin.debug: - var: grafana_integration_response - - name: Update CR status to Failure for failed integrations operator_sdk.util.k8s_status: api_version: grafanacloud.stakater.com/v1alpha1 From 99accb5858b91dae5a0d456ca701c344dead31e4 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 10:45:37 +0500 Subject: [PATCH 31/60] update --- .../tasks/delete_grafana_oncall_hub_spoke.yml | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml index e6dd64ab..fd766646 100644 --- a/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml @@ -38,16 +38,26 @@ ansible.builtin.set_fact: managed_clusters: [] -- name: Extract list of ManagedCluster CRs with owners +- name: Extract ManagedCluster names with prefix + ansible.builtin.set_fact: + managed_cluster_names: "{{ managed_cluster_names | default([]) + [item.metadata.name] }}" + loop: "{{ managed_clusters_raw.resources }}" + loop_control: + loop_var: item + +- name: Extract ManagedCluster owners with prefix + ansible.builtin.set_fact: + managed_cluster_owners: "{{ managed_cluster_owners | default([]) + [item.metadata.labels.owner | default('unknown')] }}" + loop: "{{ managed_clusters_raw.resources }}" + loop_control: + loop_var: item + +- name: Combine managed_cluster_names and managed_cluster_owners into a list of strings ansible.builtin.set_fact: managed_clusters: >- {{ - managed_clusters_raw.resources - | map(attribute='metadata.name') - | zip( - managed_clusters_raw.resources - | map(attribute='metadata.labels.owner' | default('unknown')) - ) + managed_cluster_names + | zip(managed_cluster_owners) | map('join', '-') | list }} From 58dbff6aaf679045097a35163464f4dcf2ecdf76 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 11:29:04 +0500 Subject: [PATCH 32/60] update --- .../tasks/grafana_slo_hub_spoke.yml | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml index 6c9c1c2d..0df30004 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml @@ -12,6 +12,44 @@ reason: "OperationStarted" message: "Starting creation of SLO dashboard in hubAndSpoke mode" +- name: Fetch ManagedCluster CRs + kubernetes.core.k8s_info: + api_version: cluster.open-cluster-management.io/v1 + kind: ManagedCluster + register: managed_clusters_raw + +- name: Extract ManagedCluster names with prefix + ansible.builtin.set_fact: + managed_cluster_names: "{{ managed_cluster_names | default([]) + ['name: ' ~ item.metadata.name] }}" + loop: "{{ managed_clusters_raw.resources }}" + loop_control: + loop_var: item + +- name: Extract ManagedCluster owners with prefix + ansible.builtin.set_fact: + managed_cluster_owners: "{{ managed_cluster_owners | default([]) + ['owner: ' ~ item.metadata.labels.owner | default('unknown')] }}" + loop: "{{ managed_clusters_raw.resources }}" + loop_control: + loop_var: item + +- name: Combine managed_cluster_names and managed_cluster_owners into a dictionary + ansible.builtin.set_fact: + managed_clusters: >- + {{ + dict( + managed_cluster_names + | map('regex_replace', '^name: ', '') + | zip( + managed_cluster_owners + | map('regex_replace', '^owner: ', '') + ) + ) + }} + +- name: Convert managed_clusters to - format + ansible.builtin.set_fact: + current_managed_clusters: "{{ managed_clusters | dict2items | map('join', '-') | list }}" + - name: Get all folders in Grafana Cloud ansible.builtin.uri: url: "{{ gco_cr.spec.sloCloudAPI }}/folders" From 3ca8b4cfdd682d639a2d88b577fbd864e8c7b8d9 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 11:38:29 +0500 Subject: [PATCH 33/60] update --- .../tasks/delete_grafana_oncall_hub_spoke.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml index fd766646..1c780100 100644 --- a/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml @@ -149,6 +149,17 @@ message: "Clears old managed clusters" when: delete_integration_for + - name: Deduplicate and clean up managedClusters status + ansible.builtin.set_fact: + cleaned_managed_clusters: >- + {{ + config_cr.resources[0].status.managedClusters + | map('regex_replace', '^name: ', '') + | map('regex_replace', '-owner: ', '-') + | unique + | list + }} + - name: Update CR status for IntegrationsDeleted operator_sdk.util.k8s_status: api_version: grafanacloud.stakater.com/v1alpha1 @@ -156,7 +167,7 @@ name: "{{ cr_name }}" namespace: "{{ cr_namespace }}" status: - managedClusters: "{{ managed_clusters }}" + managedClusters: "{{ cleaned_managed_clusters }}" conditions: - lastTransitionTime: "{{ ansible_date_time.iso8601 }}" status: "True" From 609e85096c7ac26327c70610401af1552c616ed3 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 11:47:40 +0500 Subject: [PATCH 34/60] update --- .../tasks/delete_grafana_oncall_hub_spoke.yml | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml index 1c780100..1280fa1a 100644 --- a/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml @@ -38,26 +38,16 @@ ansible.builtin.set_fact: managed_clusters: [] -- name: Extract ManagedCluster names with prefix - ansible.builtin.set_fact: - managed_cluster_names: "{{ managed_cluster_names | default([]) + [item.metadata.name] }}" - loop: "{{ managed_clusters_raw.resources }}" - loop_control: - loop_var: item - -- name: Extract ManagedCluster owners with prefix - ansible.builtin.set_fact: - managed_cluster_owners: "{{ managed_cluster_owners | default([]) + [item.metadata.labels.owner | default('unknown')] }}" - loop: "{{ managed_clusters_raw.resources }}" - loop_control: - loop_var: item - -- name: Combine managed_cluster_names and managed_cluster_owners into a list of strings +- name: Extract list of ManagedCluster CRs with owners ansible.builtin.set_fact: managed_clusters: >- {{ - managed_cluster_names - | zip(managed_cluster_owners) + managed_clusters_raw.resources + | map(attribute='metadata.name') + | zip( + managed_clusters_raw.resources + | map(attribute='metadata.labels.owner' | default('unknown')) + ) | map('join', '-') | list }} @@ -149,6 +139,22 @@ message: "Clears old managed clusters" when: delete_integration_for + - name: Update CR status for IntegrationsDeleted + operator_sdk.util.k8s_status: + api_version: grafanacloud.stakater.com/v1alpha1 + kind: Config + name: "{{ cr_name }}" + namespace: "{{ cr_namespace }}" + status: + managedClusters: "{{ managed_clusters }}" + conditions: + - lastTransitionTime: "{{ ansible_date_time.iso8601 }}" + status: "True" + type: "DeletionCompleted" + reason: "OperationDone" + message: "Deleted the integrations {{ delete_integration_for }}" + when: delete_integration_for + - name: Deduplicate and clean up managedClusters status ansible.builtin.set_fact: cleaned_managed_clusters: >- @@ -159,8 +165,9 @@ | unique | list }} + when: delete_integration_for - - name: Update CR status for IntegrationsDeleted + - name: Update CR status with deduplicated ManagedClusters operator_sdk.util.k8s_status: api_version: grafanacloud.stakater.com/v1alpha1 kind: Config @@ -171,9 +178,9 @@ conditions: - lastTransitionTime: "{{ ansible_date_time.iso8601 }}" status: "True" - type: "DeletionCompleted" - reason: "OperationDone" - message: "Deleted the integrations {{ delete_integration_for }}" + type: "Updated" + reason: "Deduplicated" + message: "Removed duplicates and updated managedClusters status." when: delete_integration_for - name: Remove ManifestWork CR from cluster From dd486eaa28b24eb97e9970b793a650eff3109721 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 11:54:49 +0500 Subject: [PATCH 35/60] update --- .../tasks/delete_grafana_oncall_hub_spoke.yml | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml index 1280fa1a..1f8eee8d 100644 --- a/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml @@ -38,16 +38,26 @@ ansible.builtin.set_fact: managed_clusters: [] -- name: Extract list of ManagedCluster CRs with owners +- name: Extract ManagedCluster names with prefix + ansible.builtin.set_fact: + managed_cluster_names: "{{ managed_cluster_names | default([]) + [item.metadata.name] }}" + loop: "{{ managed_clusters_raw.resources }}" + loop_control: + loop_var: item + +- name: Extract ManagedCluster owners with prefix + ansible.builtin.set_fact: + managed_cluster_owners: "{{ managed_cluster_owners | default([]) + [item.metadata.labels.owner | default('unknown')] }}" + loop: "{{ managed_clusters_raw.resources }}" + loop_control: + loop_var: item + +- name: Combine managed_cluster_names and managed_cluster_owners into a list of strings ansible.builtin.set_fact: managed_clusters: >- {{ - managed_clusters_raw.resources - | map(attribute='metadata.name') - | zip( - managed_clusters_raw.resources - | map(attribute='metadata.labels.owner' | default('unknown')) - ) + managed_cluster_names + | zip(managed_cluster_owners) | map('join', '-') | list }} From 7f09d371f01b3924d9a4cadd6ad95157969fa47e Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 11:55:16 +0500 Subject: [PATCH 36/60] update --- roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml index 0df30004..13a7e272 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml @@ -46,7 +46,7 @@ ) }} -- name: Convert managed_clusters to - format +- name: Convert managed_clusters to format ansible.builtin.set_fact: current_managed_clusters: "{{ managed_clusters | dict2items | map('join', '-') | list }}" From 7696fdcd039b9bf0d3abb9dae2fa48d90466fab8 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 11:56:45 +0500 Subject: [PATCH 37/60] update --- roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml index 13a7e272..0df30004 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml @@ -46,7 +46,7 @@ ) }} -- name: Convert managed_clusters to format +- name: Convert managed_clusters to - format ansible.builtin.set_fact: current_managed_clusters: "{{ managed_clusters | dict2items | map('join', '-') | list }}" From e6f93dded7569fd8b82012957d8dc8fe3c51c6ae Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 12:07:14 +0500 Subject: [PATCH 38/60] update --- .../tasks/delete_grafana_oncall_hub_spoke.yml | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml index 1f8eee8d..4bc93d18 100644 --- a/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml @@ -149,48 +149,33 @@ message: "Clears old managed clusters" when: delete_integration_for - - name: Update CR status for IntegrationsDeleted - operator_sdk.util.k8s_status: - api_version: grafanacloud.stakater.com/v1alpha1 - kind: Config - name: "{{ cr_name }}" - namespace: "{{ cr_namespace }}" - status: - managedClusters: "{{ managed_clusters }}" - conditions: - - lastTransitionTime: "{{ ansible_date_time.iso8601 }}" - status: "True" - type: "DeletionCompleted" - reason: "OperationDone" - message: "Deleted the integrations {{ delete_integration_for }}" - when: delete_integration_for - - - name: Deduplicate and clean up managedClusters status + - name: Remove deleted integrations from managedClusters ansible.builtin.set_fact: - cleaned_managed_clusters: >- + updated_managed_clusters: >- {{ config_cr.resources[0].status.managedClusters | map('regex_replace', '^name: ', '') | map('regex_replace', '-owner: ', '-') + | difference(delete_integration_for) | unique | list }} - when: delete_integration_for + when: delete_integration_for | length > 0 - - name: Update CR status with deduplicated ManagedClusters + - name: Update CR status for IntegrationsDeleted operator_sdk.util.k8s_status: api_version: grafanacloud.stakater.com/v1alpha1 kind: Config name: "{{ cr_name }}" namespace: "{{ cr_namespace }}" status: - managedClusters: "{{ cleaned_managed_clusters }}" + managedClusters: "{{ updated_managed_clusters }}" conditions: - lastTransitionTime: "{{ ansible_date_time.iso8601 }}" status: "True" - type: "Updated" - reason: "Deduplicated" - message: "Removed duplicates and updated managedClusters status." + type: "DeletionCompleted" + reason: "OperationDone" + message: "Deleted the integrations {{ delete_integration_for }}" when: delete_integration_for - name: Remove ManifestWork CR from cluster From 313564e767cef336ffae0b78fd67411ca53a0d79 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 12:32:30 +0500 Subject: [PATCH 39/60] update --- .../tasks/grafana_slo_hub_spoke.yml | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml index 0df30004..45b6602b 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml @@ -18,38 +18,30 @@ kind: ManagedCluster register: managed_clusters_raw -- name: Extract ManagedCluster names with prefix +- name: Extract ManagedCluster names ansible.builtin.set_fact: - managed_cluster_names: "{{ managed_cluster_names | default([]) + ['name: ' ~ item.metadata.name] }}" + managed_cluster_names: "{{ managed_cluster_names | default([]) + [item.metadata.name] }}" loop: "{{ managed_clusters_raw.resources }}" loop_control: loop_var: item -- name: Extract ManagedCluster owners with prefix +- name: Extract ManagedCluster owners ansible.builtin.set_fact: - managed_cluster_owners: "{{ managed_cluster_owners | default([]) + ['owner: ' ~ item.metadata.labels.owner | default('unknown')] }}" + managed_cluster_owners: "{{ managed_cluster_owners | default([]) + [item.metadata.labels.owner | default('unknown')] }}" loop: "{{ managed_clusters_raw.resources }}" loop_control: loop_var: item -- name: Combine managed_cluster_names and managed_cluster_owners into a dictionary +- name: Combine ManagedCluster names and owners into a list of strings ansible.builtin.set_fact: - managed_clusters: >- + current_managed_clusters: >- {{ - dict( - managed_cluster_names - | map('regex_replace', '^name: ', '') - | zip( - managed_cluster_owners - | map('regex_replace', '^owner: ', '') - ) - ) + managed_cluster_names + | zip(managed_cluster_owners) + | map('join', '-') + | list }} -- name: Convert managed_clusters to - format - ansible.builtin.set_fact: - current_managed_clusters: "{{ managed_clusters | dict2items | map('join', '-') | list }}" - - name: Get all folders in Grafana Cloud ansible.builtin.uri: url: "{{ gco_cr.spec.sloCloudAPI }}/folders" From d6bac6d41f624628bf4eaf6603d5914184840be8 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 13:50:48 +0500 Subject: [PATCH 40/60] update --- .../tasks/grafana_oncall_hub_spoke.yml | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 302bbe81..6d3124f7 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -280,11 +280,19 @@ - name: Start deletion for hubAndSpoke mode ansible.builtin.include_tasks: delete_grafana_oncall_hub_spoke.yml - - name: Associate Grafana integration details with ManagedClusters - ansible.builtin.set_fact: - mapped_integrations: "{{ mapped_integrations | default([]) + [{'cluster': item.item, 'grafana_details': item.json}] }}" - loop: "{{ grafana_integration_response.results }}" - when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 + - name: Associate Grafana integration details with ManagedClusters + ansible.builtin.set_fact: + mapped_integrations: >- + {{ + mapped_integrations | default([]) + [ + { + 'cluster': item.item, # Ensure this aligns with the loop structure + 'grafana_details': item.json + } + ] + }} + loop: "{{ grafana_integration_response.results | default([]) }}" + when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 # Following tasks will execute only if Grafana integration was created successfully - name: Modify Alertmanager secret @@ -296,6 +304,8 @@ cluster_name: "{{ item.cluster.name }}" provision_mode: "hubAndSpoke" loop: "{{ mapped_integrations }}" + loop_control: + label: "{{ item.cluster.name }}" - name: Update CR status for ManifestWork creation operator_sdk.util.k8s_status: From f720a42914538edbc648f00cfa9689446865f31a Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 13:52:41 +0500 Subject: [PATCH 41/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 6d3124f7..fdcb628f 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -286,7 +286,7 @@ {{ mapped_integrations | default([]) + [ { - 'cluster': item.item, # Ensure this aligns with the loop structure + 'cluster': item.item, 'grafana_details': item.json } ] From ef8b6e137de108699fa4de04d3bbdcedf91a3b88 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 14:20:31 +0500 Subject: [PATCH 42/60] update --- .../tasks/grafana_oncall_hub_spoke.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index fdcb628f..5d610e4b 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -277,9 +277,6 @@ - grafana_integration_response.results | length > 0 - item.status not in [200, 201] - - name: Start deletion for hubAndSpoke mode - ansible.builtin.include_tasks: delete_grafana_oncall_hub_spoke.yml - - name: Associate Grafana integration details with ManagedClusters ansible.builtin.set_fact: mapped_integrations: >- @@ -338,3 +335,6 @@ reason: "ManifestWorkCreationFailed" message: "Failed to create ManifestWork for one or more ManagedClusters" when: manifestwork_creation_results.failed + +- name: Start deletion for hubAndSpoke mode + ansible.builtin.include_tasks: delete_grafana_oncall_hub_spoke.yml From 31b81b35da7b70a84a6efcd43bc626d13fa279e8 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 14:33:56 +0500 Subject: [PATCH 43/60] update --- .../tasks/grafana_oncall_hub_spoke.yml | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 5d610e4b..d3fcfe88 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -277,19 +277,11 @@ - grafana_integration_response.results | length > 0 - item.status not in [200, 201] - - name: Associate Grafana integration details with ManagedClusters - ansible.builtin.set_fact: - mapped_integrations: >- - {{ - mapped_integrations | default([]) + [ - { - 'cluster': item.item, - 'grafana_details': item.json - } - ] - }} - loop: "{{ grafana_integration_response.results | default([]) }}" - when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 + - name: Associate Grafana integration details with ManagedClusters + ansible.builtin.set_fact: + mapped_integrations: "{{ mapped_integrations | default([]) + [{'cluster': item.item, 'grafana_details': item.json}] }}" + loop: "{{ grafana_integration_response.results }}" + when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 # Following tasks will execute only if Grafana integration was created successfully - name: Modify Alertmanager secret From d9f8f67cf1d77649c0403468d12d3691dfb13d93 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 14:45:54 +0500 Subject: [PATCH 44/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index d3fcfe88..f8e28c3b 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -295,6 +295,7 @@ loop: "{{ mapped_integrations }}" loop_control: label: "{{ item.cluster.name }}" + when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 - name: Update CR status for ManifestWork creation operator_sdk.util.k8s_status: From aa1615cce2848cea4d9eb1927de338ce55a07a25 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 14:58:49 +0500 Subject: [PATCH 45/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index f8e28c3b..51ac9e38 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -289,7 +289,7 @@ vars: receiver_name: "{{ item.grafana_details.name }}" receiver_url: "{{ item.grafana_details.link }}" - namespace: "{{ item.cluster.name }}" + namespace: "{{ item.cluster.name | regex_replace('^(.+?)(-new)?$', '\\1') }}" cluster_name: "{{ item.cluster.name }}" provision_mode: "hubAndSpoke" loop: "{{ mapped_integrations }}" From bbbda9395c1bd7bb824fb8bd9dbd93be45d76196 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 15:21:39 +0500 Subject: [PATCH 46/60] update --- .../tasks/grafana_oncall_hub_spoke.yml | 2 +- .../tasks/modify_alertmanager_secret.yml | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 51ac9e38..f8e28c3b 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -289,7 +289,7 @@ vars: receiver_name: "{{ item.grafana_details.name }}" receiver_url: "{{ item.grafana_details.link }}" - namespace: "{{ item.cluster.name | regex_replace('^(.+?)(-new)?$', '\\1') }}" + namespace: "{{ item.cluster.name }}" cluster_name: "{{ item.cluster.name }}" provision_mode: "hubAndSpoke" loop: "{{ mapped_integrations }}" diff --git a/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml b/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml index e3c7b656..cc6afa7a 100644 --- a/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml +++ b/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml @@ -72,6 +72,13 @@ provision_mode_check: "{{ provision_mode }}" when: provision_mode_check == "hubAndSpoke" +- name: Adjust namespace if necessary + ansible.builtin.set_fact: + namespace_corrected: "{{ namespace | regex_replace('^(.+?)(-new)?$', '\\1') }}" + vars: + namespace: "{{ namespace | default('') }}" + when: namespace != namespace | regex_replace('^(.+?)(-new)?$', '\\1') + - name: Create a new ManifestWork for each cluster to patch alertmanager-main secret kubernetes.core.k8s: state: present @@ -80,7 +87,7 @@ kind: ManifestWork metadata: name: "{{ receiver_name }}-manifestwork-grafana-oncall" - namespace: "{{ namespace }}" + namespace: "{{ namespace_corrected }}" spec: workload: manifests: From 14ed456a43be5e82ac3d8010d8f24f74590149e2 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 15:46:40 +0500 Subject: [PATCH 47/60] update --- .../tasks/modify_alertmanager_secret.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml b/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml index cc6afa7a..ce50a947 100644 --- a/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml +++ b/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml @@ -72,13 +72,6 @@ provision_mode_check: "{{ provision_mode }}" when: provision_mode_check == "hubAndSpoke" -- name: Adjust namespace if necessary - ansible.builtin.set_fact: - namespace_corrected: "{{ namespace | regex_replace('^(.+?)(-new)?$', '\\1') }}" - vars: - namespace: "{{ namespace | default('') }}" - when: namespace != namespace | regex_replace('^(.+?)(-new)?$', '\\1') - - name: Create a new ManifestWork for each cluster to patch alertmanager-main secret kubernetes.core.k8s: state: present @@ -87,7 +80,7 @@ kind: ManifestWork metadata: name: "{{ receiver_name }}-manifestwork-grafana-oncall" - namespace: "{{ namespace_corrected }}" + namespace: "{{ namespace | regex_replace('^(.*?)(-new)?$', '\\1') | default('default-namespace') }}" spec: workload: manifests: From c5d63b361cb6979f510ca3653c9fe00350121c06 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 15:46:49 +0500 Subject: [PATCH 48/60] update --- .../grafana_cloud_operator/tasks/modify_alertmanager_secret.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml b/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml index ce50a947..fd6abd58 100644 --- a/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml +++ b/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml @@ -80,7 +80,7 @@ kind: ManifestWork metadata: name: "{{ receiver_name }}-manifestwork-grafana-oncall" - namespace: "{{ namespace | regex_replace('^(.*?)(-new)?$', '\\1') | default('default-namespace') }}" + namespace: "{{ namespace | regex_replace('^(.*?)(-new)?$', '\\1') | default('default') }}" spec: workload: manifests: From 8671912ea8c9172616160c507519c2738816a217 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 15:54:19 +0500 Subject: [PATCH 49/60] update --- .../grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 4 +--- .../tasks/modify_alertmanager_secret.yml | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index f8e28c3b..cd40e88c 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -289,12 +289,10 @@ vars: receiver_name: "{{ item.grafana_details.name }}" receiver_url: "{{ item.grafana_details.link }}" - namespace: "{{ item.cluster.name }}" + namespace: "{{ item.cluster.name | regex_replace('^(.*?)(-new)?$', '\\1') | default('default') }}" cluster_name: "{{ item.cluster.name }}" provision_mode: "hubAndSpoke" loop: "{{ mapped_integrations }}" - loop_control: - label: "{{ item.cluster.name }}" when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 - name: Update CR status for ManifestWork creation diff --git a/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml b/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml index fd6abd58..e3c7b656 100644 --- a/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml +++ b/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml @@ -80,7 +80,7 @@ kind: ManifestWork metadata: name: "{{ receiver_name }}-manifestwork-grafana-oncall" - namespace: "{{ namespace | regex_replace('^(.*?)(-new)?$', '\\1') | default('default') }}" + namespace: "{{ namespace }}" spec: workload: manifests: From 2882936c22edbfd2402fd8ccdbc93e7b224ff726 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 16:04:21 +0500 Subject: [PATCH 50/60] update --- .../grafana_cloud_operator/tasks/modify_alertmanager_secret.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml b/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml index e3c7b656..f238e638 100644 --- a/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml +++ b/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml @@ -80,7 +80,7 @@ kind: ManifestWork metadata: name: "{{ receiver_name }}-manifestwork-grafana-oncall" - namespace: "{{ namespace }}" + namespace: "{{ item.cluster.name | regex_replace('^(.*?)(-new)?$', '\\1') | default('default') }}" spec: workload: manifests: From da6e35d6dad3500e1579b826012cc534e14fd250 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 16:16:08 +0500 Subject: [PATCH 51/60] update --- .../tasks/grafana_oncall_hub_spoke.yml | 9 ++++++++- .../tasks/modify_alertmanager_secret.yml | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index cd40e88c..086192f6 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -283,13 +283,20 @@ loop: "{{ grafana_integration_response.results }}" when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 + - name: Transform and set namespace for each cluster + ansible.builtin.set_fact: + transformed_namespaces: "{{ transformed_namespaces | default([]) + [{'original': item.cluster.name, 'transformed': item.cluster.name | regex_replace('^(.*?)-.*$', '\\1')}] }}" + loop: "{{ mapped_integrations }}" + loop_control: + label: "{{ item.cluster.name }}" + # Following tasks will execute only if Grafana integration was created successfully - name: Modify Alertmanager secret ansible.builtin.include_tasks: modify_alertmanager_secret.yml vars: receiver_name: "{{ item.grafana_details.name }}" receiver_url: "{{ item.grafana_details.link }}" - namespace: "{{ item.cluster.name | regex_replace('^(.*?)(-new)?$', '\\1') | default('default') }}" + namespace: "{{ transformed_namespaces }}" cluster_name: "{{ item.cluster.name }}" provision_mode: "hubAndSpoke" loop: "{{ mapped_integrations }}" diff --git a/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml b/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml index f238e638..e3c7b656 100644 --- a/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml +++ b/roles/grafana_cloud_operator/tasks/modify_alertmanager_secret.yml @@ -80,7 +80,7 @@ kind: ManifestWork metadata: name: "{{ receiver_name }}-manifestwork-grafana-oncall" - namespace: "{{ item.cluster.name | regex_replace('^(.*?)(-new)?$', '\\1') | default('default') }}" + namespace: "{{ namespace }}" spec: workload: manifests: From 73e5efcd6c1f0375dcde6836ac5239e9a2f694bd Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 16:19:23 +0500 Subject: [PATCH 52/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 086192f6..fcd47562 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -285,7 +285,7 @@ - name: Transform and set namespace for each cluster ansible.builtin.set_fact: - transformed_namespaces: "{{ transformed_namespaces | default([]) + [{'original': item.cluster.name, 'transformed': item.cluster.name | regex_replace('^(.*?)-.*$', '\\1')}] }}" + transformed_namespaces: "{{ transformed_namespaces | default([]) + [{'original': item.cluster.name, 'transformed': item.cluster.name | regex_replace('^(.*?)-.*$', '\\1')}] }}" # yamllint disable-line rule:line-length loop: "{{ mapped_integrations }}" loop_control: label: "{{ item.cluster.name }}" From ed957305e053fcfed507e5cd037fa036fc3d9789 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 16:25:55 +0500 Subject: [PATCH 53/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index fcd47562..75a0808c 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -285,7 +285,7 @@ - name: Transform and set namespace for each cluster ansible.builtin.set_fact: - transformed_namespaces: "{{ transformed_namespaces | default([]) + [{'original': item.cluster.name, 'transformed': item.cluster.name | regex_replace('^(.*?)-.*$', '\\1')}] }}" # yamllint disable-line rule:line-length + transformed_namespaces: "{{ transformed_namespaces | default([]) + [item.cluster.name | regex_replace('^(.*?)-.*$', '\\1')] }}" loop: "{{ mapped_integrations }}" loop_control: label: "{{ item.cluster.name }}" From 1bfc63514e550d9a7bf70222306d90959a71d027 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 16:34:53 +0500 Subject: [PATCH 54/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 75a0808c..8fa3a6ae 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -285,7 +285,7 @@ - name: Transform and set namespace for each cluster ansible.builtin.set_fact: - transformed_namespaces: "{{ transformed_namespaces | default([]) + [item.cluster.name | regex_replace('^(.*?)-.*$', '\\1')] }}" + transformed_namespaces: "{{ item.cluster.name | regex_replace('^(.*?)-.*$', '\\1') }}" loop: "{{ mapped_integrations }}" loop_control: label: "{{ item.cluster.name }}" From 4aa724f41a61363b0d66e052b3e6806ca3f0baae Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 16:52:49 +0500 Subject: [PATCH 55/60] update --- .../tasks/grafana_oncall_hub_spoke.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 8fa3a6ae..8e7b0ec9 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -276,6 +276,8 @@ - grafana_integration_response.results is defined - grafana_integration_response.results | length > 0 - item.status not in [200, 201] + + - name: Associate Grafana integration details with ManagedClusters ansible.builtin.set_fact: @@ -289,6 +291,7 @@ loop: "{{ mapped_integrations }}" loop_control: label: "{{ item.cluster.name }}" + when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 # Following tasks will execute only if Grafana integration was created successfully - name: Modify Alertmanager secret @@ -333,6 +336,3 @@ reason: "ManifestWorkCreationFailed" message: "Failed to create ManifestWork for one or more ManagedClusters" when: manifestwork_creation_results.failed - -- name: Start deletion for hubAndSpoke mode - ansible.builtin.include_tasks: delete_grafana_oncall_hub_spoke.yml From 656b17a3fc4c39c618e9a93e82d58733c88c958f Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 16:59:13 +0500 Subject: [PATCH 56/60] update --- roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 8e7b0ec9..340c7a12 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -276,8 +276,6 @@ - grafana_integration_response.results is defined - grafana_integration_response.results | length > 0 - item.status not in [200, 201] - - - name: Associate Grafana integration details with ManagedClusters ansible.builtin.set_fact: From 957073f2a68e620d14edb1ce88049e010023d244 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 17:06:34 +0500 Subject: [PATCH 57/60] update --- .../grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 340c7a12..78eac992 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -334,3 +334,6 @@ reason: "ManifestWorkCreationFailed" message: "Failed to create ManifestWork for one or more ManagedClusters" when: manifestwork_creation_results.failed + +- name: Start deletion for hubAndSpoke mode + ansible.builtin.include_tasks: delete_grafana_oncall_hub_spoke.yml From b605b5d712459fe1c3960adc882a6f11543507c6 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Wed, 8 Jan 2025 17:13:20 +0500 Subject: [PATCH 58/60] update --- .../grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 78eac992..3ec963ce 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -316,7 +316,7 @@ type: "Successful" reason: "ManifestWorksCreated" message: "ManifestWorks created for all ManagedClusters" - when: not manifestwork_creation_results.failed + when: manifestwork_creation_results is defined and not manifestwork_creation_results.failed - name: Update CR status for ManifestWork creation failure kubernetes.core.k8s: @@ -333,7 +333,7 @@ type: "Failed" reason: "ManifestWorkCreationFailed" message: "Failed to create ManifestWork for one or more ManagedClusters" - when: manifestwork_creation_results.failed + when: manifestwork_creation_results is defined and not manifestwork_creation_results.failed - name: Start deletion for hubAndSpoke mode ansible.builtin.include_tasks: delete_grafana_oncall_hub_spoke.yml From 89cb1041840a4b2a8bfca65a46853d872f7bfb9f Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Thu, 9 Jan 2025 14:38:42 +0500 Subject: [PATCH 59/60] add comments --- .../tasks/delete_grafana_oncall_hub_spoke.yml | 7 +++++++ .../tasks/grafana_oncall_hub_spoke.yml | 16 ++++++++++++++++ .../tasks/grafana_slo_hub_spoke.yml | 3 +++ 3 files changed, 26 insertions(+) diff --git a/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml index 4bc93d18..1dcb0406 100644 --- a/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/delete_grafana_oncall_hub_spoke.yml @@ -34,10 +34,12 @@ kind: ManagedCluster register: managed_clusters_raw +# This initializes the managed_cluster var as it has been used at other places in the playbook - name: Initialize managed_clusters as an empty list ansible.builtin.set_fact: managed_clusters: [] +# This will extract all the names from the ManagedCluster CR - name: Extract ManagedCluster names with prefix ansible.builtin.set_fact: managed_cluster_names: "{{ managed_cluster_names | default([]) + [item.metadata.name] }}" @@ -45,6 +47,7 @@ loop_control: loop_var: item +# This will extract all the owner from the labels of ManagedCluster CR - name: Extract ManagedCluster owners with prefix ansible.builtin.set_fact: managed_cluster_owners: "{{ managed_cluster_owners | default([]) + [item.metadata.labels.owner | default('unknown')] }}" @@ -52,6 +55,7 @@ loop_control: loop_var: item +# This combines both the name and owner as [managed_cluster_names]-[managed_cluster_owners] and saves it in var managed_cluster - name: Combine managed_cluster_names and managed_cluster_owners into a list of strings ansible.builtin.set_fact: managed_clusters: >- @@ -74,6 +78,7 @@ ansible.builtin.set_fact: previous_managed_clusters: "{{ config_cr.resources[0].status.managedClusters | default([]) }}" +# Compares the Status field of Config CR with exsiting managed clusters in the clusters and then detemines which integrations to delete. - name: Determine integrations to delete in Grafana Cloud ansible.builtin.set_fact: delete_integration_for: "{{ previous_managed_clusters | difference(managed_clusters) }}" @@ -133,6 +138,7 @@ loop_control: loop_var: item + # This clears out the status field which was having existing managedCluster list - name: Removing old ManagedCluster List operator_sdk.util.k8s_status: api_version: grafanacloud.stakater.com/v1alpha1 @@ -149,6 +155,7 @@ message: "Clears old managed clusters" when: delete_integration_for + # This removes any duplications if found and stores the mangedCluster list with correct format [managed_cluster_name]-[managed_cluster_owner] - name: Remove deleted integrations from managedClusters ansible.builtin.set_fact: updated_managed_clusters: >- diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 3ec963ce..1de82f72 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -43,6 +43,7 @@ kind: ManagedCluster register: managed_clusters_raw +# Extracts name from MangedCluster and saves it like name: local-cluster - name: Extract ManagedCluster names with prefix ansible.builtin.set_fact: managed_cluster_names: "{{ managed_cluster_names | default([]) + ['name: ' ~ item.metadata.name] }}" @@ -50,6 +51,7 @@ loop_control: loop_var: item +# Extracts owner from the ManagedCluster labels and saves it like owner: unknown - name: Extract ManagedCluster owners with prefix ansible.builtin.set_fact: managed_cluster_owners: "{{ managed_cluster_owners | default([]) + ['owner: ' ~ item.metadata.labels.owner | default('unknown')] }}" @@ -57,6 +59,7 @@ loop_control: loop_var: item +# Removes name: and owner: and joins the managed_cluster_names and managed_cluster_owners with hyphen in between. e.g. local-cluster-unkonwn - name: Combine managed_cluster_names and managed_cluster_owners into a dictionary ansible.builtin.set_fact: managed_clusters: >- @@ -71,6 +74,7 @@ ) }} +# existing_integration_names comes fomr common_task via GET request and it has extracted names of integrations existing on Grafana Cloud. We add name: local-cluster-owner and store them as list to integration_names - name: Adds name as prefix to integration_names ansible.builtin.set_fact: integration_names: "{{ existing_integration_names | map('regex_replace', '^', 'name: ') | list }}" @@ -85,6 +89,7 @@ | items2dict }} +# By comparing local available managedClusters CR names and existing_integration_names integrations names on grafana cloud we are creating a list for the integration to be created - name: Determine which ManagedCluster CRs don't have integrations (case-insensitive) ansible.builtin.set_fact: create_integration_for: >- @@ -103,6 +108,7 @@ | list }} +# This creates a dictionary from the create_integration_for list to streamline with our usage ahead - name: Transform create_integration_for into a list of dictionaries ansible.builtin.set_fact: create_integration_for_dict: "{{ create_integration_for_dict | default([]) + [{'name': item}] }}" @@ -112,6 +118,7 @@ - name: Integration creation block: + # This will run only when we have create_integration_for_dict defined - name: Fetch Slack Channel from ManagedCluster namespace kubernetes.core.k8s_info: api_version: slack.stakater.com/v1alpha1 @@ -148,6 +155,7 @@ label: "{{ item }}" when: slack_channel_ids is defined + # Creates the new integration with prefix added for customer e.g. local-cluster-unknown. Will run only once there's integration to be created - name: Create a new integration in Grafana OnCall integration for each ManagedClusters that does not have one ansible.builtin.uri: url: "{{ grafana_cloud_operator_grafana_cloud_integrations_api_url }}" @@ -209,6 +217,9 @@ }} when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 + # This task processes the 'managed_clusters' dictionary to generate a list of ManagedCluster names + # with their associated prefixes. Each entry in the dictionary is transformed into a string in the + # format "-". The resulting list is stored in 'managed_cluster_names'. - name: Extract new ManagedCluster names ansible.builtin.set_fact: managed_cluster_names: >- @@ -283,6 +294,7 @@ loop: "{{ grafana_integration_response.results }}" when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 + # The namespace for ManagedCluster is without prefix of customer name. So we remove it here and store it as transformed_namespaces - name: Transform and set namespace for each cluster ansible.builtin.set_fact: transformed_namespaces: "{{ item.cluster.name | regex_replace('^(.*?)-.*$', '\\1') }}" @@ -292,6 +304,7 @@ when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 # Following tasks will execute only if Grafana integration was created successfully + # transformed_namespaces from above task it removes owner name from it and prints out as local-cluster - name: Modify Alertmanager secret ansible.builtin.include_tasks: modify_alertmanager_secret.yml vars: @@ -303,6 +316,7 @@ loop: "{{ mapped_integrations }}" when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 +# Skipped when manifestwork_creation_results is not defined - name: Update CR status for ManifestWork creation operator_sdk.util.k8s_status: api_version: grafanacloud.stakater.com/v1alpha1 @@ -318,6 +332,7 @@ message: "ManifestWorks created for all ManagedClusters" when: manifestwork_creation_results is defined and not manifestwork_creation_results.failed +# Skipped when manifestwork_creation_results is not defined - name: Update CR status for ManifestWork creation failure kubernetes.core.k8s: state: present @@ -335,5 +350,6 @@ message: "Failed to create ManifestWork for one or more ManagedClusters" when: manifestwork_creation_results is defined and not manifestwork_creation_results.failed +# Moved to the bottom as we want to trigger deletion after all - name: Start deletion for hubAndSpoke mode ansible.builtin.include_tasks: delete_grafana_oncall_hub_spoke.yml diff --git a/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml index 45b6602b..1485f25d 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_slo_hub_spoke.yml @@ -18,6 +18,7 @@ kind: ManagedCluster register: managed_clusters_raw +# Extracts the name from ManagedCluster CR - name: Extract ManagedCluster names ansible.builtin.set_fact: managed_cluster_names: "{{ managed_cluster_names | default([]) + [item.metadata.name] }}" @@ -25,6 +26,7 @@ loop_control: loop_var: item +# Extracts the owner from ManagedCluster CR - name: Extract ManagedCluster owners ansible.builtin.set_fact: managed_cluster_owners: "{{ managed_cluster_owners | default([]) + [item.metadata.labels.owner | default('unknown')] }}" @@ -32,6 +34,7 @@ loop_control: loop_var: item +# Combines them into a list - name: Combine ManagedCluster names and owners into a list of strings ansible.builtin.set_fact: current_managed_clusters: >- From bf4aa96cb2fd0db4bcead83b8c00a13818a5ed24 Mon Sep 17 00:00:00 2001 From: stakater-nordmart-bot Date: Thu, 9 Jan 2025 14:43:16 +0500 Subject: [PATCH 60/60] update --- .../tasks/grafana_oncall_hub_spoke.yml | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml index 1de82f72..7684cc6e 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -43,7 +43,7 @@ kind: ManagedCluster register: managed_clusters_raw -# Extracts name from MangedCluster and saves it like name: local-cluster +# Extracts name from MangedCluster and saves it like name: local-cluster - name: Extract ManagedCluster names with prefix ansible.builtin.set_fact: managed_cluster_names: "{{ managed_cluster_names | default([]) + ['name: ' ~ item.metadata.name] }}" @@ -74,7 +74,9 @@ ) }} -# existing_integration_names comes fomr common_task via GET request and it has extracted names of integrations existing on Grafana Cloud. We add name: local-cluster-owner and store them as list to integration_names +# existing_integration_names comes fomr common_task via GET request +# and it has extracted names of integrations existing on Grafana Cloud. +# We add name: local-cluster-owner and store them as list to integration_names - name: Adds name as prefix to integration_names ansible.builtin.set_fact: integration_names: "{{ existing_integration_names | map('regex_replace', '^', 'name: ') | list }}" @@ -89,7 +91,8 @@ | items2dict }} -# By comparing local available managedClusters CR names and existing_integration_names integrations names on grafana cloud we are creating a list for the integration to be created +# By comparing local available managedClusters CR names and existing_integration_names +# integrations names on grafana cloud we are creating a list for the integration to be created - name: Determine which ManagedCluster CRs don't have integrations (case-insensitive) ansible.builtin.set_fact: create_integration_for: >- @@ -108,7 +111,8 @@ | list }} -# This creates a dictionary from the create_integration_for list to streamline with our usage ahead +# This creates a dictionary from the create_integration_for +# list to streamline with our usage ahead - name: Transform create_integration_for into a list of dictionaries ansible.builtin.set_fact: create_integration_for_dict: "{{ create_integration_for_dict | default([]) + [{'name': item}] }}" @@ -155,7 +159,8 @@ label: "{{ item }}" when: slack_channel_ids is defined - # Creates the new integration with prefix added for customer e.g. local-cluster-unknown. Will run only once there's integration to be created + # Creates the new integration with prefix added for customer e.g. + # local-cluster-unknown. Will run only once there's integration to be created - name: Create a new integration in Grafana OnCall integration for each ManagedClusters that does not have one ansible.builtin.uri: url: "{{ grafana_cloud_operator_grafana_cloud_integrations_api_url }}" @@ -218,7 +223,7 @@ when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 # This task processes the 'managed_clusters' dictionary to generate a list of ManagedCluster names - # with their associated prefixes. Each entry in the dictionary is transformed into a string in the + # with their associated prefixes. Each entry in the dictionary is transformed into a string in the # format "-". The resulting list is stored in 'managed_cluster_names'. - name: Extract new ManagedCluster names ansible.builtin.set_fact: @@ -294,7 +299,8 @@ loop: "{{ grafana_integration_response.results }}" when: create_integration_for_dict is defined and create_integration_for_dict | length > 0 - # The namespace for ManagedCluster is without prefix of customer name. So we remove it here and store it as transformed_namespaces + # The namespace for ManagedCluster is without prefix + # of customer name. So we remove it here and store it as transformed_namespaces - name: Transform and set namespace for each cluster ansible.builtin.set_fact: transformed_namespaces: "{{ item.cluster.name | regex_replace('^(.*?)-.*$', '\\1') }}" @@ -350,6 +356,6 @@ message: "Failed to create ManifestWork for one or more ManagedClusters" when: manifestwork_creation_results is defined and not manifestwork_creation_results.failed -# Moved to the bottom as we want to trigger deletion after all +# Moved to the bottom as we want to trigger deletion after all - name: Start deletion for hubAndSpoke mode ansible.builtin.include_tasks: delete_grafana_oncall_hub_spoke.yml