Browse Source

Add files via upload

Signed-off-by: sakshiarora13 <sakshi_arora1@dell.com>
sakshiarora13 3 years ago
parent
commit
350d1776a0

+ 88 - 0
control_plane/roles/webui_grafana/tasks/deployment.yml

@@ -0,0 +1,88 @@
+# Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+---
+
+
+- name: Grafana pod
+  kubernetes.core.k8s:
+    state: present
+    definition:
+      apiVersion: apps/v1
+      kind: Deployment
+      metadata:
+        name: "{{ grafana_k8s }}"
+        namespace: "{{ grafana_namespace }}"
+        labels:
+          app: "{{ grafana_k8s }}"
+      spec:
+        selector:
+          matchLabels:
+            app: "{{ grafana_k8s }}"
+        replicas: 1
+        strategy:
+          type: RollingUpdate
+        template:
+          metadata:
+            labels:
+              app: "{{ grafana_k8s }}"
+          spec:
+            containers:
+              - name: grafana
+                image: "{{ grafana_image }}"
+                imagePullPolicy: "IfNotPresent"
+                env:
+                - name: GF_SERVER_HTTP_PORT
+                  value: "{{ grafana_port }}"
+                - name: GF_PLUGINS_PLUGIN_ADMIN_ENABLED
+                  value: "true"
+                - name: GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS
+                  value: "{{ grafana_plugins_names }}"
+                - name: GF_SECURITY_ADMIN_USER
+                  valueFrom:
+                    secretKeyRef:
+                      name: "{{ grafana_secrets }}"
+                      key: grafana_username
+                - name: GF_SECURITY_ADMIN_PASSWORD
+                  valueFrom:
+                    secretKeyRef:
+                      name: "{{ grafana_secrets }}"
+                      key: grafana_password
+                ports:
+                - containerPort: "{{ grafana_http_port }}"
+                volumeMounts:
+                - mountPath: /var/lib/grafana/
+                  name: grafana-data
+            volumes:
+            - name: grafana-data
+              persistentVolumeClaim:
+                claimName: grafana-volume-claim
+
+- name: Service for grafana
+  kubernetes.core.k8s:
+    state: present
+    definition:
+      apiVersion: v1
+      kind: Service
+      metadata:
+        name: "{{ grafana_k8s }}"
+        namespace: "{{ grafana_namespace }}"
+        labels:
+          app: "{{ grafana_k8s }}"
+      spec:
+        type: ClusterIP
+        ports:
+          - name: http
+            port: "{{ grafana_http_port }}"
+        selector:
+          app: "{{ grafana_k8s }}"

+ 40 - 0
control_plane/roles/webui_grafana/tasks/main.yml

@@ -0,0 +1,40 @@
+# Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+---
+
+
+- name: Pre-requisites for grafana
+  include_tasks: pre-requisites.yml
+
+- name: Create k8s secrets for grafana
+  include_tasks: secrets.yml
+
+- name: Create persistent volume for grafana
+  include_tasks: volume.yml
+
+- name: Create grafana pod
+  include_tasks: deployment.yml
+
+- name: Add grafana-plugins for visualization
+  include_tasks: plugins.yml
+
+- name: Get grafana service IP
+  command: kubectl get svc "{{ grafana_k8s }}" -n "{{ grafana_namespace }}" -o=jsonpath='{.spec.clusterIP}'
+  changed_when: false
+  register: grafana_svc_ip
+
+- name: Get grafana service port
+  command: kubectl get svc "{{ grafana_k8s }}" -n "{{ grafana_namespace }}" -o=jsonpath='{.spec.ports[0].port}'
+  changed_when: false
+  register: grafana_svc_port

+ 36 - 0
control_plane/roles/webui_grafana/tasks/plugins.yml

@@ -0,0 +1,36 @@
+# Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+---
+
+
+- name: Git clone grafana plugin repo
+  ansible.builtin.git:
+    repo: "{{ grafana_plugins_github_repo }}"
+    dest: "{{ mount_location + grafana_plugins_folder_name }}"
+    version: main
+
+- name: Wait for grafana pod to come to ready state
+  command: kubectl wait --for=condition=ready --timeout=10m -n "{{ grafana_namespace }}" pod -l app="{{ grafana_k8s }}"
+  changed_when: false
+  
+- name: Unzip plugins at grafana-plugins folder
+  unarchive:
+    src: "{{ mount_location + grafana_plugins_folder_name + item }}"
+    dest: "{{ mount_location + grafana_k8s + '/plugins/'}}"
+  with_items: "{{ plugins_name }}"
+  changed_when: false
+
+- name: Restart grafana deployment to add grafana plugins
+  command: kubectl rollout restart deployment -n "{{ grafana_namespace }}"
+  changed_when: false

+ 35 - 0
control_plane/roles/webui_grafana/tasks/pre-requisites.yml

@@ -0,0 +1,35 @@
+# Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+---
+
+
+- name: Add kubernetes and grafana ansible-galaxy collection
+  command: ansible-galaxy collection install "{{ item }}"
+  with_items: "{{ collections_name }}"
+  changed_when: false
+
+- name: Create grafana namespace
+  kubernetes.core.k8s:
+    api_version: v1
+    kind: Namespace
+    name: "{{ grafana_namespace }}"
+    state: present
+
+- name: Make grafana persistent directory if it doesnt exist
+  file:
+    path: "{{ mount_location + grafana_k8s }}"
+    state: directory
+    mode: "{{ directory_mode }}"
+    group: root
+    owner: root

+ 45 - 0
control_plane/roles/webui_grafana/tasks/secrets.yml

@@ -0,0 +1,45 @@
+# Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+---
+
+
+- name: Encrypt grafana username
+  shell: |
+    set -o pipefail
+    echo -n "{{ grafana_username }}" | base64
+  register: grafana_user_encrypted
+  changed_when: false
+  no_log: true
+
+- name: Encrypt grafana password
+  shell: |
+    set -o pipefail
+    echo -n "{{ grafana_password }}" | base64
+  register: grafana_password_encrypted
+  changed_when: false
+  no_log: true
+
+- name: Kubernetes secrets
+  kubernetes.core.k8s:
+    state: present
+    definition:
+      apiVersion: v1
+      kind: Secret
+      metadata:
+        name: "{{ grafana_secrets }}"
+        namespace: "{{ grafana_namespace }}"
+      type: Opaque
+      data:
+        grafana_username: "{{ grafana_user_encrypted.stdout }}"
+        grafana_password: "{{ grafana_password_encrypted.stdout }}"

+ 53 - 0
control_plane/roles/webui_grafana/tasks/volume.yml

@@ -0,0 +1,53 @@
+# Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+---
+
+
+- name: Persistent volume for grafana
+  kubernetes.core.k8s:
+    state: present
+    definition:
+      apiVersion: v1
+      kind: PersistentVolume
+      metadata:
+        name: grafana-volume
+        namespace: "{{ grafana_namespace }}"
+        labels:
+          type: manual
+      spec:
+        storageClassName: manual
+        capacity:
+          storage: "{{ grafana_volume_memory }}"
+        accessModes:
+          - ReadWriteOnce
+        hostPath:
+          path: "{{ mount_location + grafana_k8s }}"
+
+
+- name: Persistent volume claim for grafana
+  kubernetes.core.k8s:
+    state: present
+    definition:
+      apiVersion: v1
+      kind: PersistentVolumeClaim
+      metadata:
+        name: grafana-volume-claim
+        namespace: "{{ grafana_namespace }}"
+      spec:
+        storageClassName: manual
+        accessModes:
+          - ReadWriteOnce
+        resources:
+          requests:
+            storage: "{{ grafana_volume_memory }}"

+ 46 - 0
control_plane/roles/webui_grafana/vars/main.yml

@@ -0,0 +1,46 @@
+#  Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+---
+
+
+# Usage: pre-requisites.yml
+collections_name:
+  - kubernetes.core
+  - community.grafana
+directory_mode: '0774'
+
+# Usage: secrets.yml
+grafana_secrets: grafana-secrets
+
+# Usage: volume.yml
+grafana_volume_memory: 1Gi
+
+# Usage: deployment.yml
+grafana_k8s: grafana
+grafana_namespace: grafana
+grafana_image: grafana/grafana-enterprise:8.3.2
+
+# Usage: deployment.yml
+grafana_port: "5000"
+grafana_http_port: 5000
+grafana_plugins_names: "hpcviz-idvl-hpcc-sankey,hpcviz-idvl-hpcc-parallel-coordinate,hpcviz-idvl-hpcc-spiral-layout,hpcviz-idvl-hpcc-stream-net"
+
+# Usage: plugins.yml
+plugins_name:
+  - parallel-coordinate.zip
+  - sankey.zip
+  - spiral-layout.zip
+  - stream-net.zip
+grafana_plugins_folder_name: github-grafana-plugins/
+grafana_plugins_github_repo: https://github.com/nsfcac/grafana-plugin.git