Skip to content

Commit

Permalink
adding support ansible metrics-utility:
Browse files Browse the repository at this point in the history
updating crd
adding defaults
adding cronjobs
adding tasks to installer
  • Loading branch information
aknochow committed Mar 8, 2024
1 parent ffba1b4 commit c0dfff4
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 0 deletions.
25 changes: 25 additions & 0 deletions config/crd/bases/awx.ansible.com_awxs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,31 @@ spec:
description: Disable web container's nginx ipv6 listener
type: boolean
default: false
metrics_enabled:
description: Enable metrics utility
type: boolean
default: false
metrics_image:
description: Image to use for the metrics-utility container
type: string
metrics_image_version:
description: Version of metrics-utility container image
type: string
metrics_configmap:
description: Configmap where metrics-utility environment variables are stored
type: string
metrics_cronjob_gather_schedule:
description: Schedule for the metrics-gather cronjob
type: string
default: '@hourly'
metrics_cronjob_report_schedule:
description: Schedule for the metrics-report cronjob
type: string
default: '@monthly'
metrics_retention_days:
description: Duration to store metrics locally
type: integer
default: 96
type: object
status:
properties:
Expand Down
1 change: 1 addition & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ rules:
- apiGroups:
- batch
resources:
- cronjobs
- jobs
verbs:
- get
Expand Down
13 changes: 13 additions & 0 deletions roles/installer/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -481,3 +481,16 @@ nginx_worker_processes: 1
nginx_worker_connections: "{{ uwsgi_listen_queue_size }}"
nginx_worker_cpu_affinity: 'auto'
nginx_listen_queue_size: "{{ uwsgi_listen_queue_size }}"

_postgres_image: quay.io/sclorg/postgresql-15-c9s
_postgres_image_version: latest

Check failure on line 486 in roles/installer/defaults/main.yml

View workflow job for this annotation

GitHub Actions / molecule (--skip-tags=replicas)

486:1 [key-duplicates] duplication of key "_postgres_image" in mapping

Check failure on line 486 in roles/installer/defaults/main.yml

View workflow job for this annotation

GitHub Actions / molecule (-t replicas)

486:1 [key-duplicates] duplication of key "_postgres_image" in mapping

Check failure on line 487 in roles/installer/defaults/main.yml

View workflow job for this annotation

GitHub Actions / molecule (--skip-tags=replicas)

487:1 [key-duplicates] duplication of key "_postgres_image_version" in mapping

Check failure on line 487 in roles/installer/defaults/main.yml

View workflow job for this annotation

GitHub Actions / molecule (-t replicas)

487:1 [key-duplicates] duplication of key "_postgres_image_version" in mapping
# metrics-utility (github.com/ansible/metrics-utility)
_metrics_image: "{{ metrics_image | default(_image) }}"
_metrics_image_version: "{{ metrics_image_version | default(_image_version) }}"
_metrics_enabled: "{{ metrics_enabled | default('false') }}"
_metrics_configmap: "{{ metrics_configmap | default(deployment_type + '-metrics-configmap') }}"
_metrics_pvc_claim: "{{ metrics_pvc_claim | default(deployment_type + '-metrics-claim') }}"
_metrics_cronjob_gather_schedule: "{{ metrics_cronjob_gather_schedule | default('@hourly') }}"
_metrics_cronjob_report_schedule: "{{ metrics_cronjob_report_schedule | default('@monthly') }}"
_metrics_retention_days: "{{ metrics_retention_days | default('96') }}"
32 changes: 32 additions & 0 deletions roles/installer/tasks/enable_metrics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
# Check to make sure provided pvc exists, error loudly if not. Otherwise, the management pod will just stay in pending state forever.
- name: Check provided PVC claim exists
kubernetes.core.k8s_info:
name: "{{ _metrics_pvc_claim }}"
kind: PersistentVolumeClaim
namespace: "{{ ansible_operator_meta.namespace }}"
register: provided_pvc
when:
- _metrics_pvc_claim | length

- block:
- name: Create PVC for metrics
kubernetes.core.k8s:
kind: PersistentVolumeClaim
definition: "{{ lookup('template', 'storage/metrics.yaml.j2') }}"

- block:

Check failure on line 18 in roles/installer/tasks/enable_metrics.yml

View workflow job for this annotation

GitHub Actions / molecule (--skip-tags=replicas)

18:9 [trailing-spaces] trailing spaces

Check failure on line 18 in roles/installer/tasks/enable_metrics.yml

View workflow job for this annotation

GitHub Actions / molecule (-t replicas)

18:9 [trailing-spaces] trailing spaces
- name: Create Kubernetes CronJob for metrics-gather
kubernetes.core.k8s:
name: "{{ ansible_operator_meta.name }}-metrics-gather"
kind: CronJob
definition: "{{ lookup('template', 'cronjobs/metrics-gather.yaml.j2') }}"
wait: true

- block:

Check failure on line 26 in roles/installer/tasks/enable_metrics.yml

View workflow job for this annotation

GitHub Actions / molecule (--skip-tags=replicas)

26:9 [trailing-spaces] trailing spaces

Check failure on line 26 in roles/installer/tasks/enable_metrics.yml

View workflow job for this annotation

GitHub Actions / molecule (-t replicas)

26:9 [trailing-spaces] trailing spaces
- name: Create Kubernetes CronJob for metrics-report
kubernetes.core.k8s:
name: "{{ ansible_operator_meta.name }}-metrics-report"
kind: CronJob
definition: "{{ lookup('template', 'cronjobs/metrics-report.yaml.j2') }}"
wait: true

Check failure on line 32 in roles/installer/tasks/enable_metrics.yml

View workflow job for this annotation

GitHub Actions / molecule (--skip-tags=replicas)

32:19 [new-line-at-end-of-file] no new line character at the end of file

Check failure on line 32 in roles/installer/tasks/enable_metrics.yml

View workflow job for this annotation

GitHub Actions / molecule (-t replicas)

32:19 [new-line-at-end-of-file] no new line character at the end of file
4 changes: 4 additions & 0 deletions roles/installer/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@
include_tasks: initialize_django.yml
when: awx_web_pod_name != ''

- name: Enable optional metrics
include_tasks: enable_metrics.yml
when: metrics_enabled

- name: Update status variables
include_tasks: update_status.yml

Expand Down
56 changes: 56 additions & 0 deletions roles/installer/templates/cronjobs/metrics-gather.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
apiVersion: v1
kind: CronJob
metadata:
name: {{ ansible_operator_meta.name }}-metrics-gather
namespace: '{{ ansible_operator_meta.namespace }}'
labels:
app.kubernetes.io/name: '{{ ansible_operator_meta.name }}-metrics-gather'
{{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(width=4) | trim }}
spec:
schedule: "{{ _metrics_cronjob_gather_schedule }}"
jobTemplate:
spec:
template:
spec:
containers:
- name: {{ ansible_operator_meta.name }}-metrics-gather
image: "{{ _metrics_image }}"
imagePullPolicy: "{{ image_pull_policy }}"
command:
- /bin/sh
- -c
- metrics-utility gather_automation_controller_billing_data --ship --until=10m
envFrom:
- configMapRef:
name: {{ _metrics_configmap }}
volumeMounts:
- name: {{ ansible_operator_meta.name }}-metrics
mountPath: /metrics
readOnly: false
- name: "{{ ansible_operator_meta.name }}-application-credentials"
mountPath: "/etc/tower/conf.d/credentials.py"
subPath: credentials.py
readOnly: true
- name: {{ ansible_operator_meta.name }}-settings
mountPath: /etc/tower/settings.py
subPath: settings.py
readOnly: true
volumes:
- name: {{ ansible_operator_meta.name }}-metrics
persistentVolumeClaim:
claimName: {{ _metrics_pvc_claim }}
readOnly: false
- name: "{{ ansible_operator_meta.name }}-application-credentials"
secret:
secretName: "{{ ansible_operator_meta.name }}-app-credentials"
items:
- key: credentials.py
path: 'credentials.py'
- name: {{ ansible_operator_meta.name }}-settings
configMap:
name: '{{ ansible_operator_meta.name }}-{{ deployment_type }}-configmap'
items:
- key: settings
path: settings.py
restartPolicy: OnFailure
56 changes: 56 additions & 0 deletions roles/installer/templates/cronjobs/metrics-report.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
apiVersion: v1
kind: CronJob
metadata:
name: {{ ansible_operator_meta.name }}-metrics-report
namespace: '{{ ansible_operator_meta.namespace }}'
labels:
app.kubernetes.io/name: '{{ ansible_operator_meta.name }}-metrics-report'
{{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(width=4) | trim }}
spec:
schedule: "{{ _metrics_cronjob_report_schedule }}"
jobTemplate:
spec:
template:
spec:
containers:
- name: {{ ansible_operator_meta.name }}-metrics-report
image: "{{ _metrics_image }}"
imagePullPolicy: "{{ image_pull_policy }}"
command:
- /bin/sh
- -c
- metrics-utility build_report
envFrom:
- configMapRef:
name: {{ _metrics_configmap }}
volumeMounts:
- name: {{ ansible_operator_meta.name }}-metrics
mountPath: /metrics
readOnly: false
- name: "{{ ansible_operator_meta.name }}-application-credentials"
mountPath: "/etc/tower/conf.d/credentials.py"
subPath: credentials.py
readOnly: true
- name: {{ ansible_operator_meta.name }}-settings
mountPath: /etc/tower/settings.py
subPath: settings.py
readOnly: true
volumes:
- name: {{ ansible_operator_meta.name }}-metrics
persistentVolumeClaim:
claimName: {{ _metrics_pvc_claim }}
readOnly: false
- name: "{{ ansible_operator_meta.name }}-application-credentials"
secret:
secretName: "{{ ansible_operator_meta.name }}-app-credentials"
items:
- key: credentials.py
path: 'credentials.py'
- name: {{ ansible_operator_meta.name }}-settings
configMap:
name: '{{ ansible_operator_meta.name }}-{{ deployment_type }}-configmap'
items:
- key: settings
path: settings.py
restartPolicy: OnFailure
15 changes: 15 additions & 0 deletions roles/installer/templates/storage/metrics.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ deployment_type }}-metrics-claim
namespace: {{ ansible_operator_meta.namespace }}
ownerReferences: null
labels:
{{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(width=4) | trim }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ metrics_storage_size | default('5Gi') }}

0 comments on commit c0dfff4

Please sign in to comment.