diff --git a/operator/config/rbac/leader_election_role.yaml b/operator/config/rbac/leader_election_role.yaml index 7cff90f47..54bd8ac54 100644 --- a/operator/config/rbac/leader_election_role.yaml +++ b/operator/config/rbac/leader_election_role.yaml @@ -15,6 +15,7 @@ rules: - events - configmaps - secrets + - namespaces verbs: - '*' - apiGroups: @@ -39,6 +40,10 @@ rules: verbs: - get - create + - update + - patch + - list + - watch - apiGroups: - apps.openshift.io resources: diff --git a/operator/config/rbac/role.yaml b/operator/config/rbac/role.yaml index c37828a77..ab6106a35 100644 --- a/operator/config/rbac/role.yaml +++ b/operator/config/rbac/role.yaml @@ -4,6 +4,13 @@ kind: ClusterRole metadata: name: manager-role rules: +- apiGroups: + - '' + resources: + - namespaces + verbs: + - list + - watch - apiGroups: - config.openshift.io resources: diff --git a/operator/roles/forkliftcontroller/defaults/main.yml b/operator/roles/forkliftcontroller/defaults/main.yml index 3faa69de6..788864b87 100644 --- a/operator/roles/forkliftcontroller/defaults/main.yml +++ b/operator/roles/forkliftcontroller/defaults/main.yml @@ -112,3 +112,8 @@ virt_v2v_warm_image_fqin: "{{ lookup( 'env', 'VIRT_V2V_WARM_IMAGE') or lookup( ' virt_v2v_dont_request_kvm: "{{ lookup( 'env', 'VIRT_V2V_DONT_REQUEST_KVM') }}" ova_provider_server_fqin: "{{ lookup( 'env', 'OVA_PROVIDER_SERVER_IMAGE') or lookup( 'env', 'RELATED_IMAGE_OVA_PROVIDER_SERVER') }}" + +metric_service_name: "{{ app_name }}-metrics" +metric_servicemonitor_name: "{{ app_name }}-metrics" +metric_interval: "30s" +metric_port_name: "metrics" \ No newline at end of file diff --git a/operator/roles/forkliftcontroller/tasks/main.yml b/operator/roles/forkliftcontroller/tasks/main.yml index 8acf71b09..9eb622cb8 100644 --- a/operator/roles/forkliftcontroller/tasks/main.yml +++ b/operator/roles/forkliftcontroller/tasks/main.yml @@ -79,6 +79,29 @@ definition: "{{ lookup('template', 'controller/controller-scc.yml.j2') }}" when: not k8s_cluster|bool + - when: not k8s_cluster|bool + block: + - name: "Setup metrics service" + k8s: + state: present + definition: "{{ lookup('template', 'monitor/service-metrics.yml.j2') }}" + + - name: "Setup metrics service monitor" + k8s: + state: present + definition: "{{ lookup('template', 'monitor/servicemonitor-metrics.yml.j2') }}" + + - name: "Add monitoring label to namespace" + k8s: + state: present + definition: + apiVersion: v1 + kind: Namespace + metadata: + name: "{{ app_namespace }}" + labels: + openshift.io/cluster-monitoring: "true" + - when: feature_volume_populator|bool block: - name: "Setup populator controller deployment" diff --git a/operator/roles/forkliftcontroller/templates/controller/deployment-controller.yml.j2 b/operator/roles/forkliftcontroller/templates/controller/deployment-controller.yml.j2 index 5ad44b316..a6776dabb 100644 --- a/operator/roles/forkliftcontroller/templates/controller/deployment-controller.yml.j2 +++ b/operator/roles/forkliftcontroller/templates/controller/deployment-controller.yml.j2 @@ -21,6 +21,7 @@ spec: app: {{ app_name }} control-plane: controller-manager controller-tools.k8s.io: "1.0" + prometheus.forklift.konveyor.io: "true" annotations: configHash: "{{ (inventory_volume_path | string) }}" spec: diff --git a/operator/roles/forkliftcontroller/templates/monitor/service-metrics.yml.j2 b/operator/roles/forkliftcontroller/templates/monitor/service-metrics.yml.j2 new file mode 100644 index 000000000..4af645b4a --- /dev/null +++ b/operator/roles/forkliftcontroller/templates/monitor/service-metrics.yml.j2 @@ -0,0 +1,22 @@ +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: {{ app_name }} + service: {{ metric_service_name }} + prometheus.forklift.konveyor.io: "true" + control-plane: controller-manager + controller-tools.k8s.io: "1.0" + name: {{ metric_service_name }} + namespace: {{ app_namespace }} +spec: + ports: + - name: {{ metric_port_name }} + port: 2112 + targetPort: 2112 + protocol: TCP + selector: + app: {{ app_name }} + prometheus.forklift.konveyor.io: "true" + controller-tools.k8s.io: "1.0" diff --git a/operator/roles/forkliftcontroller/templates/monitor/servicemonitor-metrics.yml.j2 b/operator/roles/forkliftcontroller/templates/monitor/servicemonitor-metrics.yml.j2 new file mode 100644 index 000000000..a049f2b90 --- /dev/null +++ b/operator/roles/forkliftcontroller/templates/monitor/servicemonitor-metrics.yml.j2 @@ -0,0 +1,21 @@ +--- +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ metric_servicemonitor_name }} + namespace: {{ app_namespace }} + labels: + app: {{ app_name }} + prometheus.forklift.konveyor.io: "true" + control-plane: controller-manager +spec: + endpoints: + - interval: {{ metric_interval }} + port: {{ metric_port_name }} + namespaceSelector: + matchNames: + - {{ app_namespace }} + selector: + matchLabels: + app: {{ app_name }} + prometheus.forklift.konveyor.io: "true"