From f2bf41d3e7f254b3da35154417ba1e38d6688d53 Mon Sep 17 00:00:00 2001 From: Mohammed Naser Date: Sat, 25 Apr 2020 09:10:58 -0400 Subject: [PATCH] Add basic heat support Change-Id: Iabab0770fd03fa11845ac175b13886cdfa8a42d8 --- Makefile | 3 + .../orchestration.openstack.org_heats.yaml | 24 ++++++ chart/templates/clusterrole.yaml | 20 +++++ chart/templates/deployment.yaml | 2 + .../samples/orchestration_v1alpha1_heat.yaml | 7 ++ hack/update-zuul-jobs.py | 5 +- images/heat/Dockerfile | 37 +++++++++ images/heat/bindep.txt | 2 + openstack_operator/heat.py | 43 ++++++++++ .../templates/heat/deployment.yml.j2 | 80 +++++++++++++++++++ .../templates/heat/service.yml.j2 | 27 +++++++ openstack_operator/tests/unit/test_heat.py | 27 +++++++ zuul.d/ceilometer-jobs.yaml | 3 + zuul.d/functional-jobs.yaml | 36 +++++---- zuul.d/heat-jobs.yaml | 45 +++++++++++ 15 files changed, 342 insertions(+), 19 deletions(-) create mode 100644 chart/crds/orchestration.openstack.org_heats.yaml create mode 100644 config/samples/orchestration_v1alpha1_heat.yaml create mode 100644 images/heat/Dockerfile create mode 100644 images/heat/bindep.txt create mode 100644 openstack_operator/heat.py create mode 100644 openstack_operator/templates/heat/deployment.yml.j2 create mode 100644 openstack_operator/templates/heat/service.yml.j2 create mode 100644 openstack_operator/tests/unit/test_heat.py create mode 100644 zuul.d/heat-jobs.yaml diff --git a/Makefile b/Makefile index 8f5bdc72..0e8777f2 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ images: docker build images/horizon -t vexxhost/horizon:latest docker build images/ceilometer --target ceilometer-agent-notification -t vexxhost/ceilometer-agent-notification:latest + docker build images/heat --target heat-api -t vexxhost/heat-api:latest + docker build images/heat --target heat-api-cfn -t vexxhost/heat-api-cfn:latest + docker build images/heat --target heat-engine -t vexxhost/heat-engine:latest docker build images/mcrouter -t vexxhost/mcrouter:latest docker build images/mcrouter-exporter -t vexxhost/mcrouter-exporter:latest docker build images/memcached -t vexxhost/memcached:latest diff --git a/chart/crds/orchestration.openstack.org_heats.yaml b/chart/crds/orchestration.openstack.org_heats.yaml new file mode 100644 index 00000000..bab31818 --- /dev/null +++ b/chart/crds/orchestration.openstack.org_heats.yaml @@ -0,0 +1,24 @@ +--- +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: heats.orchestration.openstack.org +spec: + group: orchestration.openstack.org + names: + kind: Heat + listKind: HeatList + plural: heats + singular: heat + scope: Namespaced + version: v1alpha1 + versions: + - name: v1alpha1 + served: true + storage: true +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] diff --git a/chart/templates/clusterrole.yaml b/chart/templates/clusterrole.yaml index 89da1440..78d98dbb 100644 --- a/chart/templates/clusterrole.yaml +++ b/chart/templates/clusterrole.yaml @@ -131,6 +131,26 @@ rules: - get - patch - update +- apiGroups: + - orchestration.openstack.org + resources: + - heats + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - orchestration.openstack.org + resources: + - heats/status + verbs: + - get + - patch + - update - apiGroups: - dashboard.openstack.org resources: diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml index 2c2e9ad9..e7455822 100644 --- a/chart/templates/deployment.yaml +++ b/chart/templates/deployment.yaml @@ -29,6 +29,8 @@ spec: args: - run - -m + - openstack_operator.heat + - -m - openstack_operator.horizon - -m - openstack_operator.keystone diff --git a/config/samples/orchestration_v1alpha1_heat.yaml b/config/samples/orchestration_v1alpha1_heat.yaml new file mode 100644 index 00000000..7981ea3b --- /dev/null +++ b/config/samples/orchestration_v1alpha1_heat.yaml @@ -0,0 +1,7 @@ +--- +apiVersion: orchestration.openstack.org/v1alpha1 +kind: Heat +metadata: + name: sample +spec: + configDir: /etc/heat diff --git a/hack/update-zuul-jobs.py b/hack/update-zuul-jobs.py index 37ba2092..d3189e8a 100755 --- a/hack/update-zuul-jobs.py +++ b/hack/update-zuul-jobs.py @@ -51,9 +51,8 @@ for image in images: continue if len(line.value) >= 3 and line.value[1].lower() != 'as': continue - if line.value[0] != image: - continue - targets.append(line.value[2]) + if len(line.value) >= 3 and image in line.value[2]: + targets.append(line.value[2]) # Update images if we have more than 1 target if targets: diff --git a/images/heat/Dockerfile b/images/heat/Dockerfile new file mode 100644 index 00000000..db7fcfd7 --- /dev/null +++ b/images/heat/Dockerfile @@ -0,0 +1,37 @@ +# Copyright (c) 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. + +FROM docker.io/opendevorg/python-builder as builder +COPY bindep.txt /tmp/src/bindep.txt +RUN assemble openstack-heat==13.0.1 python-memcached + +FROM docker.io/opendevorg/uwsgi-base AS heat-api-base +COPY --from=builder /output/ /output +RUN /output/install-from-bindep +RUN ln -s /usr/local/etc/heat /etc/heat + +FROM heat-api-base AS heat-api +EXPOSE 8004 +ENV UWSGI_HTTP_SOCKET=:8004 UWSGI_WSGI_FILE=/usr/local/bin/heat-wsgi-api + +FROM heat-api-base AS heat-api-cfn +EXPOSE 8000 +ENV UWSGI_HTTP_SOCKET=:8000 UWSGI_WSGI_FILE=/usr/local/bin/heat-wsgi-api-cfn + +FROM docker.io/opendevorg/python-base AS heat-engine +COPY --from=builder /output/ /output +RUN /output/install-from-bindep +RUN ln -s /usr/local/etc/heat /etc/heat +CMD ["/usr/local/bin/heat-engine"] diff --git a/images/heat/bindep.txt b/images/heat/bindep.txt new file mode 100644 index 00000000..64b038ba --- /dev/null +++ b/images/heat/bindep.txt @@ -0,0 +1,2 @@ +gcc [compile] +libc-dev [compile] diff --git a/openstack_operator/heat.py b/openstack_operator/heat.py new file mode 100644 index 00000000..84baa525 --- /dev/null +++ b/openstack_operator/heat.py @@ -0,0 +1,43 @@ +# 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. + +"""Heat Operator + +This module maintains the operator for Heat, it takes care of creating +the appropriate deployments, an instance of Memcache, RabbitMQ and a database +server for the installation. +""" + +import kopf + +from openstack_operator import utils + + +@kopf.on.resume('orchestration.openstack.org', 'v1alpha1', 'heats') +@kopf.on.create('orchestration.openstack.org', 'v1alpha1', 'heats') +def create_or_resume(name, spec, **_): + """Create and re-sync any Heat instances + + This function is called when a new resource is created but also when we + start the service up for the first time. + """ + + for component in ("api", "api-cfn"): + utils.create_or_update('heat/deployment.yml.j2', + name=name, spec=spec, component=component) + utils.create_or_update('heat/service.yml.j2', + name=name, component=component) + + utils.create_or_update('heat/deployment.yml.j2', + name=name, spec=spec, component='engine') diff --git a/openstack_operator/templates/heat/deployment.yml.j2 b/openstack_operator/templates/heat/deployment.yml.j2 new file mode 100644 index 00000000..33242463 --- /dev/null +++ b/openstack_operator/templates/heat/deployment.yml.j2 @@ -0,0 +1,80 @@ +--- +# 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. + +{% if component is defined %} +{% set component = component %} +{% else %} +{% set component = "api" %} +{% endif %} + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: heat-{{ name }}-{{ component }} + labels: + {{ labels("heat", name, component) | indent(4) }} +spec: + replicas: 3 + selector: + matchLabels: + {{ labels("heat", name, component) | indent(6) }} + template: + metadata: + labels: + {{ labels("heat", name, component) | indent(8) }} + spec: + containers: + - name: heat-{{ component }} + image: vexxhost/heat-{{ component }}:latest + imagePullPolicy: Always + {% if 'api' in component %} + ports: + - name: heat-{{ component }} + containerPort: {% if component == 'api' %}8004{% else %}8000{% endif%} + livenessProbe: + tcpSocket: + port: heat-{{ component }} + readinessProbe: + tcpSocket: + port: heat-{{ component }} + {% endif %} + resources: + limits: + cpu: 1000m + ephemeral-storage: 50M + memory: 512M + requests: + cpu: 50m + ephemeral-storage: 50M + memory: 64M + securityContext: + runAsUser: 65534 + runAsGroup: 65534 + volumeMounts: + - mountPath: /etc/heat + name: config + volumes: + - name: config + hostPath: + path: {{ spec['configDir'] }} + type: Directory +{% if 'nodeSelector' in spec %} + nodeSelector: + {{ spec.nodeSelector | to_yaml | indent(8) }} +{% endif %} +{% if 'tolerations' in spec %} + tolerations: + {{ spec.tolerations | to_yaml | indent(8) }} +{% endif %} diff --git a/openstack_operator/templates/heat/service.yml.j2 b/openstack_operator/templates/heat/service.yml.j2 new file mode 100644 index 00000000..018886f1 --- /dev/null +++ b/openstack_operator/templates/heat/service.yml.j2 @@ -0,0 +1,27 @@ +--- +# 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: v1 +kind: Service +metadata: + name: heat-{{ name }}-{{ component }} +spec: + serviceType: ClusterIP + ports: + - name: heat-{{ component }} + port: 80 + targetPort: heat-{{ component }} + selector: + {{ labels("heat", name, component) | indent(4) }} diff --git a/openstack_operator/tests/unit/test_heat.py b/openstack_operator/tests/unit/test_heat.py new file mode 100644 index 00000000..4a38ffed --- /dev/null +++ b/openstack_operator/tests/unit/test_heat.py @@ -0,0 +1,27 @@ +# 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. + +"""Tests for Heat Operator + +This module contains all the tests for the Heat operator. +""" + +from openstack_operator.tests.unit import base + + +class HeatAPIDeploymentTestCase(base.DeploymentTestCase): + """Basic tests for the Deployment.""" + + SAMPLE_FILE = 'orchestration_v1alpha1_heat.yaml' + TEMPLATE_FILE = 'heat/deployment.yml.j2' diff --git a/zuul.d/ceilometer-jobs.yaml b/zuul.d/ceilometer-jobs.yaml index e4e897a4..01a149bb 100644 --- a/zuul.d/ceilometer-jobs.yaml +++ b/zuul.d/ceilometer-jobs.yaml @@ -4,6 +4,9 @@ provides: openstack-operator:image:ceilometer vars: &id001 docker_images: + - context: images/ceilometer + repository: vexxhost/ceilometer + target: ceilometer - context: images/ceilometer repository: vexxhost/ceilometer-agent-notification target: ceilometer-agent-notification diff --git a/zuul.d/functional-jobs.yaml b/zuul.d/functional-jobs.yaml index abf11f0b..3264040c 100644 --- a/zuul.d/functional-jobs.yaml +++ b/zuul.d/functional-jobs.yaml @@ -20,41 +20,45 @@ jobs: - openstack-operator:functional: dependencies: - - name: openstack-operator:images:build:ceilometer - soft: true - - name: openstack-operator:images:build:rabbitmq - soft: true - - name: openstack-operator:images:build:keystone + - name: openstack-operator:images:build:mcrouter-exporter soft: true - name: openstack-operator:images:build:horizon soft: true + - name: openstack-operator:images:build:rabbitmq + soft: true + - name: openstack-operator:images:build:ceilometer + soft: true + - name: openstack-operator:images:build:memcached-exporter + soft: true - name: openstack-operator:images:build:memcached soft: true + - name: openstack-operator:images:build:keystone + soft: true - name: openstack-operator:images:build:mcrouter soft: true - openstack-operator:images:build:openstack-operator - - name: openstack-operator:images:build:mcrouter-exporter - soft: true - - name: openstack-operator:images:build:memcached-exporter + - name: openstack-operator:images:build:heat soft: true gate: jobs: - openstack-operator:functional: dependencies: - - name: openstack-operator:images:upload:ceilometer - soft: true - - name: openstack-operator:images:upload:rabbitmq - soft: true - - name: openstack-operator:images:upload:keystone + - name: openstack-operator:images:upload:mcrouter-exporter soft: true - name: openstack-operator:images:upload:horizon soft: true + - name: openstack-operator:images:upload:rabbitmq + soft: true + - name: openstack-operator:images:upload:ceilometer + soft: true + - name: openstack-operator:images:upload:memcached-exporter + soft: true - name: openstack-operator:images:upload:memcached soft: true + - name: openstack-operator:images:upload:keystone + soft: true - name: openstack-operator:images:upload:mcrouter soft: true - openstack-operator:images:upload:openstack-operator - - name: openstack-operator:images:upload:mcrouter-exporter - soft: true - - name: openstack-operator:images:upload:memcached-exporter + - name: openstack-operator:images:upload:heat soft: true diff --git a/zuul.d/heat-jobs.yaml b/zuul.d/heat-jobs.yaml new file mode 100644 index 00000000..426ac815 --- /dev/null +++ b/zuul.d/heat-jobs.yaml @@ -0,0 +1,45 @@ +- job: + name: openstack-operator:images:build:heat + parent: vexxhost-build-docker-image + provides: openstack-operator:image:heat + vars: &id001 + docker_images: + - context: images/heat + repository: vexxhost/heat-api-base + target: heat-api-base + - context: images/heat + repository: vexxhost/heat-api + target: heat-api + - context: images/heat + repository: vexxhost/heat-api-cfn + target: heat-api-cfn + - context: images/heat + repository: vexxhost/heat-engine + target: heat-engine + dependencies: + - openstack-operator:images:build:openstack-operator + files: &id002 + - ^images/heat/.* +- job: + name: openstack-operator:images:upload:heat + parent: vexxhost-upload-docker-image + provides: openstack-operator:image:heat + vars: *id001 + dependencies: + - openstack-operator:images:upload:openstack-operator + files: *id002 +- job: + name: openstack-operator:images:promote:heat + parent: vexxhost-promote-docker-image + vars: *id001 + files: *id002 +- project: + check: + jobs: + - openstack-operator:images:build:heat + gate: + jobs: + - openstack-operator:images:upload:heat + promote: + jobs: + - openstack-operator:images:promote:heat