From e5854e573c2c027cfba5ae26b4d043179356cd85 Mon Sep 17 00:00:00 2001 From: tehreemnisa Date: Tue, 30 Jan 2024 14:19:18 +0500 Subject: [PATCH 01/16] Adding support for slack --- .../tasks/grafana_oncall_hub_spoke.yml | 18 ++++++++++++++++++ 1 file changed, 18 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 f488c47d..f1cf98e1 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -36,6 +36,23 @@ - name: Integration creation block: + - name: Fetch Slack Channel from clusterdeployment namespace + kubernetes.core.k8s_info: + api_version: slack.stakater.com/v1alpha1 + kind: Channel + namespace: "{{ item.namespace }}" + register: slack_channel_info + loop: "{{ create_integration_for }}" + loop_control: + label: "{{ item.namespace }}" + + - name: Extract Channel id from slack channel + ansible.builtin.set_fact: + slack_channel_ids: "{{ slack_channel_ids | default([]) + [{'name': item.metadata.name, 'slack_id': item.status.id}] }}" + loop: "{{ slack_channel_info.results | map(attribute='resources') | flatten }}" + loop_control: + label: "{{ item.metadata.name }}" + - name: Create a new integration in Grafana OnCall integration for each ClusterDeployment that does not have one ansible.builtin.uri: url: "{{ grafana_cloud_operator_grafana_cloud_integrations_api_url }}" @@ -48,6 +65,7 @@ body: type: "alertmanager" name: "{{ item.name }}" + slack_id: "{{ item.slack_id }}" status_code: [200, 201] register: grafana_integration_response loop: "{{ create_integration_for }}" From dce19f86f4a56aceb1d251ef16bf3c5f4eed9660 Mon Sep 17 00:00:00 2001 From: tehreemnisa Date: Tue, 30 Jan 2024 17:07:31 +0500 Subject: [PATCH 02/16] adding permission for grafana role --- config/rbac/role.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 15ecf3eb..93f089e1 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -75,6 +75,9 @@ rules: - apiGroups: ["hive.openshift.io"] resources: ["syncsets"] verbs: ["*"] + - apiGroups: ["slack.stakater.com"] + resources: ["channels"] + verbs: ["create", "get", "list", "patch", "update", "watch"] - apiGroups: [""] resources: ["secrets"] verbs: ["*"] From d7310f096eff2f29413267d11a294b23d0b25fb5 Mon Sep 17 00:00:00 2001 From: tehreemnisa Date: Tue, 30 Jan 2024 17:09:27 +0500 Subject: [PATCH 03/16] fixing lint issue --- config/rbac/role.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 93f089e1..2fe6cf8e 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -77,7 +77,7 @@ rules: verbs: ["*"] - apiGroups: ["slack.stakater.com"] resources: ["channels"] - verbs: ["create", "get", "list", "patch", "update", "watch"] + verbs: ["create", "get", "list", "patch", "update", "watch"] - apiGroups: [""] resources: ["secrets"] verbs: ["*"] From c7cbc5bbadfa6d22e82987f51288db0f88fb588b Mon Sep 17 00:00:00 2001 From: tehreemnisa Date: Tue, 30 Jan 2024 17:17:54 +0500 Subject: [PATCH 04/16] fecthing values --- .../tasks/grafana_oncall_hub_spoke.yml | 5 +++++ 1 file changed, 5 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 f1cf98e1..21165a37 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -53,6 +53,11 @@ loop_control: label: "{{ item.metadata.name }}" + - name: Print the slack id and name for each channel + ansible.builtin.debug: + msg: Cluster {{ item.name }} has slackID {{ item.slack_id }} and complete resource {{ slack_channel_info.results }} + when: item.name is defined + - name: Create a new integration in Grafana OnCall integration for each ClusterDeployment that does not have one ansible.builtin.uri: url: "{{ grafana_cloud_operator_grafana_cloud_integrations_api_url }}" From 1986fbe09ee83a442431d8835df10ec010d824bd Mon Sep 17 00:00:00 2001 From: tehreemnisa Date: Tue, 30 Jan 2024 17:40:10 +0500 Subject: [PATCH 05/16] adding more rbac --- config/rbac/role.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 2fe6cf8e..962fafd4 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -54,6 +54,17 @@ rules: - patch - update - watch + - apiGroups: + - slack.stakater.com/v1alpha1 + resources: + - channel + verbs: + - create + - get + - list + - patch + - update + - watch - apiGroups: [""] resources: ["namespaces"] verbs: ["*"] From 7d06531c6a055847a70bdcfbf3d05561bdacc467 Mon Sep 17 00:00:00 2001 From: tehreemnisa Date: Tue, 30 Jan 2024 18:12:37 +0500 Subject: [PATCH 06/16] adding correct indentation --- .../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 21165a37..076b363f 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -70,7 +70,10 @@ body: type: "alertmanager" name: "{{ item.name }}" - slack_id: "{{ item.slack_id }}" + default_route: + slack: + channel_id: "{{ item.slack_id }}" + enabled: true status_code: [200, 201] register: grafana_integration_response loop: "{{ create_integration_for }}" From e1935a91de619a3669aec85b2eec2dde42277fb8 Mon Sep 17 00:00:00 2001 From: tehreemnisa Date: Thu, 1 Feb 2024 12:44:09 +0500 Subject: [PATCH 07/16] adding more rbac --- ...-cloud-ansible-operator.clusterserviceversion.yaml | 8 ++++++++ charts/grafana-oncall/templates/role.yaml | 3 +++ config/rbac/role.yaml | 11 ----------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bundle/manifests/grafana-cloud-ansible-operator.clusterserviceversion.yaml b/bundle/manifests/grafana-cloud-ansible-operator.clusterserviceversion.yaml index 8560d6e8..cd92e20c 100644 --- a/bundle/manifests/grafana-cloud-ansible-operator.clusterserviceversion.yaml +++ b/bundle/manifests/grafana-cloud-ansible-operator.clusterserviceversion.yaml @@ -140,6 +140,14 @@ spec: - get - list - watch + - apiGroups: + - slack.stakater.com + resources: + - channels + verbs: + - get + - list + - watch - apiGroups: - hive.openshift.io resources: diff --git a/charts/grafana-oncall/templates/role.yaml b/charts/grafana-oncall/templates/role.yaml index 79394793..2f0dd730 100644 --- a/charts/grafana-oncall/templates/role.yaml +++ b/charts/grafana-oncall/templates/role.yaml @@ -73,6 +73,9 @@ rules: - apiGroups: ["hive.openshift.io"] resources: ["clusterdeployments"] verbs: ["get", "list", "watch"] + - apiGroups: ["slack.stakater.com"] + resources: ["channels"] + verbs: ["get", "list", "watch"] - apiGroups: ["hive.openshift.io"] resources: ["syncsets"] verbs: ["*"] diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 962fafd4..2fe6cf8e 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -54,17 +54,6 @@ rules: - patch - update - watch - - apiGroups: - - slack.stakater.com/v1alpha1 - resources: - - channel - verbs: - - create - - get - - list - - patch - - update - - watch - apiGroups: [""] resources: ["namespaces"] verbs: ["*"] From 349ef289a21a51b279e3f78306481c29e04e6e3b Mon Sep 17 00:00:00 2001 From: tehreemnisa Date: Thu, 1 Feb 2024 12:57:59 +0500 Subject: [PATCH 08/16] fixing indentation in rbac --- ...a-cloud-ansible-operator.clusterserviceversion.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bundle/manifests/grafana-cloud-ansible-operator.clusterserviceversion.yaml b/bundle/manifests/grafana-cloud-ansible-operator.clusterserviceversion.yaml index cd92e20c..bcb05986 100644 --- a/bundle/manifests/grafana-cloud-ansible-operator.clusterserviceversion.yaml +++ b/bundle/manifests/grafana-cloud-ansible-operator.clusterserviceversion.yaml @@ -141,13 +141,13 @@ spec: - list - watch - apiGroups: - - slack.stakater.com + - slack.stakater.com resources: - - channels + - channels verbs: - - get - - list - - watch + - get + - list + - watch - apiGroups: - hive.openshift.io resources: From a0b748701b2aa3e33c96e3f00c9e24286db96cc8 Mon Sep 17 00:00:00 2001 From: tehreemnisa Date: Thu, 1 Feb 2024 14:24:54 +0500 Subject: [PATCH 09/16] updating variable --- .../tasks/grafana_oncall_hub_spoke.yml | 8 ++++---- 1 file changed, 4 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 076b363f..5436d362 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -55,8 +55,8 @@ - name: Print the slack id and name for each channel ansible.builtin.debug: - msg: Cluster {{ item.name }} has slackID {{ item.slack_id }} and complete resource {{ slack_channel_info.results }} - when: item.name is defined + msg: Cluster {{ slack_channel_ids.name }} has slackID {{ slack_channel_ids.slack_id }} and complete resource {{ slack_channel_info.results }} + when: slack_channel_ids is defined - name: Create a new integration in Grafana OnCall integration for each ClusterDeployment that does not have one ansible.builtin.uri: @@ -69,10 +69,10 @@ Content-Type: "application/json" body: type: "alertmanager" - name: "{{ item.name }}" + name: "{{ slack_channel_ids.name }}" default_route: slack: - channel_id: "{{ item.slack_id }}" + channel_id: "{{ slack_channel_ids.slack_id }}" enabled: true status_code: [200, 201] register: grafana_integration_response From e647b9554aaa51f9aa6da5f2b62ffee373057cd9 Mon Sep 17 00:00:00 2001 From: tehreemnisa Date: Thu, 1 Feb 2024 14:36:37 +0500 Subject: [PATCH 10/16] updating variable --- 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 5436d362..590e6d49 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -56,7 +56,7 @@ - name: Print the slack id and name for each channel ansible.builtin.debug: msg: Cluster {{ slack_channel_ids.name }} has slackID {{ slack_channel_ids.slack_id }} and complete resource {{ slack_channel_info.results }} - when: slack_channel_ids is defined + when: slack_channel_ids.name is defined - name: Create a new integration in Grafana OnCall integration for each ClusterDeployment that does not have one ansible.builtin.uri: From d8ce5696822c38179f93a0f9f4b2ecf8d1bd98cb Mon Sep 17 00:00:00 2001 From: tehreemnisa Date: Thu, 1 Feb 2024 14:47:05 +0500 Subject: [PATCH 11/16] updating variable --- .../tasks/grafana_oncall_hub_spoke.yml | 7 ++++++- 1 file changed, 6 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 590e6d49..9e800aa3 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -58,6 +58,11 @@ msg: Cluster {{ slack_channel_ids.name }} has slackID {{ slack_channel_ids.slack_id }} and complete resource {{ slack_channel_info.results }} when: slack_channel_ids.name is defined + - name: Print return information from the previous task + ansible.builtin.debug: + var: slack_channel_ids + verbosity: 2 + - name: Create a new integration in Grafana OnCall integration for each ClusterDeployment that does not have one ansible.builtin.uri: url: "{{ grafana_cloud_operator_grafana_cloud_integrations_api_url }}" @@ -69,7 +74,7 @@ Content-Type: "application/json" body: type: "alertmanager" - name: "{{ slack_channel_ids.name }}" + name: "test" default_route: slack: channel_id: "{{ slack_channel_ids.slack_id }}" From a8184ef768ba03d08ea2fa7692d9789e0aa310f4 Mon Sep 17 00:00:00 2001 From: tehreemnisa Date: Thu, 1 Feb 2024 14:57:37 +0500 Subject: [PATCH 12/16] updating variable --- .../tasks/grafana_oncall_hub_spoke.yml | 12 +++--------- 1 file changed, 3 insertions(+), 9 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 9e800aa3..ce359836 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -55,13 +55,7 @@ - name: Print the slack id and name for each channel ansible.builtin.debug: - msg: Cluster {{ slack_channel_ids.name }} has slackID {{ slack_channel_ids.slack_id }} and complete resource {{ slack_channel_info.results }} - when: slack_channel_ids.name is defined - - - name: Print return information from the previous task - ansible.builtin.debug: - var: slack_channel_ids - verbosity: 2 + msg: Cluster {{ slack_channel_ids[0] }} has slackID {{ slack_channel_ids.slack_id }} - name: Create a new integration in Grafana OnCall integration for each ClusterDeployment that does not have one ansible.builtin.uri: @@ -74,10 +68,10 @@ Content-Type: "application/json" body: type: "alertmanager" - name: "test" + name: "{{ item.name }}" default_route: slack: - channel_id: "{{ slack_channel_ids.slack_id }}" + channel_id: "{{ slack_channel_ids[0].slack_id }}" enabled: true status_code: [200, 201] register: grafana_integration_response From 44e3cb806322ffeca3308f43ff690c4efeb29e46 Mon Sep 17 00:00:00 2001 From: tehreemnisa Date: Thu, 1 Feb 2024 15:03:46 +0500 Subject: [PATCH 13/16] updating variable --- 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 ce359836..d6883e78 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -55,7 +55,7 @@ - name: Print the slack id and name for each channel ansible.builtin.debug: - msg: Cluster {{ slack_channel_ids[0] }} has slackID {{ slack_channel_ids.slack_id }} + msg: Cluster Slack ID output looks like this {{ slack_channel_ids[0] }} - name: Create a new integration in Grafana OnCall integration for each ClusterDeployment that does not have one ansible.builtin.uri: From f82e246ae1b674dd49c885aad2aedb9ac9585b25 Mon Sep 17 00:00:00 2001 From: tehreemnisa Date: Thu, 1 Feb 2024 19:08:04 +0500 Subject: [PATCH 14/16] updating variable --- .../tasks/grafana_oncall_hub_spoke.yml | 10 +++++++--- 1 file changed, 7 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 d6883e78..3cab63bc 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -41,11 +41,15 @@ api_version: slack.stakater.com/v1alpha1 kind: Channel namespace: "{{ item.namespace }}" - register: slack_channel_info + register: loop: "{{ create_integration_for }}" loop_control: label: "{{ item.namespace }}" + - name: Print the slack id and name for each channel Number01 + ansible.builtin.debug: + msg: Cluster Slack ID output looks like this {{ slack_channel_info }} + - name: Extract Channel id from slack channel ansible.builtin.set_fact: slack_channel_ids: "{{ slack_channel_ids | default([]) + [{'name': item.metadata.name, 'slack_id': item.status.id}] }}" @@ -53,9 +57,9 @@ loop_control: label: "{{ item.metadata.name }}" - - name: Print the slack id and name for each channel + - name: Print the slack id and name for each channel Number01 ansible.builtin.debug: - msg: Cluster Slack ID output looks like this {{ slack_channel_ids[0] }} + msg: Cluster Slack ID output looks like this {{ slack_channel_ids }} - name: Create a new integration in Grafana OnCall integration for each ClusterDeployment that does not have one ansible.builtin.uri: From ad90bcc08d3d410909a8433dbb7ff3d6f029bd0a Mon Sep 17 00:00:00 2001 From: tehreemnisa Date: Thu, 1 Feb 2024 19:32:58 +0500 Subject: [PATCH 15/16] updating variable --- 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 3cab63bc..65f38e38 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -41,7 +41,7 @@ api_version: slack.stakater.com/v1alpha1 kind: Channel namespace: "{{ item.namespace }}" - register: + register: slack_channel_info loop: "{{ create_integration_for }}" loop_control: label: "{{ item.namespace }}" From 708004a185cdb658461c2cf853a847de956e2d46 Mon Sep 17 00:00:00 2001 From: tehreemnisa Date: Thu, 1 Feb 2024 19:41:39 +0500 Subject: [PATCH 16/16] removing print variables --- .../tasks/grafana_oncall_hub_spoke.yml | 8 -------- 1 file changed, 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 65f38e38..b282dba1 100644 --- a/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml +++ b/roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml @@ -46,10 +46,6 @@ loop_control: label: "{{ item.namespace }}" - - name: Print the slack id and name for each channel Number01 - ansible.builtin.debug: - msg: Cluster Slack ID output looks like this {{ slack_channel_info }} - - name: Extract Channel id from slack channel ansible.builtin.set_fact: slack_channel_ids: "{{ slack_channel_ids | default([]) + [{'name': item.metadata.name, 'slack_id': item.status.id}] }}" @@ -57,10 +53,6 @@ loop_control: label: "{{ item.metadata.name }}" - - name: Print the slack id and name for each channel Number01 - ansible.builtin.debug: - msg: Cluster Slack ID output looks like this {{ slack_channel_ids }} - - name: Create a new integration in Grafana OnCall integration for each ClusterDeployment that does not have one ansible.builtin.uri: url: "{{ grafana_cloud_operator_grafana_cloud_integrations_api_url }}"