Skip to content

Charms enters Error state when deployed on its own: lightkube.core.exceptions.LoadResourceError: No module named 'lightkube.resources.metacontroller_v1alpha1' #66

Description

@mvlassis

Bug Description

The resource -dispatcher charm enters an Error state when deployed on its own, with this error message from the debug logs:

lightkube.core.exceptions.LoadResourceError: No module named 'lightkube.resources.metacontroller_v1alpha1'. If using a CRD, ensure you define a generic resource.

The issue seems to be that some CRDs are missing that are usually applied with the metacontroller-operator charm.

To Reproduce

  • Get a fresh microk8s installation
  • Deploy the resource-dispatcher charm with juju deploy resource-dispatcher --trust
  • The charm should enter an Error state after some time

Environment

Charm channel: latest/stable
Juju: 3.4.5
Microk8s: 1.29

Relevant Log Output

unit-resource-dispatcher-0: 12:58:51 ERROR unit.resource-dispatcher/0.juju-log Uncaught exception while in charm code:
Traceback (most recent call last):
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/lightkube/codecs.py", line 37, in _load_model
    module = importlib.import_module(f'lightkube.resources.{version.lower()}')
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'lightkube.resources.metacontroller_v1alpha1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./src/charm.py", line 296, in <module>
    main(ResourceDispatcherOperator)
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/ops/main.py", line 441, in main
    _emit_charm_event(charm, dispatcher.event_name)
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/ops/main.py", line 149, in _emit_charm_event
    event_to_emit.emit(*args, **kwargs)
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/ops/framework.py", line 344, in emit
    framework._emit(event)
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/ops/framework.py", line 841, in _emit
    self._reemit(event_path)
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/ops/framework.py", line 930, in _reemit
    custom_handler(event)
  File "./src/charm.py", line 141, in _on_install
    self._deploy_k8s_resources()
  File "./src/charm.py", line 131, in _deploy_k8s_resources
    self.k8s_resource_handler.apply()
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/charmed_kubeflow_chisme/kubernetes/_kubernetes_resource_handler.py", line 324, in apply
    resources = self.render_manifests(force_recompute=False)
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/charmed_kubeflow_chisme/kubernetes/_kubernetes_resource_handler.py", line 272, in render_manifests
    self._manifests = codecs.load_all_yaml(
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/lightkube/codecs.py", line 105, in load_all_yaml
    return _flatten(yaml.safe_load_all(stream))
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/lightkube/codecs.py", line 98, in _flatten
    res = from_dict(obj)
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/lightkube/codecs.py", line 61, in from_dict
    model = _load_model(d['apiVersion'], d['kind'])
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/lightkube/codecs.py", line 40, in _load_model
    raise LoadResourceError(f"{e}. If using a CRD, ensure you define a generic resource.")
lightkube.core.exceptions.LoadResourceError: No module named 'lightkube.resources.metacontroller_v1alpha1'. If using a CRD, ensure you define a generic resource.
unit-resource-dispatcher-0: 12:58:51 ERROR juju.worker.uniter.operation hook "install" (via hook dispatching script: dispatch) failed: exit status 1

Additional Context

We should probably handle the CRD missing and put the charm into a Blocked state.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions