Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Make exporter service become juju Object base. #272

Open
jneo8 opened this issue Jun 28, 2024 · 0 comments · May be fixed by #334
Open

[Refactor] Make exporter service become juju Object base. #272

jneo8 opened this issue Jun 28, 2024 · 0 comments · May be fixed by #334

Comments

@jneo8
Copy link
Contributor

jneo8 commented Jun 28, 2024

Currently the logic to control the service is base on the BaseExporter class, which controls the life-cycle of the service. And we control this exporter class life-cycle in the main charm class.

The refactor idea is that we re-create the exporter service class inherit from operator framework's Object class

  • This means every exporter service need to handle their install/config-change/remove hooks.
  • With this change, every time we need to add a new exporter to this charm, we only need to create another exporter service class and register them to the main charm class. Don't have to change the skeleton of main charm class.
  • The exporter service class should handle it's own resource download/attach. The situation right now is the attach resource logic belong to the main charm class. From my point of view, those hardware resource should always belong to one specific exporter, e.g., the storcli belong to hardware-exporter and smartctl exporter binary belong to smartctl-exporter.

sudo refactor code

import ops

class HardwareObserverCharm(ops.CharmBase):

    def __init__(self, args) -> None
      self.hardware_exporter = HardwareExporterService(self)
      self.smart_exporter = SmartExporterService(self)
      ...
      

class HardwareExporterService(ops.Object):
    
    strategies = [StrategyClassA(), StrategyClassB()]
    
    def __init__(self, charm):
        self._charm = charm
        self.framework.observer(self._charm.on.install, self._on_install)
        self.framework.observer(self._charm.on.config_changed, self._on_config_changed)
        
    def _on_install(self, event):
        """Install resources and exporter service."""
        for strategy in self.strategies:
            strategy.install()
        
        # Install exporter service
        ...
        
    def _on_config(self, event):
        """Configure."""
        # Render/Set configurations
        ...


class SmartExporterService(ops.Object):
    
    strategies = [StrategyClassC(), StrategyClassD()]
    
    ...      
@jneo8 jneo8 changed the title [Refactor] Make exporter service be become juju Object base. [Refactor] Make exporter service become juju Object base. Jun 28, 2024
jneo8 added a commit to jneo8/hardware-observer-operator that referenced this issue Oct 8, 2024
- Restructure StrategyABC to have consistence interface
- Remove HWToolHelper and move the logic into service layer
- Change the `install` function return on BaseExporter for blocked
message required
- New ResourceMixin embedded into BaseExporter

partial fix: canonical#272
@jneo8 jneo8 linked a pull request Oct 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant