From 10f9be432a8ae512dc806928d313dbb09e40075c Mon Sep 17 00:00:00 2001 From: okozachenko Date: Wed, 20 May 2020 02:40:38 +0300 Subject: [PATCH] Remove some CRs, and deploy at the startup of the operator 1. Keystone, heat, and horizon CRs are eliminated, and deploy automatically at the beginning. 2. Use a constant namespace "openstack" for the auto-deployed resources. 3. Adjust resource request. Depends-On: https://review.opendev.org/727868/ Change-Id: I75bc8b9e73035f3ca73f00612bc4c50f42473dc3 --- chart/templates/clusterrole.yaml | 36 +-------- chart/templates/configmap.yaml | 12 +++ chart/templates/deployment.yaml | 11 +-- chart/test-values.yaml | 8 ++ chart/values.yaml | 1 + devstack/lib/common | 17 ++++- devstack/lib/keystone | 20 ++--- openstack_operator/horizon.py | 10 ++- openstack_operator/mcrouter.py | 14 ++-- openstack_operator/memcached.py | 12 +-- openstack_operator/objects.py | 2 + openstack_operator/operator.py | 73 +++++++++++++++++++ openstack_operator/rabbitmq.py | 10 +-- .../templates/heat/deployment.yml.j2 | 5 +- .../templates/heat/service.yml.j2 | 3 +- .../templates/horizon/configmap.yml.j2 | 5 +- .../templates/horizon/deployment.yml.j2 | 9 ++- .../horizon/horizontalpodautoscaler.yml.j2 | 7 +- .../templates/horizon/ingress.yml.j2 | 5 +- .../templates/horizon/memcached.yml.j2 | 3 +- .../templates/horizon/secret-secretkey.yml.j2 | 3 +- .../templates/horizon/service.yml.j2 | 3 +- .../templates/keystone/deployment.yml.j2 | 5 +- .../keystone/horizontalpodautoscaler.yml.j2 | 7 +- .../templates/keystone/service.yml.j2 | 3 +- .../templates/operator/namespace.yml.j2 | 24 ++++++ .../templates/rabbitmq/deployment.yml.j2 | 2 +- openstack_operator/tests/unit/base.py | 4 +- openstack_operator/tests/unit/test_heat.py | 1 + openstack_operator/tests/unit/test_horizon.py | 1 + .../tests/unit/test_keystone.py | 28 +++++++ openstack_operator/utils.py | 32 +++++++- playbooks/functional/devstack.yaml | 3 + 33 files changed, 270 insertions(+), 109 deletions(-) create mode 100644 chart/templates/configmap.yaml create mode 100644 openstack_operator/operator.py create mode 100644 openstack_operator/templates/operator/namespace.yml.j2 create mode 100644 openstack_operator/tests/unit/test_keystone.py diff --git a/chart/templates/clusterrole.yaml b/chart/templates/clusterrole.yaml index a61c4329..9093a46c 100644 --- a/chart/templates/clusterrole.yaml +++ b/chart/templates/clusterrole.yaml @@ -23,42 +23,8 @@ rules: - "" resources: - configmaps - - services - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - "" - resources: + - namespaces - pods - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - "" - resources: - - secrets - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - "" - resources: - secrets - services verbs: diff --git a/chart/templates/configmap.yaml b/chart/templates/configmap.yaml new file mode 100644 index 00000000..81afe835 --- /dev/null +++ b/chart/templates/configmap.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: {{ .Release.Namespace }} + name: operator-config + labels: +{{ include "openstack-operator.labels" . | indent 4 }} +data: +{{- with .Values.configMap }} + operator-config.yaml: | +{{ toYaml . | indent 4 }} +{{- end }} diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml index 6aa18065..d2bd2d20 100644 --- a/chart/templates/deployment.yaml +++ b/chart/templates/deployment.yaml @@ -21,6 +21,11 @@ spec: - name: operator image: vexxhost/openstack-operator:latest command: ["/usr/local/bin/kopf"] + env: + - name: OPERATOR_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace {{- with .Values.secretName }} envFrom: - secretRef: @@ -29,11 +34,7 @@ spec: args: - run - -m - - openstack_operator.heat - - -m - - openstack_operator.horizon - - -m - - openstack_operator.keystone + - openstack_operator.operator - -m - openstack_operator.mcrouter - -m diff --git a/chart/test-values.yaml b/chart/test-values.yaml index 6916598d..2e3632b4 100644 --- a/chart/test-values.yaml +++ b/chart/test-values.yaml @@ -1,2 +1,10 @@ --- secretName: devstack +configMap: + horizon: + ingress: + host: "horizon.vexxhost.com" + keystone: + configDir: /etc/keystone + heat: + configDir: /etc/heat \ No newline at end of file diff --git a/chart/values.yaml b/chart/values.yaml index f6a6e7f7..6f04346a 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -1,3 +1,4 @@ crd: monitoring: true dns: true +configMap: {} diff --git a/devstack/lib/common b/devstack/lib/common index 89ab2185..3d695a8d 100644 --- a/devstack/lib/common +++ b/devstack/lib/common @@ -34,16 +34,27 @@ function kubernetes_rollout_status { kubectl rollout status deploy/$deployment } +function kubernetes_rollout_restart { + local deployment="$1" + + for i in {1..30}; do + kubectl get deploy/$deployment && break || sleep 1; + done + + kubectl rollout restart deploy/$deployment +} + function proxy_pass_to_kubernetes { local url=$1 local svc=$2 + local conf=$3 local ip=$(get_kubernetes_service_ip $svc) - local apache_conf=$(apache_site_config_for $svc) + local apache_conf=$(apache_site_config_for $conf) echo "ProxyPass \"${url}\" \"http://${ip}/\"" | sudo tee -a $apache_conf - enable_apache_site $svc + enable_apache_site $conf restart_apache_server } @@ -78,4 +89,4 @@ spec: url: $3 EOF } -export -f _get_or_create_endpoint_with_interface \ No newline at end of file +export -f _get_or_create_endpoint_with_interface diff --git a/devstack/lib/keystone b/devstack/lib/keystone index 5c2a9a29..f4fa2bc6 100644 --- a/devstack/lib/keystone +++ b/devstack/lib/keystone @@ -54,18 +54,9 @@ export -f init_keystone # start_keystone() - Start running processes function start_keystone { - # install keystone - cat <