You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.
To work properly with different Kubernetes client libraries, such as PyKube/PyKubeNG (#15), the authentication is needed.
One way to do this is on the module import level. Yet, this is wrong from the code structuring point of view.
It would be better to have the explicit event handler for the operator-wide (not just object-wide) events:
importkopfimportkubernetesimportpykubeconfig=None@kopf.on.startup()defauth_pykube(**_):
globalconfigtry:
config=pykube.KubeConfig.from_service_account() # cluster env varsexceptFileNotFoundError:
config=pykube.KubeConfig.from_file() # developer's config files@kopf.on.startup()defauth_client(logger, **_):
try:
kubernetes.config.load_incluster_config() # cluster env varslogger.debug("configured in cluster with service account")
exceptkubernetes.config.ConfigExceptionase1:
try:
kubernetes.config.load_kube_config() # developer's config fileslogger.debug("configured via kubeconfig file")
exceptkubernetes.config.ConfigExceptionase2:
raiseException(f"Cannot authenticate neither in-cluster, nor via kubeconfig.")
@kopf.on.cleanup()defpurge_caches(**_):
pass
It could be also used to start some background threads or async coroutines for monitoring the unrelated systems (e.g. API polling).
The handler should be called before any implicit login() or other API calls, so that nothing is implicitly configured by the framework. But after the logging is configured and registry is populated — so that the handler itself is logged, but it could adjust the logging, or the registry.
For the exit-handlers, perhaps the atexit stdlib can be used.
The text was updated successfully, but these errors were encountered:
To work properly with different Kubernetes client libraries, such as PyKube/PyKubeNG (#15), the authentication is needed.
One way to do this is on the module import level. Yet, this is wrong from the code structuring point of view.
It would be better to have the explicit event handler for the operator-wide (not just object-wide) events:
It could be also used to start some background threads or async coroutines for monitoring the unrelated systems (e.g. API polling).
The handler should be called before any implicit
login()
or other API calls, so that nothing is implicitly configured by the framework. But after the logging is configured and registry is populated — so that the handler itself is logged, but it could adjust the logging, or the registry.For the exit-handlers, perhaps the
atexit
stdlib can be used.The text was updated successfully, but these errors were encountered: