Commit ed1e5e44 authored by lavado's avatar lavado
Browse files

Merge branch 'squid' into 'master'

Impovements in squid charm

See merge request !12
parents 1dc5a578 d6eb55b0
Loading
Loading
Loading
Loading
+4 −7
Original line number Diff line number Diff line
@@ -10,6 +10,9 @@ tags:
    - misc
series:
    - kubernetes
deployment:
    type: stateful
    service: loadbalancer
storage:
    docker:
        type: filesystem
@@ -17,10 +20,4 @@ storage:
    spool:
        type: filesystem
        location: /var/spool/squid
# -- example relations, delete if unneeded
#requires:
#    db:
#        interface: mysql
#provides:
#    website:
#        interface: http
+0 −24
Original line number Diff line number Diff line
@@ -65,7 +65,6 @@ class SquidK8SCharm(CharmBase):

        if not self.state.installed:
            logging.warning("Config changed called before install complete, deferring event: {}.".format(event.handle))
            self._defer_once(event)

            return

@@ -81,7 +80,6 @@ class SquidK8SCharm(CharmBase):

        if not self.state.configured:
            logging.warning("Start called before configuration complete, deferring event: {}".format(event.handle))
            self._defer_once(event)

            return
        self.unit.status = MaintenanceStatus("Applying pod spec")
@@ -93,28 +91,6 @@ class SquidK8SCharm(CharmBase):
        self.state.started = True
        logging.info("Started")

    def _defer_once(self, event):
        """Defer the given event, but only once."""
        notice_count = 0
        handle = str(event.handle)

        for event_path, _, _ in self.framework._storage.notices(None):
            if event_path.startswith(handle.split('[')[0]):
                notice_count += 1
                logging.debug("Found event: {} x {}".format(event_path, notice_count))

        if notice_count > 1:
            logging.debug("Not deferring {} notice count of {}".format(handle, notice_count))
        else:
            logging.debug("Deferring {} notice count of {}".format(handle, notice_count))
            event.defer()

    def on_addconfig_action(self, event):
        """Handle the example_action action."""
        event.log("Hello from the example action.")
        event.set_results({"success": "true"})


if __name__ == "__main__":
    from ops.main import main
    main(SquidK8SCharm)