Use server-side apply

Change-Id: I87913a4080bf14b000c7619428bc0ebdcb80531b
This commit is contained in:
Mohammed Naser 2020-05-27 22:00:06 -04:00
parent 16725c38c1
commit e65d3c5c70
16 changed files with 31 additions and 36 deletions

View File

@ -68,7 +68,7 @@ def create_or_rotate_fernet_repository(name):
# Update secret
utils.create_or_update('keystone/secret-fernet.yml.j2', name=name,
keys=keys, is_strategic=False, adopt=True)
keys=keys, adopt=True)
@kopf.timer('apps', 'v1', 'deployments',

View File

@ -52,6 +52,7 @@ spec:
{% if 'api' in component %}
ports:
- name: heat-{{ component }}
protocol: TCP
containerPort: {% if component == 'api' %}8004{% else %}8000{% endif%}
livenessProbe:
tcpSocket:

View File

@ -19,9 +19,9 @@ metadata:
name: heat-{{ component }}
namespace: openstack
spec:
serviceType: ClusterIP
ports:
- name: heat-{{ component }}
protocol: TCP
port: 80
targetPort: heat-{{ component }}
selector:

View File

@ -48,6 +48,7 @@ spec:
name: horizon
ports:
- name: horizon
protocol: TCP
containerPort: 8000
livenessProbe:
tcpSocket:

View File

@ -19,7 +19,6 @@ metadata:
name: horizon
namespace: openstack
spec:
type: ClusterIP
ports:
- name: horizon
port: 80

View File

@ -43,6 +43,7 @@ spec:
{% endfor %}
ports:
- name: keystone
protocol: TCP
containerPort: 5000
livenessProbe:
httpGet:

View File

@ -19,7 +19,4 @@ metadata:
name: keystone-{{ name }}
namespace: openstack
data:
{% if keys | length > 2 %}
$patch: replace
{% endif %}
{{ keys | to_yaml | indent(2) }}

View File

@ -19,7 +19,6 @@ metadata:
name: keystone
namespace: openstack
spec:
type: ClusterIP
ports:
- name: keystone
port: 80

View File

@ -36,6 +36,7 @@ spec:
imagePullPolicy: Always
ports:
- name: mcrouter
protocol: TCP
containerPort: 11211
livenessProbe:
tcpSocket:
@ -64,6 +65,7 @@ spec:
imagePullPolicy: Always
ports:
- name: metrics
protocol: TCP
containerPort: 9442
livenessProbe:
httpGet:

View File

@ -18,7 +18,6 @@ kind: Service
metadata:
name: mcrouter-{{ name }}
spec:
serviceType: ClusterIP
ports:
- name: mcrouter
port: 11211

View File

@ -36,6 +36,7 @@ spec:
imagePullPolicy: Always
ports:
- name: memcached
protocol: TCP
containerPort: 11211
livenessProbe:
tcpSocket:
@ -59,6 +60,7 @@ spec:
imagePullPolicy: Always
ports:
- name: metrics
protocol: TCP
containerPort: 9150
livenessProbe:
httpGet:

View File

@ -21,6 +21,7 @@ spec:
clusterIP: None
ports:
- name: memcached
protocol: TCP
port: 11211
targetPort: memcached
selector:

View File

@ -37,6 +37,7 @@ spec:
imagePullPolicy: Always
ports:
- name: memcached
protocol: TCP
containerPort: 11211
livenessProbe:
tcpSocket:
@ -60,6 +61,7 @@ spec:
imagePullPolicy: Always
ports:
- name: metrics
protocol: TCP
containerPort: 9150
livenessProbe:
httpGet:

View File

@ -46,8 +46,10 @@ spec:
imagePullPolicy: Always
ports:
- name: rabbitmq
protocol: TCP
containerPort: 5672
- name: metrics
protocol: TCP
containerPort: 15692
livenessProbe:
tcpSocket:
@ -82,4 +84,4 @@ spec:
{% if 'tolerations' in spec %}
tolerations:
{{ spec.tolerations | to_yaml | indent(8) }}
{% endif %}
{% endif %}

View File

@ -18,7 +18,6 @@ kind: Service
metadata:
name: rabbitmq-{{ name }}
spec:
serviceType: ClusterIP
ports:
- name: rabbitmq
port: 5672

View File

@ -18,7 +18,6 @@ The module contains a few useful utilities which we refactor out in order
to be able to use them across all different operators.
"""
import base64
import copy
import operator
import json
import os
@ -29,7 +28,6 @@ import jinja2
import kopf
from pbr import version
import pykube
from pykube.utils import obj_merge
import yaml
import openstack
@ -87,7 +85,7 @@ ENV.filters['to_yaml'] = to_yaml
ENV.globals['labels'] = labels
def create_or_update(template, is_strategic=True, **kwargs):
def create_or_update(template, **kwargs):
"""Create or update a Kubernetes resource.
This function is called with a template and the args to pass to that
@ -97,31 +95,23 @@ def create_or_update(template, is_strategic=True, **kwargs):
"""
resource = generate_object(template, **kwargs)
obj = copy.deepcopy(resource.obj)
# Try to get the remote record
try:
resource.reload()
resource.obj = obj
# NOTE(mnaser): Workaround until the following lands
# https://github.com/hjacobs/pykube/pull/68
# pylint: disable=W0212
patch = obj_merge(resource.obj, resource._original_obj, is_strategic)
resp = resource.api.patch(
**resource.api_kwargs(
headers={
"Content-Type": "application/strategic-merge-patch+json"
},
data=json.dumps(patch),
)
# NOTE(mnaser): The following relies on server-side apply and requires
# at least Kuberentes v1.16+
resp = resource.api.patch(
**resource.api_kwargs(
headers={
"Content-Type": "application/apply-patch+yaml"
},
params={
'fieldManager': 'openstack-operator',
'force': True,
},
data=to_yaml(resource.obj),
)
resource.api.raise_for_status(resp)
resource.set_obj(resp.json())
except pykube.exceptions.HTTPError as exc:
if exc.code != 404:
raise
resource.create()
)
resource.api.raise_for_status(resp)
resource.set_obj(resp.json())
return resource