8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
enables client-python to be used inside a kubernetes cluster.
Fixes #26
Sorry, something went wrong.
6315ee7
0f1bcec
What's the plan for enabling automated testing (unit/integration/e2e)? There's only so much a review of code can do, and I'd rather be reviewing code + tests, and have those tests run automatically.
bbf441b
@marun Thanks for demanding test from a lazy engineer here :) It is in much better shape now. Refactored code to be able to test and added tests. Please take another look.
792b5fb
e9568d2
4b1c41f
@marun would you please take another look at this? I want to create a release after this PR.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to see tests. Is there a timeline on automatic execution ci and e2e (so that client behavior can be validated against a real cluster)?
(No action required)
Consider avoiding explicitly calling str() (i.e. '%s' % 42 works just fine).
str()
Also, consider the following alternate implementation:
template = '%s:%s' # Where possible, assign a conditional statement to a variable and name it descriptively. # This can reduce the need for comments, which cost more to maintain than code that is self-documenting. host_requires_bracketing = ':' in host or '%' in host if host_requires_bracketing: template = '[%s]:%s' return template % (host, port)
'r' is the default and can be omitted.
'r'
Done.
Consider separating reading of cluster config from modifying configuration to ensure it is only modified once configuration has been validated. This separation of concerns will also allow simplify testing by allowing the read values to be checked without involving configuration:
configuration
# Consider using namedtuple instead of a dict for simple types ClusterConfig = collections.NamedTuple('ClusterConfig', ['host', 'token'...]) def load_incluster_config(environ=os.environ): conf = read_incluster_config(environ=environ) set_incluster_config(conf) def read_incluster_config(environ=os.environ): # Consider checking the value of env vars rather than the presence of the name to protect against empty vars service_host = environ.get(_SERVICE_HOST_ENV_NAME) if not service_host: raise ConfigException("Service host not set.") ... host = 'https://%s' % (_join_host_port(service_host, service_port) return ClusterConfig(host, token...) def set_incluster_config(conf): configuration.host = conf.host ...
This will also avoid the problem of modifying configuration in one unit test and accidentally having that modification affect the behavior of a different test that relies on its state. Due to configuration being a singleton, any changes to its default state must be reverted on test teardown.
I've used the InClusterConfigLoader to store the values and separate load and set methods.
Consider reusing the names of the env vars defined as constants in the module under test (e.g. _SERVICE_HOST_ENV_NAME) rather than defining new names in this test module. Since the environ dict is passed to the function under test, there is no need to vary the names of the env vars and the names can be fixed across runtime and test.
_SERVICE_HOST_ENV_NAME
@marun I am going to discuss ci and e2e with kubernetes e2e test folks in a separate thread/issue.
Add incluster config support
ba3e22a
@marun, I've addressed all of your comments. As all of them were optional, I assume this PR is look good. Please apply LGTM next time if your comments are all optional. Thanks for the review.
What if the file is empty?
Missed these comments, addressed them in #50
What about the case where either of the env vars are defined but empty (e.g. KUBERNETES_SERVICE_HOST=)?
KUBERNETES_SERVICE_HOST=
9506c55
marun marun left review comments
marun
Successfully merging this pull request may close these issues.