global _api_client#262
Conversation
41a6cfa to
46058f5
Compare
AlbertoSoutullo
left a comment
There was a problem hiding this comment.
Hmm I dontt really agree with this approach.
First, there are a lot of places where api_client is still being used, which makes the PR a bit weird to review.
Then, if we want to simplify the usage of api_clientI would not go with global.
Create something like a session:
@dataclass
class KubeSession:
kube_config: str
api_client: client.ApiClient
@classmethod
def from_config(cls, kube_config: str) -> "KubeSession":
config.load_kube_config(config_file=kube_config)
return cls(kube_config=kube_config, api_client=client.ApiClient())
def close(self) -> None:
self.api_client.close()Then you can do something like:
session = KubeSession.from_config(str(kube_config))
try:
await experiment.run(session, args, values_yaml)
finally:
session.close()This allows you to pass session through experiment boundaries only:
BaseExperiment.run(session, args, values_yaml)
BaseExperiment._run(session, ...)
RegressionNodes.run(session, ...)Then inside BaseExperiment.run, you can store self._api_client = session.api_client for convenience, and remove the global entirely.
There are probably even better ways to do this, but definitely this global approach... I don't see the benefit of it.
We have to load the kube_config once at the beginning, and then it's globally initialized in the library, even if we didn't keep it here in the the
As for the wrapper, what do you think about wrapping the kube_utils in a class, storing the api_client there, and injecting that into the experiment? Otherwise, I'm happy to just close this for now. I already have some local changes for moving all of the run fields, including the api_client, into the Experiment classes as per this comment: |
I think this sounds good. But we already have a |
Use global api_client instead of passing it around