-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from AdityaHonkalas/monitoring-user-defined-pr…
…ojects Fixes and enhancements for monitoring-user-defined-projects role
- Loading branch information
Showing
6 changed files
with
145 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
playbooks/roles/monitoring-user-defined-projects/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
--- | ||
|
||
# User defined project monitoring vars with defaults | ||
user_defined_namespace: "test-namespace" | ||
user_defined_app_name: "prometheus-example-app" | ||
service_monitor_name: "prometheus-app-monitor" | ||
enable_user_defined_project_monitoring: false # Set true to enable role execution | ||
user_defined_app_name: "example-app" # User defined app name | ||
user_defined_namespace: "test-project1" # User defined namespace | ||
service_monitor_name: "example-app-monitor" # User defined name for ServiceMonitor object name | ||
user_defined_app_image: "quay.io/powercloud/nginx-unprivileged:latest" # Any image for deploying the user-defined app |
13 changes: 13 additions & 0 deletions
13
playbooks/roles/monitoring-user-defined-projects/tasks/cleanup.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
|
||
- name: Delete the servicemonitor instance | ||
shell: oc delete servicemonitor {{ service_monitor_name }} -n {{ user_defined_namespace }} | ||
|
||
- name: Delete the service | ||
shell: oc delete service {{ user_defined_app_name }} -n {{ user_defined_namespace }} | ||
|
||
- name: Delete the example app | ||
shell: oc delete deploy {{ user_defined_app_name }} -n {{ user_defined_namespace }} | ||
|
||
- name: Delete the project | ||
shell: oc delete ns {{ user_defined_namespace }} |
91 changes: 91 additions & 0 deletions
91
playbooks/roles/monitoring-user-defined-projects/tasks/deployment.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
--- | ||
|
||
- name: Create a new namespace | ||
k8s: | ||
state: present | ||
definition: | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: "{{ user_defined_namespace }}" | ||
|
||
- name: Deploy a sample app | ||
k8s: | ||
state: present | ||
definition: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: "{{ user_defined_app_name }}" | ||
name: "{{ user_defined_app_name }}" | ||
namespace: "{{ user_defined_namespace }}" | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: "{{ user_defined_app_name }}" | ||
template: | ||
metadata: | ||
labels: | ||
app: "{{ user_defined_app_name }}" | ||
spec: | ||
containers: | ||
- image: "{{ user_defined_app_image }}" | ||
imagePullPolicy: IfNotPresent | ||
name: "{{ user_defined_app_name }}" | ||
|
||
- name: Create a service that expose the metrics of the deployed app | ||
k8s: | ||
state: present | ||
definition: | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
app: "{{ user_defined_app_name }}" | ||
name: "{{ user_defined_app_name }}" | ||
namespace: "{{ user_defined_namespace }}" | ||
spec: | ||
ports: | ||
- port: 8080 | ||
protocol: TCP | ||
targetPort: 8080 | ||
name: web | ||
selector: | ||
app: "{{ user_defined_app_name }}" | ||
type: ClusterIP | ||
|
||
- name: Check the pod for the deployed prometheus app | ||
shell: "oc -n {{ user_defined_namespace }} get pod --no-headers | awk '{ if($3 != 'Running') print $3 }' | wc -l" | ||
register: pod_count | ||
until: pod_count.stdout|int > 0 | ||
retries: 10 | ||
delay: 60 | ||
|
||
- name: Deploying ServiceMonitor resource object | ||
k8s: | ||
state: present | ||
definition: | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: ServiceMonitor | ||
metadata: | ||
labels: | ||
k8s-app: "{{ service_monitor_name }}" | ||
name: "{{ service_monitor_name }}" | ||
namespace: "{{ user_defined_namespace }}" | ||
spec: | ||
endpoints: | ||
- interval: 30s | ||
port: web | ||
scheme: http | ||
selector: | ||
matchLabels: | ||
app: "{{ user_defined_app_name }}" | ||
|
||
- name: Check the ServiceMonitor resource | ||
shell: "oc -n {{ user_defined_namespace }} get servicemonitor --no-headers | wc -l" | ||
register: service_monitor_count | ||
until: service_monitor_count.stdout|int > 0 | ||
retries: 5 | ||
delay: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters