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

adding support for ansible metrics-utility #1754

Merged
merged 6 commits into from
Mar 20, 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
34 changes: 34 additions & 0 deletions config/crd/bases/awx.ansible.com_awxs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1923,6 +1923,40 @@ spec:
description: Disable web container's nginx ipv6 listener
type: boolean
default: false
metrics_utility_enabled:
description: Enable metrics utility
type: boolean
default: false
metrics_utility_image:
description: Metrics-Utility Image
type: string
metrics_utility_image_version:
description: Metrics-Utility Image Version
type: string
metrics_utility_image_pull_policy:
description: Metrics-Utility Image PullPolicy
type: string
metrics_utility_configmap:
description: Metrics-Utlity ConfigMap
type: string
metrics_utility_cronjob_gather_schedule:
description: Metrics-Utlity Gather Data CronJob Schedule
type: string
default: '@hourly'
metrics_utility_cronjob_report_schedule:
description: Metrics-Utlity Report CronJob Schedule
type: string
default: '@monthly'
metrics_utility_pvc_claim:
description: Metrics-Utlity PVC Claim
type: string
metrics_utility_pvc_claim_size:
description: Metrics-Utlity PVC Claim Size
type: string
default: 5Gi
metrics_utility_pvc_claim_storage_class:
description: Metrics-Utlity PVC Claim Storage Class
type: string
type: object
status:
properties:
Expand Down
50 changes: 50 additions & 0 deletions config/manifests/bases/awx-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,56 @@ spec:
path: image
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:text
- displayName: Metrics-Utility Enabled
path: metrics_utility_enabled
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- displayName: Metrics-Utility Image
path: metrics_utility_image
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:text
- displayName: Metrics-Utlity Image Version
path: metrics_utility_image_version
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:text
- displayName: Metrics-Utility Image PullPolicy
path: metrics_utility_image_pull_policy
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:imagePullPolicy
- displayName: Metrics-Utlity ConfigMap
path: metrics_utility_configmap
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:selector:core:v1:ConfigMap
- displayName: Metrics-Utlity Gather Data CronJob Schedule
path: metrics_utility_cronjob_gather_schedule
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:text
- displayName: Metrics-Utlity Report CronJob Schedule
path: metrics_utility_cronjob_report_schedule
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:text
- displayName: Metrics-Utlity PVC Claim
path: metrics_utility_pvc_claim
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:text
- displayName: Metrics-Utlity PVC Claim Size
path: metrics_utility_pvc_claim_size
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:text
- displayName: Metrics-Utlity PVC Claim Storage Class
path: metrics_utility_pvc_claim_storage_class
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:io.kubernetes:StorageClass
version: v1beta1
description: |
AWX is designed to help accelerate and scale your business through automation.
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
11 changes: 11 additions & 0 deletions roles/installer/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,14 @@ nginx_worker_processes: 1
nginx_worker_connections: "{{ uwsgi_listen_queue_size }}"
nginx_worker_cpu_affinity: 'auto'
nginx_listen_queue_size: "{{ uwsgi_listen_queue_size }}"

# metrics-utility (github.com/ansible/metrics-utility)
_metrics_utility_enabled: "{{ metrics_utility_enabled | default(false) }}"
_metrics_utility_configmap: "{{ metrics_utility_configmap | default(deployment_type + '-metrics-utility-configmap') }}"
_metrics_utility_image: "{{ metrics_utility_image | default(_image) }}"
_metrics_utility_image_version: "{{ metrics_utility_image_version | default(_image_version) }}"
_metrics_utility_image_pull_policy: "{{ metrics_utility_image_pull_policy | default('IfNotPresent') }}"
_metrics_utility_pvc_claim: "{{ metrics_utility_pvc_claim | default(deployment_type + '-metrics-utility') }}"
_metrics_utility_pvc_claim_size: "{{ metrics_utility_pvc_claim_size | default('5Gi') }}"
_metrics_utility_cronjob_gather_schedule: "{{ metrics_utility_cronjob_gather_schedule | default('@hourly') }}"
_metrics_utility_cronjob_report_schedule: "{{ metrics_utility_cronjob_report_schedule | default('@monthly') }}"
23 changes: 23 additions & 0 deletions roles/installer/tasks/enable_metrics_utility.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
# 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_utility_pvc_claim }}"
kind: PersistentVolumeClaim
namespace: "{{ ansible_operator_meta.namespace }}"
when:
- _metrics_utility_pvc_claim | length

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

- name: Create Kubernetes CronJobs for metrics-utility
kubernetes.core.k8s:
definition: "{{ lookup('template', item) }}"
apply: true
wait: true
loop:
- cronjobs/metrics-utility-gather.yaml.j2
- cronjobs/metrics-utility-report.yaml.j2
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-utility
include_tasks: enable_metrics_utility.yml
when: metrics_utility_enabled | bool

- name: Update status variables
include_tasks: update_status.yml

Expand Down
76 changes: 76 additions & 0 deletions roles/installer/templates/cronjobs/metrics-utility-gather.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ ansible_operator_meta.name }}-metrics-utility-gather
namespace: '{{ ansible_operator_meta.namespace }}'
labels:
app.kubernetes.io/name: '{{ ansible_operator_meta.name }}-metrics-utility-gather'
{{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(width=4) | trim }}
{{ lookup("template", "../common/templates/labels/version.yaml.j2") | indent(width=4) | trim }}
spec:
schedule: "{{ _metrics_utility_cronjob_gather_schedule }}"
jobTemplate:
spec:
backoffLimit: 2
template:
metadata:
labels:
app.kubernetes.io/name: '{{ ansible_operator_meta.name }}-metrics-utility-gather'
{{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(width=12) | trim }}
{{ lookup("template", "../common/templates/labels/version.yaml.j2") | indent(width=12) | trim }}
spec:
{% if image_pull_secret is defined %}
imagePullSecrets:
- name: {{ image_pull_secret }}
{% elif image_pull_secrets | length > 0 %}
imagePullSecrets:
{% for secret in image_pull_secrets %}
- name: {{ secret }}
{% endfor %}
{% endif %}
containers:
- name: {{ ansible_operator_meta.name }}-metrics-utility-gather
image: "{{ _metrics_utility_image }}"
imagePullPolicy: "{{ image_pull_policy }}"
resources:
requests:
memory: "100Mi"
cpu: "100m"
command:
- /bin/sh
- -c
- metrics-utility gather_automation_controller_billing_data --ship --until=10m
envFrom:
- configMapRef:
name: {{ _metrics_utility_configmap }}
volumeMounts:
- name: {{ ansible_operator_meta.name }}-metrics-utility
mountPath: /metrics-utility
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-utility
persistentVolumeClaim:
claimName: {{ _metrics_utility_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
76 changes: 76 additions & 0 deletions roles/installer/templates/cronjobs/metrics-utility-report.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ ansible_operator_meta.name }}-metrics-utility-report
namespace: '{{ ansible_operator_meta.namespace }}'
labels:
app.kubernetes.io/name: '{{ ansible_operator_meta.name }}-metrics-utility-report'
{{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(width=4) | trim }}
{{ lookup("template", "../common/templates/labels/version.yaml.j2") | indent(width=4) | trim }}
spec:
schedule: "{{ _metrics_utility_cronjob_report_schedule }}"
jobTemplate:
spec:
backoffLimit: 2
template:
metadata:
labels:
app.kubernetes.io/name: '{{ ansible_operator_meta.name }}-metrics-utility-report'
{{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(width=12) | trim }}
{{ lookup("template", "../common/templates/labels/version.yaml.j2") | indent(width=12) | trim }}
spec:
{% if image_pull_secret is defined %}
imagePullSecrets:
- name: {{ image_pull_secret }}
{% elif image_pull_secrets | length > 0 %}
imagePullSecrets:
{% for secret in image_pull_secrets %}
- name: {{ secret }}
{% endfor %}
{% endif %}
containers:
- name: {{ ansible_operator_meta.name }}-metrics-utility-report
image: "{{ _metrics_utility_image }}"
imagePullPolicy: "{{ image_pull_policy }}"
resources:
requests:
memory: "100Mi"
cpu: "100m"
command:
- /bin/sh
- -c
- metrics-utility build_report
envFrom:
- configMapRef:
name: {{ _metrics_utility_configmap }}
volumeMounts:
- name: {{ ansible_operator_meta.name }}-metrics-utility
mountPath: /metrics-utility
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-utility
persistentVolumeClaim:
claimName: {{ _metrics_utility_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
18 changes: 18 additions & 0 deletions roles/installer/templates/storage/metrics-utility.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ _metrics_utility_pvc_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_utility_pvc_claim_size }}
{% if metrics_utility_pvc_claim_storage_class is defined %}
storageClassName: {{ metrics_utility_pvc_claim_storage_class }}
{% endif %}
Loading