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

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

Open
mvlassis opened this issue Sep 20, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@mvlassis
Copy link
Contributor

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.

@mvlassis mvlassis added the bug Something isn't working label Sep 20, 2024
Copy link

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/KF-6282.

This message was autogenerated

@mvlassis
Copy link
Contributor Author

After discussing about this with the team:

  • We consider this a bug, and the charm should ideally stay in a Blocked state until the CRD is applied.
  • A simple fix would be to add an if statement checking for the CRD, and stay in a Blocked state if it isn't present.
  • As a better solution, we have decided adding a relation between resource-dispatcher and admission-webhook to track whether the CRD is applied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant