Closed sed-i closed 2 years ago
Merged, thanks. I think you should have rights to publish this to Charmhub @sed-i?
So needing to add a patch
to the unittests here was an early indication that this change is going to break people's CI:
lightkube.core.exceptions.ConfigError: [Errno 2] No such file or directory: '/var/run/secrets/kubernetes.io/serviceaccount/token'
lightkube.core.exceptions.ConfigError: Configuration file ~/.kube/config not found
Revert and create v2? (Haven't published to charmhub yet.)
Oh interesting. Yeh, I'm away from my computer for a bit, but if it's breaking things then definitely revert - where did you catch it?
I'm interested because in most places I've seen this, the whole class is mocked out for tests?
where did you catch it
Prometheus unit tests. Although perhaps because I moved too quickly from v0 to v1. Checking.
Prometheus unit tests mock methods, not the entire class, so reverting is best. Created #14 for this.
So needing to add a
patch
to the unittests here was an early indication that this change is going to break people's CI:lightkube.core.exceptions.ConfigError: [Errno 2] No such file or directory: '/var/run/secrets/kubernetes.io/serviceaccount/token' lightkube.core.exceptions.ConfigError: Configuration file ~/.kube/config not found
Revert and create v2? (Haven't published to charmhub yet.)
Does this actually break "real" code where k8s/microk8s is deployed, or just unit tests?
Since lightkube
itself wasn't updated, the "right" way may be catching the exception. It's happening now because Client
isn't actually instantiated until patch|is_patched
, but:
from lightkube.core import exceptions
...
class KubernetesServicePatch(Object):
def _patch(self, ...):
try:
_client = Client()
except exceptions.ConfigError:
logger.warning(...)
return
if self.is_patched(client):
...
Issue
The k8s patching had a leader guard inside on-install, which always happens before leader-elected. It's possible that juju already elected a leader by the time
install
fires, but it is technically incorrect to assume so. A unit does not need to be a leader to patch k8s.Solution
Use
is_patched
guard instead of leader guard.Context
This is only a partial solution so far, because we still get these kind of errors:
Testing Instructions
Deploy e.g. prometheus with this version of the lib.
Release Notes
Replace leader guard with is_patched guard in k8s patching.