def __init__(self, framework): super().__init__(framework) if not self.model.unit.is_leader(): logger.info("Not a leader, skipping any work") self.model.unit.status = ActiveStatus() return try: self.interfaces = get_interfaces(self) except NoVersionsListed as err: self.model.unit.status = WaitingStatus(str(err)) return except NoCompatibleVersions as err: self.model.unit.status = BlockedStatus(str(err)) return else: self.model.unit.status = ActiveStatus() self.image = OCIImageResource(self, "oci-image") self.framework.observe(self.on.install, self.set_pod_spec) self.framework.observe(self.on.upgrade_charm, self.set_pod_spec) self.framework.observe( self.on["ingress"].relation_changed, self.configure_ingress, )
def __init__(self, *args): super().__init__(*args) self.log = logging.getLogger() if not self.model.unit.is_leader(): self.log.info("Not a leader, skipping set_pod_spec") self.model.unit.status = ActiveStatus() return self.image = OCIImageResource(self, "oci-image") try: self.interfaces = get_interfaces(self) except NoVersionsListed as err: self.model.unit.status = WaitingStatus(str(err)) return except NoCompatibleVersions as err: self.model.unit.status = BlockedStatus(str(err)) return else: self.model.unit.status = ActiveStatus() self.framework.observe(self.on.install, self.set_pod_spec) self.framework.observe(self.on.upgrade_charm, self.set_pod_spec) self.framework.observe(self.on.config_changed, self.set_pod_spec) self.framework.observe(self.on["mysql"].relation_changed, self.set_pod_spec) self.framework.observe(self.on["grpc"].relation_changed, self.send_info)
def __init__(self, *args): super().__init__(*args) if not self.unit.is_leader(): # We can't do anything useful when not the leader, so do nothing. self.model.unit.status = WaitingStatus("Waiting for leadership") return try: self.interfaces = get_interfaces(self) except NoVersionsListed as err: self.model.unit.status = WaitingStatus(str(err)) return except NoCompatibleVersions as err: self.model.unit.status = BlockedStatus(str(err)) return else: self.model.unit.status = ActiveStatus() self.log = logging.getLogger(__name__) # Every lightkube API call will use the model name as the namespace by default self.lightkube_client = Client(namespace=self.model.name, field_manager="lightkube") self.framework.observe(self.on.start, self.start) self.framework.observe(self.on["istio-pilot"].relation_changed, self.start) self.framework.observe(self.on.config_changed, self.start) self.framework.observe(self.on.remove, self.remove)
def __init__(self, *args): super().__init__(*args) if not self.unit.is_leader(): # We can't do anything useful when not the leader, so do nothing. self.model.unit.status = WaitingStatus("Waiting for leadership") return self.log = logging.getLogger(__name__) self.image = OCIImageResource(self, "oci-image") try: self.interfaces = get_interfaces(self) except NoVersionsListed as err: self.model.unit.status = WaitingStatus(str(err)) return except NoCompatibleVersions as err: self.model.unit.status = BlockedStatus(str(err)) return else: self.model.unit.status = ActiveStatus() for event in [ self.on.install, self.on.upgrade_charm, self.on.config_changed, ]: self.framework.observe(event, self.main) self.framework.observe(self.on["ingress"].relation_changed, self.configure_mesh)
def _get_interfaces(self): try: interfaces = get_interfaces(self) except NoVersionsListed as err: raise CheckFailed(err, WaitingStatus) except NoCompatibleVersions as err: raise CheckFailed(err, BlockedStatus) return interfaces
def _get_interfaces(self): # Remove this abstraction when SDI adds .status attribute to NoVersionsListed, # NoCompatibleVersionsListed: # https://github.com/canonical/serialized-data-interface/issues/26 try: interfaces = get_interfaces(self) except NoVersionsListed as err: raise CheckFailedError(str(err), WaitingStatus) except NoCompatibleVersions as err: raise CheckFailedError(str(err), BlockedStatus) return interfaces
def __init__(self, *args): super().__init__(*args) if not self.unit.is_leader(): # We can't do anything useful when not the leader, so do nothing. self.model.unit.status = WaitingStatus("Waiting for leadership") return try: self.interfaces = get_interfaces(self) except NoVersionsListed as err: self.model.unit.status = WaitingStatus(str(err)) return except NoCompatibleVersions as err: self.model.unit.status = BlockedStatus(str(err)) return else: self.model.unit.status = ActiveStatus() self.log = logging.getLogger(__name__) self.env = Environment(loader=FileSystemLoader('src')) self._resource_handler = ResourceHandler(self.app.name, self.model.name) self.lightkube_client = Client(namespace=self.model.name, field_manager="lightkube") self._resource_files = [ "gateway.yaml.j2", "auth_filter.yaml.j2", "virtual_service.yaml.j2", ] self.framework.observe(self.on.install, self.install) self.framework.observe(self.on.remove, self.remove) self.framework.observe(self.on.config_changed, self.handle_default_gateway) self.framework.observe(self.on["istio-pilot"].relation_changed, self.send_info) self.framework.observe(self.on['ingress'].relation_changed, self.handle_ingress) self.framework.observe(self.on['ingress'].relation_broken, self.handle_ingress) self.framework.observe(self.on['ingress'].relation_departed, self.handle_ingress) self.framework.observe(self.on['ingress-auth'].relation_changed, self.handle_ingress_auth) self.framework.observe(self.on['ingress-auth'].relation_departed, self.handle_ingress_auth)