From 60ca79a81f0d6f0296d2a7715cffcc50f272391d Mon Sep 17 00:00:00 2001 From: Michael Kelly Date: Wed, 30 Nov 2022 11:13:04 -0800 Subject: [PATCH] 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 --- zuul_operator/certmanager.py | 10 ++++++++++ zuul_operator/operator.py | 10 ++++------ zuul_operator/zuul.py | 14 +------------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/zuul_operator/certmanager.py b/zuul_operator/certmanager.py index 593a9e8..9b06da7 100644 --- a/zuul_operator/certmanager.py +++ b/zuul_operator/certmanager.py @@ -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) diff --git a/zuul_operator/operator.py b/zuul_operator/operator.py index 5aa2402..078d4c8 100644 --- a/zuul_operator/operator.py +++ b/zuul_operator/operator.py @@ -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 diff --git a/zuul_operator/zuul.py b/zuul_operator/zuul.py index ff1597b..5caf8f9 100644 --- a/zuul_operator/zuul.py +++ b/zuul_operator/zuul.py @@ -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):