k8s: Provide an option to disable PXC operator installer
This change introduces an option to disable operator built-in PXC installer because it may not be desirable in some cases. In the process, we move the check+install code into PXC#maybe_install() Because the helm chart provides a way to install and manage the PXC operator as a sub-chart, this change disables the operator's PXC installer in the chart. Change-Id: I48685f29be33ba1c40dea7f4b343bdf7573b62e8
This commit is contained in:
parent
7daf4cb5cb
commit
13792d3f22
|
@ -39,6 +39,11 @@ spec:
|
|||
resources:
|
||||
{{- toYaml .Values.resources | nindent 12 }}
|
||||
{{- end }}
|
||||
{{- if not ( index .Values "pxc-operator" "operatorManaged" ) }}
|
||||
env:
|
||||
- name: ZUUL_INSTALL_PXC
|
||||
value: "0"
|
||||
{{- end }}
|
||||
{{- with .Values.nodeSelector }}
|
||||
nodeSelector:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
|
|
|
@ -69,3 +69,6 @@ cert-manager:
|
|||
|
||||
pxc-operator:
|
||||
enabled: false
|
||||
|
||||
# cert manager should be managed by the operator
|
||||
operatorManaged: false
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
import asyncio
|
||||
import collections
|
||||
import distutils
|
||||
import os
|
||||
|
||||
import kopf
|
||||
import pykube
|
||||
|
@ -56,6 +58,12 @@ def memoize_secrets(memo, logger):
|
|||
|
||||
@kopf.on.startup()
|
||||
def startup(memo, logger, **kwargs):
|
||||
logger.info("Loading operator config")
|
||||
memo.operator_config = {
|
||||
'install_pxc': distutils.util.strtobool(
|
||||
os.environ.get('ZUUL_INSTALL_PXC', '1')),
|
||||
}
|
||||
|
||||
# Operator handlers (like this one) get a single global memo
|
||||
# object; resource handlers (like update) get a memo object for
|
||||
# that specific resource with items shallow-copied from the global
|
||||
|
@ -108,7 +116,8 @@ def create_fn(spec, name, namespace, logger, memo, **kwargs):
|
|||
zuul = Zuul(namespace, name, logger, spec)
|
||||
# Get DB installation started first; it's slow and has no
|
||||
# dependencies.
|
||||
zuul.install_db()
|
||||
zuul.install_db(install_pxc=memo.operator_config['install_pxc'])
|
||||
|
||||
# Install Cert-Manager and request the CA cert before installing
|
||||
# ZK because the CRDs must exist.
|
||||
zuul.install_cert_manager()
|
||||
|
@ -142,7 +151,7 @@ def update_fn(name, namespace, logger, old, new, memo, **kwargs):
|
|||
logger.info("Database changed")
|
||||
conf_changed = True
|
||||
# redo db stuff
|
||||
zuul.install_db()
|
||||
zuul.install_db(install_pxc=memo.operator_config['install_pxc'])
|
||||
zuul.wait_for_db()
|
||||
|
||||
if new.get('zookeeper') != old.get('zookeeper'):
|
||||
|
|
|
@ -47,6 +47,13 @@ class PXC:
|
|||
# the operator seems like the better choice.
|
||||
utils.apply_file(self.api, 'pxc-bundle.yaml', _adopt=False)
|
||||
|
||||
def maybe_install(self):
|
||||
if self.is_installed():
|
||||
return
|
||||
|
||||
self.log.info("Installing PXC operator")
|
||||
self.create_operator()
|
||||
|
||||
def create_cluster(self, small):
|
||||
kw = {'namespace': self.namespace}
|
||||
kw['anti_affinity_key'] = small and 'none' or 'kubernetes.io/hostname'
|
||||
|
|
|
@ -145,7 +145,7 @@ class Zuul:
|
|||
|
||||
# A two-part process for PXC so that this can run while other
|
||||
# installations are happening.
|
||||
def install_db(self):
|
||||
def install_db(self, install_pxc=True):
|
||||
if not self.manage_db:
|
||||
self.log.info("DB is externally managed")
|
||||
return
|
||||
|
@ -154,9 +154,9 @@ class Zuul:
|
|||
|
||||
self.log.info("DB is internally managed")
|
||||
self.pxc = pxc.PXC(self.api, self.namespace, self.log, self.name)
|
||||
if not self.pxc.is_installed():
|
||||
self.log.info("Installing PXC operator")
|
||||
self.pxc.create_operator()
|
||||
|
||||
if install_pxc:
|
||||
self.pxc.maybe_install()
|
||||
|
||||
self.log.info("Creating PXC cluster")
|
||||
self.pxc.create_cluster(small)
|
||||
|
|
Loading…
Reference in New Issue