Speed-up Memcached deployment

Change-Id: Id1d9c99fbd1ca43a4719c62553bcfbbe26ac5ac8
This commit is contained in:
Mohammed Naser 2020-08-08 14:59:08 -04:00
parent ae58ef7084
commit dfe5f77ee5
16 changed files with 63 additions and 159 deletions

2
.pylintrc Normal file
View File

@ -0,0 +1,2 @@
[SIMILARITIES]
ignore-imports=yes

View File

@ -250,10 +250,6 @@ function start_heat {
proxy_pass_to_kubernetes /heat-api heat-api heat-wsgi-api proxy_pass_to_kubernetes /heat-api heat-api heat-wsgi-api
proxy_pass_to_kubernetes /heat-api-cfn heat-api-cfn heat-wsgi-api-cfn proxy_pass_to_kubernetes /heat-api-cfn heat-api-cfn heat-wsgi-api-cfn
# (re)start memcached to make sure we have a clean memcache.
kubectl rollout restart statefulset/memcached-heat
sleep 10
} }
# stop_heat() - Stop running processes # stop_heat() - Stop running processes

View File

@ -42,8 +42,7 @@ function install_horizon {
# start_horizon() - Start running processes # start_horizon() - Start running processes
function start_horizon { function start_horizon {
kubectl rollout restart statefulset/memcached-horizon echo noop
sleep 10
} }
# stop_horizon() - Stop running processes # stop_horizon() - Stop running processes

View File

@ -59,10 +59,6 @@ function start_keystone {
if ! wait_for_service $SERVICE_TIMEOUT $service_uri; then if ! wait_for_service $SERVICE_TIMEOUT $service_uri; then
die $LINENO "keystone did not start" die $LINENO "keystone did not start"
fi fi
# (re)start memcached to make sure we have a clean memcache.
kubectl rollout restart statefulset/memcached-keystone
sleep 10
} }
export -f start_keystone export -f start_keystone

View File

@ -23,6 +23,8 @@ from openstack_operator import database
from openstack_operator import identity from openstack_operator import identity
from openstack_operator import utils from openstack_operator import utils
MEMCACHED = True
def create_or_resume(name, spec, **_): def create_or_resume(name, spec, **_):
"""Create and re-sync a glance instance """Create and re-sync a glance instance
@ -37,9 +39,6 @@ def create_or_resume(name, spec, **_):
else: else:
database.ensure_mysql_cluster("glance", spec["mysql"]) database.ensure_mysql_cluster("glance", spec["mysql"])
# deploy memcached
utils.create_or_update('glance/memcached.yml.j2', spec=spec)
# deploy glance api # deploy glance api
utils.create_or_update('glance/daemonset.yml.j2', utils.create_or_update('glance/daemonset.yml.j2',
name=name, spec=spec) name=name, spec=spec)

View File

@ -24,6 +24,8 @@ from openstack_operator import database
from openstack_operator import identity from openstack_operator import identity
from openstack_operator import utils from openstack_operator import utils
MEMCACHED = True
def create_or_resume(name, spec, **_): def create_or_resume(name, spec, **_):
"""Create and re-sync any Heat instances """Create and re-sync any Heat instances
@ -34,9 +36,6 @@ def create_or_resume(name, spec, **_):
else: else:
database.ensure_mysql_cluster("heat", spec["mysql"]) database.ensure_mysql_cluster("heat", spec["mysql"])
# deploy memcached
utils.create_or_update('heat/memcached.yml.j2', spec=spec)
# deploy rabbitmq # deploy rabbitmq
if not utils.ensure_secret("openstack", "heat-rabbitmq"): if not utils.ensure_secret("openstack", "heat-rabbitmq"):
utils.create_or_update('heat/secret-rabbitmq.yml.j2', utils.create_or_update('heat/secret-rabbitmq.yml.j2',

View File

@ -21,6 +21,8 @@ the appropriate deployments, Mcrouter, pod monitors and Prometheus rules.
from openstack_operator import utils from openstack_operator import utils
MEMCACHED = True
def create_secret(): def create_secret():
"""Create a new horizon secret for secretKey""" """Create a new horizon secret for secretKey"""
@ -49,8 +51,6 @@ def create_or_resume(name, spec, **_):
spec=spec) spec=spec)
utils.create_or_update('horizon/service.yml.j2', utils.create_or_update('horizon/service.yml.j2',
name=name, spec=spec) name=name, spec=spec)
utils.create_or_update('horizon/memcached.yml.j2',
name=name, spec=spec)
if "ingress" in spec: if "ingress" in spec:
utils.create_or_update('horizon/ingress.yml.j2', utils.create_or_update('horizon/ingress.yml.j2',
name=name, spec=spec) name=name, spec=spec)

View File

@ -27,6 +27,8 @@ from openstack_operator import database
from openstack_operator import filters from openstack_operator import filters
from openstack_operator import utils from openstack_operator import utils
MEMCACHED = True
TOKEN_EXPIRATION = 86400 TOKEN_EXPIRATION = 86400
FERNET_ROTATION_INTERVAL = 3600 FERNET_ROTATION_INTERVAL = 3600
ACTIVE_KEYS = int(TOKEN_EXPIRATION / FERNET_ROTATION_INTERVAL) ACTIVE_KEYS = int(TOKEN_EXPIRATION / FERNET_ROTATION_INTERVAL)
@ -113,7 +115,6 @@ def create_or_resume(name, spec, **_):
db_config = database.ensure_mysql_cluster("keystone", spec["mysql"]) db_config = database.ensure_mysql_cluster("keystone", spec["mysql"])
# deploy memcached # deploy memcached
utils.create_or_update('keystone/memcached.yml.j2', spec=spec)
# keystone config # keystone config
utils.create_or_update('keystone/secret-config.yml.j2', utils.create_or_update('keystone/secret-config.yml.j2',

View File

@ -23,6 +23,8 @@ from openstack_operator import database
from openstack_operator import identity from openstack_operator import identity
from openstack_operator import utils from openstack_operator import utils
MEMCACHED = True
def create_or_resume(name, spec, **_): def create_or_resume(name, spec, **_):
"""Create and re-sync any Magnum instances """Create and re-sync any Magnum instances
@ -35,9 +37,6 @@ def create_or_resume(name, spec, **_):
spec["mysql"] = {} spec["mysql"] = {}
database.ensure_mysql_cluster("magnum", spec["mysql"]) database.ensure_mysql_cluster("magnum", spec["mysql"])
# deploy memcached
utils.create_or_update('magnum/memcached.yml.j2', spec=spec)
# deploy rabbitmq # deploy rabbitmq
if not utils.ensure_secret("openstack", "magnum-rabbitmq"): if not utils.ensure_secret("openstack", "magnum-rabbitmq"):
utils.create_or_update('magnum/secret-rabbitmq.yml.j2', utils.create_or_update('magnum/secret-rabbitmq.yml.j2',

View File

@ -19,6 +19,7 @@ the appropriate deployments, an instance of Keystone, Heat and Horizon
for the installation. for the installation.
""" """
import functools
import os import os
import pkg_resources import pkg_resources
@ -51,7 +52,42 @@ def operator_configmap(namespace, name, **_):
"""Filter on the operator's ConfigMap.""" """Filter on the operator's ConfigMap."""
return namespace == os.getenv('OPERATOR_NAMESPACE', 'default') \ return namespace == os.getenv('OPERATOR_NAMESPACE', 'default') \
and name == OPERATOR_CONFIGMAP and name == "operator-config"
async def deploy_memcached(item, **_):
"""
Deploy a generic instance of Memcached
This function deploys a generic instance of Memcached with sane defaults,
it's meant to be here to be consumed/called by the function below.
"""
utils.create_or_update('operator/memcached.yml.j2', name=item, adopt=True)
@kopf.on.resume('', 'v1', 'configmaps', when=operator_configmap)
@kopf.on.create('', 'v1', 'configmaps', when=operator_configmap)
@kopf.on.update('', 'v1', 'configmaps', when=operator_configmap)
async def deploy_memcacheds(body, **_):
"""
Deploy multiple Memcached instances for OpenStack services
This function makes sure that Memcached is deployed for all services which
use it when when the operator sees any changes to the configuration.
"""
fns = {}
services = utils.to_dict(body['data']['operator-config.yaml']).keys()
for entry_point in pkg_resources.iter_entry_points('operators'):
if entry_point.name not in services:
continue
module = entry_point.load()
if hasattr(module, 'MEMCACHED') and module.MEMCACHED:
fns[entry_point.name] = \
functools.partial(deploy_memcached, item=entry_point.name)
await kopf.execute(fns=fns)
@kopf.on.resume('', 'v1', 'configmaps', when=operator_configmap) @kopf.on.resume('', 'v1', 'configmaps', when=operator_configmap)

View File

@ -1,32 +0,0 @@
---
# 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: infrastructure.vexxhost.cloud/v1alpha1
kind: Memcached
metadata:
name: glance
namespace: openstack
labels:
{{ labels("glance") | indent(4) }}
spec:
megabytes: 128
{% if 'nodeSelector' in spec %}
nodeSelector:
{{ spec.nodeSelector | to_yaml | indent(4) }}
{% endif %}
{% if 'tolerations' in spec %}
tolerations:
{{ spec.tolerations | to_yaml | indent(4) }}
{% endif %}

View File

@ -1,32 +0,0 @@
---
# 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: infrastructure.vexxhost.cloud/v1alpha1
kind: Memcached
metadata:
name: horizon
namespace: openstack
labels:
{{ labels("horizon", name) | indent(4) }}
spec:
megabytes: 128
{% if 'nodeSelector' in spec %}
nodeSelector:
{{ spec.nodeSelector | to_yaml | indent(4) }}
{% endif %}
{% if 'tolerations' in spec %}
tolerations:
{{ spec.tolerations | to_yaml | indent(4) }}
{% endif %}

View File

@ -1,32 +0,0 @@
---
# 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: infrastructure.vexxhost.cloud/v1alpha1
kind: Memcached
metadata:
name: keystone
namespace: openstack
labels:
{{ labels("keystone") | indent(4) }}
spec:
megabytes: 128
{% if 'nodeSelector' in spec %}
nodeSelector:
{{ spec.nodeSelector | to_yaml | indent(4) }}
{% endif %}
{% if 'tolerations' in spec %}
tolerations:
{{ spec.tolerations | to_yaml | indent(4) }}
{% endif %}

View File

@ -1,32 +0,0 @@
---
# 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: infrastructure.vexxhost.cloud/v1alpha1
kind: Memcached
metadata:
name: magnum
namespace: openstack
labels:
{{ labels("magnum") | indent(4) }}
spec:
megabytes: 128
{% if 'nodeSelector' in spec %}
nodeSelector:
{{ spec.nodeSelector | to_yaml | indent(4) }}
{% endif %}
{% if 'tolerations' in spec %}
tolerations:
{{ spec.tolerations | to_yaml | indent(4) }}
{% endif %}

View File

@ -16,17 +16,14 @@
apiVersion: infrastructure.vexxhost.cloud/v1alpha1 apiVersion: infrastructure.vexxhost.cloud/v1alpha1
kind: Memcached kind: Memcached
metadata: metadata:
name: heat name: {{ name }}
namespace: openstack namespace: openstack
labels: labels:
{{ labels("heat") | indent(4) }} {{ labels(name) | indent(4) }}
spec: spec:
megabytes: 128 megabytes: 128
{% if 'nodeSelector' in spec %}
nodeSelector: nodeSelector:
{{ spec.nodeSelector | to_yaml | indent(4) }} node-role.kubernetes.io/master: ""
{% endif %}
{% if 'tolerations' in spec %}
tolerations: tolerations:
{{ spec.tolerations | to_yaml | indent(4) }} - key: node-role.kubernetes.io/master
{% endif %} effect: NoSchedule

View File

@ -1,6 +1,14 @@
[metadata] [metadata]
name = openstack-operator name = openstack-operator
[entry_points]
operators =
glance = openstack_operator.glance
heat = openstack_operator.heat
horizon = openstack_operator.horizon
keystone = openstack_operator.keystone
magnum = openstack_operator.magnum
[files] [files]
packages = packages =
openstack_operator openstack_operator