Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[patch] Change how grafana is installed to be compatible with OCP 4.16 #1436

Merged
merged 5 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 0 additions & 123 deletions ibm/mas_devops/roles/grafana/tasks/install/grafana-v4.yml

This file was deleted.

127 changes: 0 additions & 127 deletions ibm/mas_devops/roles/grafana/tasks/install/grafana-v5.yml

This file was deleted.

123 changes: 120 additions & 3 deletions ibm/mas_devops/roles/grafana/tasks/install/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,124 @@
template: templates/cluster-monitoring-config.yml.j2


# 3. Install and configure Grafana
- name: "Debug version"
debug:
var: grafana_major_version

# 3. Version dependant variables
# -----------------------------------------------------------------------------
- name: "set facts"
set_fact:
grafana_namespace: "{{grafana_v5_namespace}}"
when: grafana_major_version == "5"

- name: "set facts"
set_fact:
grafana_namespace: "{{grafana_v4_namespace}}"
when: grafana_major_version == "4"

# 4. Create Grafana Subscription
# -----------------------------------------------------------------------------
- name: "install : Install Grafana"
include_tasks: "tasks/install/grafana-v{{grafana_major_version}}.yml"
- name: "install : Create Grafana v{{grafana_major_version}} Subscription"
include_tasks: "{{ role_path }}/../../common_tasks/create_subscription.yml"
vars:
package_name: grafana-operator
channel_name: "v{{grafana_major_version}}"
subscription_namespace: "{{ grafana_namespace }}"
subscription_config:
env:
- name: "WATCH_NAMESPACE"
value: ""
- name: "DASHBOARD_NAMESPACES_ALL"
value: "true"

# 5. Configure Grafana Operator so it can scan all namespaces for dashboards
# -------------------------------------------------------------------------------------
# See https://github.com/grafana-operator/grafana-operator/blob/master/documentation/multi_namespace_support.md
- name: "install : Apply Cluster Role and Role Binding"
kubernetes.core.k8s:
template: "templates/grafana/v{{grafana_major_version}}/grafana-rbac.yml.j2"
wait: yes
wait_timeout: 120

# 6. Configure Grafana Instance
# -------------------------------------------------------------------------------------
- name: "install : Create Grafana Instance"
kubernetes.core.k8s:
template: "templates/grafana/v{{grafana_major_version}}/grafana.yml.j2"
wait: yes
wait_timeout: 300

# 7. Configure Grafana Datasource
# -------------------------------------------------------------------------------------
# As per https://docs.openshift.com/container-platform/4.8/monitoring/enabling-monitoring-for-user-defined-projects.html#enabling-monitoring-for-user-defined-projects
# use the external thanos url

- name: Create the prometheus-user-workload token
shell: "oc create token prometheus-user-workload -n openshift-user-workload-monitoring"
register: prometheus_token_resp
retries: 10
delay: 30 # seconds
until: prometheus_token_resp.rc == 0

- name: Get prometheus token
set_fact:
prometheus_token: "{{prometheus_token_resp.stdout_lines | first}}"

- name: "install : Get Thanos Querier route in openshift-monitoring namespace"
kubernetes.core.k8s_info:
api: v1
kind: Route
name: thanos-querier
namespace: openshift-monitoring
register: thanos_route

- name: "install : Fail if we didn't get the Thanos route"
fail:
msg: "The Thanos route `thanos-querier` or host within route not found in openshift-monitoring"
when:
thanos_route is not defined or
thanos_route.resources[0].spec is not defined or
thanos_route.resources[0].spec.host is not defined

- name: "install : Get Thanos Querier host from route"
set_fact:
thanos_host: "{{ thanos_route.resources[0].spec.host }}"

- name: "install : Create Grafana Datasource"
kubernetes.core.k8s:
template: "templates/grafana/v{{grafana_major_version}}/grafana-datasource.yml.j2"
wait: yes
wait_timeout: 120

# 8. Wait for Grafana to be ready
# -------------------------------------------------------------------------------------
- name: "install : Wait for grafana v5 to be ready (60s delay)"
kubernetes.core.k8s_info:
api_version: grafana.integreatly.org/v1beta1
name: mas-grafana
namespace: "{{grafana_namespace}}"
kind: Grafana
register: grafana_cr_result
until:
- grafana_cr_result.resources[0].status.stage is defined
- grafana_cr_result.resources[0].status.stageStatus is defined
- grafana_cr_result.resources[0].status.stage == "complete"
- grafana_cr_result.resources[0].status.stageStatus == "success"
retries: 10 # approx 50 minutes before we give up
delay: 60 # 1 minute
when: grafana_major_version == "5"

- name: "install : Wait for grafana v4 to be ready (60s delay)"
kubernetes.core.k8s_info:
api_version: integreatly.org/v1alpha1
name: mas-grafana
namespace: "{{grafana_namespace}}"
kind: Grafana
register: grafana_cr_result
until:
- grafana_cr_result.resources[0].status.message is defined
- grafana_cr_result.resources[0].status.message == "success"
retries: 10 # approx 50 minutes before we give up
delay: 60 # 1 minute
when: grafana_major_version == "4"
Loading
Loading