Skip to content
This repository was archived by the owner on Jun 12, 2023. It is now read-only.

Commit d19b91b

Browse files
authored
Merge pull request #67 from fromanirh/metrics-aggregation
roles: add role to deploy metric aggregation rules
2 parents ac082e9 + 19778d8 commit d19b91b

16 files changed

+164
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: kubevirt.io/v1
2+
kind: KubevirtMetricAggregation
3+
metadata:
4+
name: kubevirt-metrics-aggregation
5+
spec:
6+
version: v0.0.1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: kubevirtmetricsaggregations.kubevirt.io
5+
spec:
6+
group: kubevirt.io
7+
names:
8+
kind: KubevirtMetricsAggregation
9+
listKind: KubevirtMetricsAggregationList
10+
plural: kubevirtmetricsaggregations
11+
singular: kubevirtmetricsaggregation
12+
scope: Namespaced
13+
version: v1
14+
subresources:
15+
status: {}
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
SCRIPTPATH=$( dirname $(readlink -f $0) )
4+
source ${SCRIPTPATH}/testlib.sh
5+
6+
RET=1
7+
TEST_NS="openshift" # TODO: check this exists?
8+
9+
{ oc get crds | grep -q prometheusrule; } || exit 99
10+
11+
oc create -n ${TEST_NS} -f "${SCRIPTPATH}/aggregation-rules-unversioned-cr.yaml" || exit 2
12+
# TODO: SSP-operator needs to improve its feedback mechanism
13+
sleep 21s
14+
for idx in $( seq 1 30); do
15+
NUM=$(oc get prometheusrules -n ${TEST_NS} -l "role=cnv-rules" -o json | jq ".items | length")
16+
(( ${V} >= 1 )) && echo "prometheus rules found in ${TEST_NS}: ${NUM}"
17+
if (( "${NUM}" > 0 )); then
18+
(( ${V} >= 1 )) && echo "enough prometheus rules found in ${TEST_NS}"
19+
RET=0
20+
break
21+
fi
22+
sleep 3s
23+
done
24+
oc delete -n ${TEST_NS} -f "${SCRIPTPATH}/aggregation-rules-unversioned-cr.yaml" || exit 2
25+
26+
exit $RET
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: kubevirt.io/v1
2+
kind: KubevirtMetricsAggregation
3+
metadata:
4+
name: kubevirt-metrics-aggregation

functests/test-runner.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ done
2222

2323
# we can run the real tests now
2424
RET=0
25-
for testscript in $( ls ??-test-*.sh); do
25+
for testscript in $( ls *-test-*.sh); do
2626
testname=$(basename -- "$testscript")
2727
testname="${testname%.*}" # see http://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
2828

@@ -33,10 +33,11 @@ for testscript in $( ls ??-test-*.sh); do
3333
printf "* TESTCASE [%-64s] START\n" $testscript
3434
./$testscript
3535
fi
36-
if [ "$?" == "0" ]; then
36+
RC="$?"
37+
if [ "$RC" == "0" ]; then
3738
result="OK"
3839
else
39-
if [ "$?" == "99" ] ; then
40+
if [ "$RC" == "99" ] ; then
4041
result="SKIP"
4142
else
4243
result="FAILED"

hack/install-operator.sh

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ _curl() {
1919
oc create -f ${BASEPATH}/../deploy/crds/kubevirt_v1_commontemplatesbundle_crd.yaml
2020
oc create -f ${BASEPATH}/../deploy/crds/kubevirt_v1_nodelabellerbundle_crd.yaml
2121
oc create -f ${BASEPATH}/../deploy/crds/kubevirt_v1_templatevalidator_crd.yaml
22+
oc create -f ${BASEPATH}/../deploy/crds/kubevirt_v1_metricsaggregation_crd.yaml
2223

2324
LAST_TAG=""
2425
if [ "${CI}" != "true" ] || [ "${TRAVIS}" != "true" ]; then

playbooks/metricsaggregation.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- hosts: localhost
2+
gather_facts: no
3+
vars_files:
4+
- _defaults.yml
5+
roles:
6+
- KubevirtMetricsAggregation
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# defaults file for KubevirtMetricsAggregation
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# handlers file for KubevirtMetricsAggregation
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
galaxy_info:
2+
author: your name
3+
description: your description
4+
company: your company (optional)
5+
6+
# If the issue tracker for your role is not on github, uncomment the
7+
# next line and provide a value
8+
# issue_tracker_url: http://example.com/issue/tracker
9+
10+
# Some suggested licenses:
11+
# - BSD (default)
12+
# - MIT
13+
# - GPLv2
14+
# - GPLv3
15+
# - Apache
16+
# - CC-BY
17+
license: license (GPLv2, CC-BY, etc)
18+
19+
min_ansible_version: 2.4
20+
21+
# If this a Container Enabled role, provide the minimum Ansible Container version.
22+
# min_ansible_container_version:
23+
24+
# Optionally specify the branch Galaxy will use when accessing the GitHub
25+
# repo for this role. During role install, if no tags are available,
26+
# Galaxy will use this branch. During import Galaxy will access files on
27+
# this branch. If Travis integration is configured, only notifications for this
28+
# branch will be accepted. Otherwise, in all cases, the repo's default branch
29+
# (usually master) will be used.
30+
#github_branch:
31+
32+
#
33+
# Provide a list of supported platforms, and for each platform a list of versions.
34+
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
35+
# To view available platforms and versions (or releases), visit:
36+
# https://galaxy.ansible.com/api/v1/platforms/
37+
#
38+
# platforms:
39+
# - name: Fedora
40+
# versions:
41+
# - all
42+
# - 25
43+
# - name: SomePlatform
44+
# versions:
45+
# - all
46+
# - 1.0
47+
# - 7
48+
# - 99.99
49+
50+
galaxy_tags: []
51+
# List tags for your role here, one per line. A tag is a keyword that describes
52+
# and categorizes the role. Users find roles by searching for tags. Be sure to
53+
# remove the '[]' above, if you add tags to this list.
54+
#
55+
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
56+
# Maximum 20 tags per role.
57+
58+
dependencies: []
59+
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
60+
# if you add dependencies to this list.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
# tasks file for KubevirtMetricsAggregation
3+
- name: Install VMI count aggregation rule
4+
k8s:
5+
state: present
6+
namespace: "{{ meta.namespace }}"
7+
definition: "{{ item | from_yaml }}"
8+
with_items: "{{ lookup('template', 'aggregation-rule-vmi-count.yaml.j2').split('\n---\n') | select('search', '(^|\n)[^#]') |list }}"
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: monitoring.coreos.com/v1
2+
kind: PrometheusRule
3+
metadata:
4+
labels:
5+
prometheus: k8s
6+
role: cnv-rules
7+
name: prometheus-k8s-rules-cnv
8+
namespace: "{{ meta.namespace }}"
9+
spec:
10+
groups:
11+
- name: cnv.rules
12+
rules:
13+
- expr: |
14+
sum(kubevirt_vmi_phase_count{phase="running"}) by (node)
15+
record: cnv:vmi_status_running:count
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
localhost
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- hosts: localhost
3+
remote_user: root
4+
roles:
5+
- KubevirtMetricsAggregation
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# vars file for KubevirtMetricsAggregation

watches.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@
1111
group: kubevirt.io
1212
kind: KubevirtNodeLabellerBundle
1313
playbook: /opt/ansible/kubevirtnodelabeller.yaml
14+
- version: v1
15+
group: kubevirt.io
16+
kind: KubevirtMetricsAggregation
17+
playbook: /opt/ansible/metricsaggregation.yaml

0 commit comments

Comments
 (0)