canonical / cos-configuration-k8s-operator

https://charmhub.io/cos-configuration-k8s
Apache License 2.0
4 stars 7 forks source link

fix: error on stop #109

Open lucabello opened 2 months ago

lucabello commented 2 months ago

Issue

When removing cos-config via juju remove-application, the charm goes into error state and is not removed.

The error is the following:

...
  File "./src/charm.py", line 483, in tracing_endpoint
    if self._tracing.is_ready():
AttributeError: 'COSConfigCharm' object has no attribute '_tracing'

This happens because the charm __init__ returns early on removal if the storage is detached (code):

... # in __init__
if len(self.model.storages["content-from-git"]) == 0:
    # Storage isn't available yet. Since storage becomes available early enough, no need
    # to observe storage-attached and complicate things; simply abort until it is ready.
    return
...

Then, the call to self._tracing.is_ready() which happens here (and is called by the @trace_charm decorator) fails because self._tracing is not defined.

Solution

Move the self._tracing definition above the early constructor return.

Testing Instructions

  1. charmcraft pack (from the PR)
  2. juju deploy ./the.charm cos-config
  3. juju remove-application --destroy-storage cos-config
  4. Verify the application is removed correctly and doesn't error on stop