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

_update_received_ca_certs method first needs to validate the availability of traefik container #265

Closed
gatici opened this issue Oct 6, 2023 · 1 comment

Comments

@gatici
Copy link
Contributor

gatici commented Oct 6, 2023

Bug Description

During the integration of CertificateTransfer interface:
If CertificateTransferAvailableEvent is emitted too quick before traefik container become available, _update_received_ca_certs method tries to write to an non-existing path which causes "ops.pebble.ConnectionError: [Errno 2] No such file or directory" error.
In , def _update_received_ca_certs method, first we need to check if container is up or not.

To Reproduce

juju deploy vault-k8s --channel edge -n 5 --trust
juju deploy traefik-k8s --channel edge --trust
juju integrate vault-k8s:send-ca-cert traefik-k8s:receive-ca-cert

Environment

juju: 3.1.5
microk8s: v1.27.5
lxd:5.0.2-838e1b2
certificate_transfer interface: 0.4

Relevant log output

unit-traefik-0: 2023-10-06 12:03:21 DEBUG jujuc running hook tool "state-get" for traefik/0-receive-ca-cert-relation-changed-577932895375089497
unit-traefik-0: 2023-10-06 12:03:21 DEBUG jujuc running hook tool "juju-log" for traefik/0-receive-ca-cert-relation-changed-577932895375089497
unit-traefik-0: 2023-10-06 12:03:21 DEBUG unit.traefik/0.juju-log receive-ca-cert:4: Emitting custom event <CertificateAvailableEvent via TraefikIngressCharm/CertificateTransferRequires[receive-ca-cert]/on/certificate_available[42]>.
unit-traefik-0: 2023-10-06 12:03:21 DEBUG jujuc running hook tool "juju-log" for traefik/0-receive-ca-cert-relation-changed-577932895375089497
unit-traefik-0: 2023-10-06 12:03:21 ERROR unit.traefik/0.juju-log receive-ca-cert:4: Uncaught exception while in charm code:
Traceback (most recent call last):
  File "/usr/lib/python3.8/urllib/request.py", line 1354, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/usr/lib/python3.8/http/client.py", line 1256, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1302, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1251, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1011, in _send_output
    self.send(msg)
  File "/usr/lib/python3.8/http/client.py", line 951, in send
    self.connect()
  File "/var/lib/juju/agents/unit-traefik-0/charm/venv/ops/pebble.py", line 272, in connect
    self.sock.connect(self.socket_path)
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/lib/juju/agents/unit-traefik-0/charm/venv/ops/pebble.py", line 1599, in _request_raw
    response = self.opener.open(request, timeout=self.timeout)
  File "/usr/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/var/lib/juju/agents/unit-traefik-0/charm/venv/ops/pebble.py", line 286, in http_open
    return self.do_open(_UnixSocketConnection, req,  # type:ignore
  File "/usr/lib/python3.8/urllib/request.py", line 1357, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 2] No such file or directory>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./src/charm.py", line 1343, in <module>
    main(TraefikIngressCharm, use_juju_for_storage=True)
  File "/var/lib/juju/agents/unit-traefik-0/charm/venv/ops/main.py", line 441, in main
    _emit_charm_event(charm, dispatcher.event_name)
  File "/var/lib/juju/agents/unit-traefik-0/charm/venv/ops/main.py", line 149, in _emit_charm_event
    event_to_emit.emit(*args, **kwargs)
  File "/var/lib/juju/agents/unit-traefik-0/charm/venv/ops/framework.py", line 342, in emit
    framework._emit(event)
  File "/var/lib/juju/agents/unit-traefik-0/charm/venv/ops/framework.py", line 839, in _emit
    self._reemit(event_path)
  File "/var/lib/juju/agents/unit-traefik-0/charm/venv/ops/framework.py", line 928, in _reemit
    custom_handler(event)
  File "/var/lib/juju/agents/unit-traefik-0/charm/lib/charms/certificate_transfer_interface/v0/certificate_transfer.py", line 374, in _on_relation_changed
    self.on.certificate_available.emit(
  File "/var/lib/juju/agents/unit-traefik-0/charm/venv/ops/framework.py", line 342, in emit
    framework._emit(event)
  File "/var/lib/juju/agents/unit-traefik-0/charm/venv/ops/framework.py", line 839, in _emit
    self._reemit(event_path)
  File "/var/lib/juju/agents/unit-traefik-0/charm/venv/ops/framework.py", line 928, in _reemit
    custom_handler(event)
  File "/var/lib/juju/agents/unit-traefik-0/charm/lib/charms/tempo_k8s/v0/charm_tracing.py", line 455, in wrapped_function
    return callable(*args, **kwargs)  # type: ignore
  File "./src/charm.py", line 271, in _on_recv_ca_cert_available
    self._update_received_ca_certs(event)
  File "/var/lib/juju/agents/unit-traefik-0/charm/lib/charms/tempo_k8s/v0/charm_tracing.py", line 455, in wrapped_function
    return callable(*args, **kwargs)  # type: ignore
  File "./src/charm.py", line 282, in _update_received_ca_certs
    self.container.push(
  File "/var/lib/juju/agents/unit-traefik-0/charm/venv/ops/model.py", line 2188, in push
    self._pebble.push(str(path), source, encoding=encoding,
  File "/var/lib/juju/agents/unit-traefik-0/charm/venv/ops/pebble.py", line 2014, in push
    response = self._request_raw('POST', '/v1/files', None, headers, data)
  File "/var/lib/juju/agents/unit-traefik-0/charm/venv/ops/pebble.py", line 1612, in _request_raw
    raise ConnectionError(e.reason)
ops.pebble.ConnectionError: [Errno 2] No such file or directory
unit-traefik-0: 2023-10-06 12:03:21 ERROR juju.worker.uniter.operation hook "receive-ca-cert-relation-changed" (via hook dispatching script: dispatch) failed: exit status 1

Additional context

No response

@lucabello
Copy link
Contributor

I believe this is solved by your own PR #267, so I'm closing the issue :)

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

No branches or pull requests

2 participants