k8s: Clean up cert-manager installer

The various helper methods are all called in exactly the same way in
both places that they're used. This change consolidates the
installation behind CertManager#maybe_install(), which
create_cert_manager_ca() invokes before trying to create cert.

Change-Id: I37262a22f532962d78b9f1cc0df2b0ee293603f9
This commit is contained in:
Michael Kelly 2022-11-30 11:13:04 -08:00
parent 7b82a3cad8
commit 701cdb1e49
No known key found for this signature in database
GPG Key ID: 77F7FE93040ECF3E
3 changed files with 15 additions and 19 deletions

View File

@ -36,6 +36,16 @@ class CertManager:
return False
return True
def maybe_install(self):
if self.is_installed():
return
self.log.info("Installing Cert-Manager")
self.install()
self.log.info("Waiting for Cert-Manager")
self.wait_for_webhook()
def install(self):
utils.apply_file(self.api, 'cert-manager.yaml', _adopt=False)

View File

@ -118,11 +118,9 @@ def create_fn(spec, name, namespace, logger, memo, **kwargs):
# dependencies.
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()
zuul.wait_for_cert_manager()
# Request the CA cert before installing ZK
zuul.create_cert_manager_ca()
# Now we can install ZK
zuul.install_zk()
# Wait for both to finish
@ -158,12 +156,12 @@ def update_fn(name, namespace, logger, old, new, memo, **kwargs):
logger.info("ZooKeeper changed")
conf_changed = True
# redo zk
zuul.install_cert_manager()
zuul.wait_for_cert_manager()
zuul.create_cert_manager_ca()
# Now we can install ZK
zuul.install_zk()
zuul.wait_for_zk()
if new.get('connections') != old.get('connections'):
logger.info("Connections changed")
conf_changed = True

View File

@ -109,21 +109,9 @@ class Zuul:
self.cert_manager = certmanager.CertManager(
self.api, self.namespace, self.log)
self.installing_cert_manager = False
def install_cert_manager(self):
if self.cert_manager.is_installed():
return
self.installing_cert_manager = True
self.cert_manager.install()
def wait_for_cert_manager(self):
if not self.installing_cert_manager:
return
self.log.info("Waiting for Cert-Manager")
self.cert_manager.wait_for_webhook()
def create_cert_manager_ca(self):
self.cert_manager.maybe_install()
self.cert_manager.create_ca(instance_name=self.name)
def install_zk(self):