diff --git a/config/crd/bases/awx.ansible.com_awxs.yaml b/config/crd/bases/awx.ansible.com_awxs.yaml index 5137f5fae..34e441d13 100644 --- a/config/crd/bases/awx.ansible.com_awxs.yaml +++ b/config/crd/bases/awx.ansible.com_awxs.yaml @@ -1940,26 +1940,36 @@ spec: description: Metrics-Utility Image PullPolicy type: string metrics_utility_configmap: - description: Metrics-Utlity ConfigMap + description: Metrics-Utility ConfigMap + type: string + metrics_utility_secret: + description: Metrics-Utility Secret type: string metrics_utility_cronjob_gather_schedule: - description: Metrics-Utlity Gather Data CronJob Schedule + description: Metrics-Utility Gather Data CronJob Schedule type: string default: '@hourly' metrics_utility_cronjob_report_schedule: - description: Metrics-Utlity Report CronJob Schedule + description: Metrics-Utility Report CronJob Schedule type: string default: '@monthly' + metrics_utility_ship_target: + description: Metrics-Utility Ship Target + type: string metrics_utility_pvc_claim: - description: Metrics-Utlity PVC Claim + description: Metrics-Utility PVC Claim type: string metrics_utility_pvc_claim_size: - description: Metrics-Utlity PVC Claim Size + description: Metrics-Utility PVC Claim Size type: string default: 5Gi metrics_utility_pvc_claim_storage_class: - description: Metrics-Utlity PVC Claim Storage Class + description: Metrics-Utility PVC Claim Storage Class type: string + metrics_utility_console_enabled: + description: Enable metrics utility shipping to Red Hat Hybrid Cloud Console + type: boolean + default: false type: object status: properties: diff --git a/config/manifests/bases/awx-operator.clusterserviceversion.yaml b/config/manifests/bases/awx-operator.clusterserviceversion.yaml index 679585ca0..d7c9fa2de 100644 --- a/config/manifests/bases/awx-operator.clusterserviceversion.yaml +++ b/config/manifests/bases/awx-operator.clusterserviceversion.yaml @@ -1039,7 +1039,7 @@ spec: - urn:alm:descriptor:com.tectonic.ui:advanced - urn:alm:descriptor:com.tectonic.ui:text - urn:alm:descriptor:com.tectonic.ui:fieldDependency:metrics_utility_enabled:true - - displayName: Metrics-Utlity Image Version + - displayName: Metrics-Utility Image Version path: metrics_utility_image_version x-descriptors: - urn:alm:descriptor:com.tectonic.ui:advanced @@ -1051,42 +1051,60 @@ spec: - urn:alm:descriptor:com.tectonic.ui:advanced - urn:alm:descriptor:com.tectonic.ui:imagePullPolicy - urn:alm:descriptor:com.tectonic.ui:fieldDependency:metrics_utility_enabled:true - - displayName: Metrics-Utlity ConfigMap + - displayName: Metrics-Utility ConfigMap path: metrics_utility_configmap x-descriptors: - urn:alm:descriptor:com.tectonic.ui:advanced - urn:alm:descriptor:io.kubernetes:ConfigMap - urn:alm:descriptor:com.tectonic.ui:fieldDependency:metrics_utility_enabled:true - - displayName: Metrics-Utlity Gather Data CronJob Schedule + - displayName: Metrics-Utility Secret + path: metrics_utility_secret + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:advanced + - urn:alm:descriptor:io.kubernetes:Secret + - urn:alm:descriptor:com.tectonic.ui:fieldDependency:metrics_utility_enabled:true + - displayName: Metrics-Utility 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 - urn:alm:descriptor:com.tectonic.ui:fieldDependency:metrics_utility_enabled:true - - displayName: Metrics-Utlity Report CronJob Schedule + - displayName: Metrics-Utility 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 - urn:alm:descriptor:com.tectonic.ui:fieldDependency:metrics_utility_enabled:true - - displayName: Metrics-Utlity PVC Claim + - displayName: Metrics-Utility Ship Target + path: metrics_utility_ship_target + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:advanced + - urn:alm:descriptor:com.tectonic.ui:text + - urn:alm:descriptor:com.tectonic.ui:fieldDependency:metrics_utility_enabled:true + - displayName: Metrics-Utility PVC Claim path: metrics_utility_pvc_claim x-descriptors: - urn:alm:descriptor:com.tectonic.ui:advanced - urn:alm:descriptor:com.tectonic.ui:text - urn:alm:descriptor:com.tectonic.ui:fieldDependency:metrics_utility_enabled:true - - displayName: Metrics-Utlity PVC Claim Size + - displayName: Metrics-Utility 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 - urn:alm:descriptor:com.tectonic.ui:fieldDependency:metrics_utility_enabled:true - - displayName: Metrics-Utlity PVC Claim Storage Class + - displayName: Metrics-Utility 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 - urn:alm:descriptor:com.tectonic.ui:fieldDependency:metrics_utility_enabled:true + - displayName: Metrics-Utility Enabled Shipping to Red Hat Hybrid Cloud Console + path: metrics_utility_console_enabled + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:advanced + - urn:alm:descriptor:com.tectonic.ui:booleanSwitch + - urn:alm:descriptor:com.tectonic.ui:fieldDependency:metrics_utility_enabled:true statusDescriptors: - description: Route to access the instance deployed displayName: URL diff --git a/roles/installer/defaults/main.yml b/roles/installer/defaults/main.yml index 0651316cf..db9d586f6 100644 --- a/roles/installer/defaults/main.yml +++ b/roles/installer/defaults/main.yml @@ -494,9 +494,11 @@ 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_console_enabled: "{{ metrics_utility_console_enabled | default(false) }}" _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_ship_target: "{{ metrics_utility_ship_target | default('directory') }}" _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') }}" diff --git a/roles/installer/tasks/enable_metrics_utility.yml b/roles/installer/tasks/enable_metrics_utility.yml index d9e72a12a..ffbb98344 100644 --- a/roles/installer/tasks/enable_metrics_utility.yml +++ b/roles/installer/tasks/enable_metrics_utility.yml @@ -1,23 +1,42 @@ --- -# 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: Setup PVC if using directory ship target + block: -- name: Create PVC for metrics-utility + # Check to make sure provided pvc exists + - 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') }}" + + when: _metrics_utility_ship_target == "directory" + +- name: Create default metrics-utility Kubernetes CronJobs kubernetes.core.k8s: - kind: PersistentVolumeClaim - definition: "{{ lookup('template', 'storage/metrics-utility.yaml.j2') }}" + definition: "{{ lookup('template', item.template) }}" + apply: true + wait: true + vars: + cronjob_name: "{{ item.name }}" + loop: + - {name: 'metrics-utility-gather', template: 'cronjobs/metrics-utility-gather.yaml.j2'} + - {name: 'metrics-utility-report', template: 'cronjobs/metrics-utility-report.yaml.j2'} -- name: Create Kubernetes CronJobs for metrics-utility +- name: Create metrics-utility Kubernetes CronJob for Red Hat Hybrid Cloud Console kubernetes.core.k8s: - definition: "{{ lookup('template', item) }}" + definition: "{{ lookup('template', item.template) }}" apply: true wait: true + vars: + cronjob_name: "{{ item.name }}" + metrics_utility_ship_target: crc # TODO - Update to console when changed loop: - - cronjobs/metrics-utility-gather.yaml.j2 - - cronjobs/metrics-utility-report.yaml.j2 + - {name: 'metrics-utility-gather-console', template: 'cronjobs/metrics-utility-gather.yaml.j2'} + when: _metrics_utility_console_enabled diff --git a/roles/installer/templates/cronjobs/metrics-utility-gather.yaml.j2 b/roles/installer/templates/cronjobs/metrics-utility-gather.yaml.j2 index 35a5cbb4d..4e717a45d 100644 --- a/roles/installer/templates/cronjobs/metrics-utility-gather.yaml.j2 +++ b/roles/installer/templates/cronjobs/metrics-utility-gather.yaml.j2 @@ -2,10 +2,10 @@ apiVersion: batch/v1 kind: CronJob metadata: - name: {{ ansible_operator_meta.name }}-metrics-utility-gather + name: {{ ansible_operator_meta.name }}-{{ cronjob_name }} namespace: '{{ ansible_operator_meta.namespace }}' labels: - app.kubernetes.io/name: '{{ ansible_operator_meta.name }}-metrics-utility-gather' + app.kubernetes.io/name: '{{ ansible_operator_meta.name }}-{{ cronjob_name }}' {{ 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: @@ -16,7 +16,7 @@ spec: template: metadata: labels: - app.kubernetes.io/name: '{{ ansible_operator_meta.name }}-metrics-utility-gather' + app.kubernetes.io/name: '{{ ansible_operator_meta.name }}-{{ cronjob_name }}' {{ 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: @@ -30,7 +30,7 @@ spec: {% endfor %} {% endif %} containers: - - name: {{ ansible_operator_meta.name }}-metrics-utility-gather + - name: {{ ansible_operator_meta.name }}-{{ cronjob_name }} image: "{{ _metrics_utility_image }}" imagePullPolicy: "{{ image_pull_policy }}" resources: @@ -41,9 +41,16 @@ spec: - /bin/sh - -c - metrics-utility gather_automation_controller_billing_data --ship --until=10m + env: + - name: METRICS_UTILITY_SHIP_TARGET + value: "{{ _metrics_utility_ship_target }}" envFrom: - configMapRef: name: {{ _metrics_utility_configmap }} +{% if _metrics_utility_secret is defined %} + - secretRef: + name: {{ _metrics_utility_secret }} +{% endif %} volumeMounts: - name: {{ ansible_operator_meta.name }}-metrics-utility mountPath: /metrics-utility diff --git a/roles/installer/templates/cronjobs/metrics-utility-report.yaml.j2 b/roles/installer/templates/cronjobs/metrics-utility-report.yaml.j2 index 2a2a76607..c1e7aed76 100644 --- a/roles/installer/templates/cronjobs/metrics-utility-report.yaml.j2 +++ b/roles/installer/templates/cronjobs/metrics-utility-report.yaml.j2 @@ -2,10 +2,10 @@ apiVersion: batch/v1 kind: CronJob metadata: - name: {{ ansible_operator_meta.name }}-metrics-utility-report + name: {{ ansible_operator_meta.name }}-{{ cronjob_name }} namespace: '{{ ansible_operator_meta.namespace }}' labels: - app.kubernetes.io/name: '{{ ansible_operator_meta.name }}-metrics-utility-report' + app.kubernetes.io/name: '{{ ansible_operator_meta.name }}-{{ cronjob_name }}' {{ 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: @@ -16,7 +16,7 @@ spec: template: metadata: labels: - app.kubernetes.io/name: '{{ ansible_operator_meta.name }}-metrics-utility-report' + app.kubernetes.io/name: '{{ ansible_operator_meta.name }}-{{ cronjob_name }}' {{ 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: @@ -30,7 +30,7 @@ spec: {% endfor %} {% endif %} containers: - - name: {{ ansible_operator_meta.name }}-metrics-utility-report + - name: {{ ansible_operator_meta.name }}-{{ cronjob_name }} image: "{{ _metrics_utility_image }}" imagePullPolicy: "{{ image_pull_policy }}" resources: @@ -44,6 +44,10 @@ spec: envFrom: - configMapRef: name: {{ _metrics_utility_configmap }} +{% if _metrics_utility_secret is defined %} + - secretRef: + name: {{ _metrics_utility_secret }} +{% endif %} volumeMounts: - name: {{ ansible_operator_meta.name }}-metrics-utility mountPath: /metrics-utility