diff --git a/chart/test-values.yaml b/chart/test-values.yaml index f69369b0..96050d07 100644 --- a/chart/test-values.yaml +++ b/chart/test-values.yaml @@ -15,4 +15,4 @@ configMap: configDir: /etc/heat magnum: configDir: /etc/magnum - chronyd: {} \ No newline at end of file + chronyd: {} diff --git a/config/samples/operator-config.yaml b/config/samples/operator-config.yaml index 115059f8..137a0f4f 100644 --- a/config/samples/operator-config.yaml +++ b/config/samples/operator-config.yaml @@ -19,4 +19,4 @@ data: api-cfn: "h-api-cfn.vexxhost.com" magnum: configDir: /etc/magnum - chronyd: {} \ No newline at end of file + chronyd: {} diff --git a/openstack_operator/libvirtd_exporter.py b/openstack_operator/libvirtd_exporter.py new file mode 100644 index 00000000..3ee15b4d --- /dev/null +++ b/openstack_operator/libvirtd_exporter.py @@ -0,0 +1,34 @@ +# Copyright 2020 VEXXHOST, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""libvirtd-exporter Operator + +This module maintains the operator for libvirtd-exporter, +it takes care of creating the appropriate daemonset +""" + + +from openstack_operator import utils + + +def create_or_resume(spec, **_): + """Create and re-sync a libvirtd-exporter instance + + This function is called when a new resource is created but also when we + start the service up for the first time. + """ + + utils.create_or_update('libvirtd_exporter/daemonset.yml.j2', + spec=spec) + utils.create_or_update('libvirtd_exporter/podmonitor.yml.j2') diff --git a/openstack_operator/operator.py b/openstack_operator/operator.py index d9be162b..84069ae1 100644 --- a/openstack_operator/operator.py +++ b/openstack_operator/operator.py @@ -28,6 +28,7 @@ from openstack_operator import glance from openstack_operator import heat from openstack_operator import horizon from openstack_operator import keystone +from openstack_operator import libvirtd_exporter from openstack_operator import magnum from openstack_operator import utils @@ -67,7 +68,17 @@ def deploy(name, namespace, new, **_): glance.create_or_resume("glance", config["glance"]) if "magnum" in config: magnum.create_or_resume("magnum", config["magnum"]) - if "chronyd" in config: - chronyd.create_or_resume(config["chronyd"]) if "ceilometer" in config: ceilometer.create_or_resume(config["ceilometer"]) + + if "chronyd" in config: + spec = config["chronyd"] + else: + spec = {} + chronyd.create_or_resume(spec) + + if "libvirtd-exporter" in config: + spec = config["libvirtd-exporter"] + else: + spec = {} + libvirtd_exporter.create_or_resume(spec) diff --git a/openstack_operator/templates/libvirtd_exporter/daemonset.yml.j2 b/openstack_operator/templates/libvirtd_exporter/daemonset.yml.j2 new file mode 100644 index 00000000..697746ed --- /dev/null +++ b/openstack_operator/templates/libvirtd_exporter/daemonset.yml.j2 @@ -0,0 +1,65 @@ +--- +# Copyright 2020 VEXXHOST, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: libvirtd-exporter + namespace: openstack + labels: + {{ labels("libvirtd-exporter", "libvirtd-exporter") | indent(4) }} +spec: + selector: + matchLabels: + {{ labels("libvirtd-exporter", "libvirtd-exporter") | indent(6) }} + template: + metadata: + labels: + {{ labels("libvirtd-exporter", "libvirtd-exporter") | indent(8) }} + spec: + containers: + - name: main + image: vexxhost/libvirtd-exporter:latest + imagePullPolicy: Always + ports: + - name: metrics + protocol: TCP + containerPort: 9474 + livenessProbe: + httpGet: + path: / + port: metrics + readinessProbe: + httpGet: + path: / + port: metrics + resources: + limits: + cpu: 500m + ephemeral-storage: 100M + memory: 256M + requests: + cpu: 250m + ephemeral-storage: 100M + memory: 128M + volumeMounts: + - mountPath: /var/run/libvirt + name: sock + volumes: + - name: sock + hostPath: + path: /var/run/libvirt + nodeSelector: + node-role.openstack.org: "compute" diff --git a/openstack_operator/templates/libvirtd_exporter/podmonitor.yml.j2 b/openstack_operator/templates/libvirtd_exporter/podmonitor.yml.j2 new file mode 100644 index 00000000..1cffd30e --- /dev/null +++ b/openstack_operator/templates/libvirtd_exporter/podmonitor.yml.j2 @@ -0,0 +1,29 @@ +--- +# Copyright 2020 VEXXHOST, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: libvirtd-exporter + namespace: openstack + labels: + {{ labels("libvirtd-exporter", "libvirtd-exporter") | indent(4) }} +spec: + podMetricsEndpoints: + - path: /metrics + port: metrics + selector: + matchLabels: + {{ labels("libvirtd-exporter", "libvirtd-exporter") | indent(6) }} diff --git a/openstack_operator/tests/unit/base.py b/openstack_operator/tests/unit/base.py index 492b0df9..cd769540 100644 --- a/openstack_operator/tests/unit/base.py +++ b/openstack_operator/tests/unit/base.py @@ -47,8 +47,11 @@ class KubernetesObjectTestCase(testtools.TestCase): with open(config_path) as config_fd: sample = yaml.load(config_fd, Loader=yaml.FullLoader) name = sample['metadata']['name'] - spec = utils.to_dict( - sample['data']['operator-config.yaml'])[cls.RELEASE_TYPE] + config = utils.to_dict(sample['data']['operator-config.yaml']) + if cls.RELEASE_TYPE in config: + spec = config[cls.RELEASE_TYPE] + else: + spec = {} cls.object = utils.render_template(cls.TEMPLATE_FILE, name=cls.RELEASE_TYPE, spec=spec,