travisghansen / kubernetes-client-php

No nonsense PHP Client for the Kubernetes API
Apache License 2.0
33 stars 10 forks source link

Change Context #2

Closed zawyelwin closed 4 years ago

zawyelwin commented 4 years ago

How Can I change the current context ?

travisghansen commented 4 years ago

Thanks for reaching out! It was originally never intended to switch contexts for a client instance so it has been assumed you'd have dedicated files for each context necessary.

Can you describe your scenario to help me understand the use case?

zawyelwin commented 4 years ago

I have a config file with multiple clusters and want to loop through the clusters and check some status and grab some contents. Can u give me some suggestions on doing so ? Thanks for the response.

travisghansen commented 4 years ago

Ah yeah, that's an interesting use case. Probably best to add a method on the config class that iterates the various contexts. Would this hypothetical code suit your needs (generally speaking)?

foreach($config->getContexts() as $context) {
  $client = new Client($context);
  ...
}
travisghansen commented 4 years ago

@zawyelwin do you intend to run stuff as '1 and done' or are you attempting to build a long-running controller?

zawyelwin commented 4 years ago

That will be a long-running controller.

travisghansen commented 4 years ago

Ok sounds good. I've got this implemented in master FYI. Got a couple more things to consider but likely in the state it will be in for the next release.

travisghansen commented 4 years ago

This is done and snapped in version v0.2.0.

https://github.com/travisghansen/kubernetes-client-php/blob/master/src/KubernetesClient/Config.php#L231

There are a couple different approaches you can take to the iteration process:

If you have any questions let me know, I think it will be pretty self-explanatory.