Skip to content

Automagic client creation #17

New issue

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

Merged
merged 1 commit into from
Jun 4, 2017

Conversation

brendandburns
Copy link
Contributor

Fixes #12

Builds on top of #7, that PR should be merged first.

@mbohlool
Copy link
Contributor

Please rebase.

@brendandburns
Copy link
Contributor Author

@mbohlool rebased.

Thanks!

@brendandburns
Copy link
Contributor Author

@mbohlool friendly ping on this one.

Thanks!

@mbohlool
Copy link
Contributor

Look like this needs a rebase.

}
String homeDir = System.getenv("HOME");
if (homeDir != null) {
File homeConfig = new File(new File(new File(homeDir), ".kube"), "config");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract constant for all of these strings? ".kube", "config" "HOME", "KUBECONFIG". I suggest we use something like "~/.kube.config" in constant and expand ~.

return fromCluster();
}
ApiClient client = new ApiClient();
client.setBasePath("http://localhost:8080");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this is not https? also better to have constant for this string too.

environmentVariables.set("HOME", "/non-existent");
try {
ApiClient client = Config.defaultClient();
assertEquals(client.getBasePath(), "http://localhost:8080");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we test other cases too?

<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.stefanbirkner/system-rules -->
<dependency>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this dependency is used!?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brendandburns
Copy link
Contributor Author

Comment addressed, please take another look.

@mbohlool
Copy link
Contributor

mbohlool commented Jun 2, 2017

I still see unrelated commits in this PR. Can you please rebase and stash all commits into one?

And some initial tests.
@brendandburns
Copy link
Contributor Author

Rebased and squashed. Thanks!

@brendandburns brendandburns mentioned this pull request Jun 2, 2017
Copy link
Contributor

@mbohlool mbohlool left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I only have one question.

if (currentContext == null) {
return;
System.err.println("Failed to find 'context' in " + ctx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above.

currentContext = (Map<String, Object>) findObject(contexts, context).get("context");
Map<String, Object> ctx = findObject(contexts, context);
if (ctx == null) {
System.err.println("Failed to find context: " + context + " in " + contexts);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I debated this... I decided that I preferered "return false" rather than "throw" because the context not existing isn't "exceptional" per-se but rather a potentially expected outcome...

(and I should probably get rid of the stderr logging)

If you feel strongly about throwing instead of returning false, I'm ok with that, this is a gray area.

(there is some interesting discussion on the subject here: https://codereview.stackexchange.com/questions/11724/is-it-better-practice-to-have-void-method-throw-an-exception-or-to-have-the-meth)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stderr thing distracted me. I agree that returning false is better here. Can you get rid of the stderr logging?

@brendandburns
Copy link
Contributor Author

I debated the question you raised, ultimately I decided to return false instead of throw, but if you feel strongly I'm happy to switch it, let me know.

Thanks!

@mbohlool
Copy link
Contributor

mbohlool commented Jun 4, 2017

As my only comment is the stderr things, to unblock other PRs, I am going to mark this as LGTM and merge it. You can remove those stderr logging in one of the other PRs if you see that fit.

@mbohlool mbohlool merged commit 07cbcb0 into kubernetes-client:master Jun 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants