-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
adding custom ConfigBuilder #171
adding custom ConfigBuilder #171
Conversation
sorry, will correct unit tests... |
return this; | ||
} | ||
|
||
public String getbasePath() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getBasePath()
return basePath; | ||
} | ||
|
||
public ConfigBuilder setbasePath(String basePath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setBasePath(...)
} | ||
|
||
public ApiClient build() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete newline
|
||
if( kubeConfig !=null) { | ||
client = Config.fromConfig(kubeConfig); | ||
return client; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this logic is a little odd.
I would expect that I could do:
client = new ConfigBuilder().setKubeConfig().setBasePath().build()
And it would mostly load the KubeConfig, but then override the basepath with the custom value I set.
Instead, it just returns the existing KubeConfig and ignores any other setFoo
directives.
I think that this is going to confuse people, and doesn't match the desired use case.
} catch (FileNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
return client; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above.
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return client; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above.
e.printStackTrace(); | ||
} | ||
return client; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete newline (here and everywhere it's extraneous)
basePath = basePath.substring(0, basePath.length() - 1); | ||
} | ||
client.setBasePath(basePath) | ||
.setVerifyingSsl(verifyingSsl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you setting verifyingSsl
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by default(if user doesn't set anything ), want to set verifyingSsl to false.
but i forget to add the actual setter..(will rectify it)
if( verifyingSsl != null ){
client..setVerifyingSsl(verifyingSsl);
}
} | ||
|
||
else { | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is weird. You are try{ ... } catch
and then throwing the exception yourself. Just log to stderr? or throw an exception?
if((certificateAuthorityData != null) || (certificateAuthorityFile != null)){ | ||
try { | ||
client.setSslCaCert(SSLUtils.getInputStreamFromDataOrFile(certificateAuthorityData, certificateAuthorityFile)); | ||
} catch (FileNotFoundException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should load the cert when someone calls setCertificateAuthority(...)
And not throw/catch here.
return this; | ||
} | ||
|
||
public boolean isTrustCerts() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to do anything. Delete?
return this; | ||
} | ||
|
||
public ConfigBuilder setKubeConfig(String fileName) throws FileNotFoundException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little weird to use File
for CertificateAuthority and String
here, I think consistency one way or the other is probably better.
} | ||
|
||
if(defaultKubeConfigMode == true) { | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get rid of the try/catch and just have build()
throw, I think that's better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better: move KubeConfig.loadDefaultKubeConfig()
up into the setDefaultMode()
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brendandburns
is the following what you intend
public ConfigBuilder setDefaultMode() {
this.defaultMode = true;
return this;
}
build() throws Exception{
....
if(defaultMode == true) {
client = Config.fromConfig(KubeConfig.loadDefaultKubeConfig());
}
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kondapally1989 no, what I was thinking was this:
public ConfigBuilder setDefaultMode() throws IOException {
this.client = config.fromConfig(KubeConfig.loadDefaultKubeConfig());
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brendandburns
if setDefaultMode() points to Config.fromConfig(KubeConfig.loadDefaultKubeConfig())
and setDefaultClientMode points to Config.defaultClient();
isn't the naming convention confusing. instead of setDefaultMode() cant we have setDefaultKubeConfigMode()
|
||
if(clusterMode == true) { | ||
try { | ||
client = Config.fromCluster(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
|
||
if(defaultClientMode ==true ) { | ||
try { | ||
client = Config.defaultClient(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too?
} | ||
client.setBasePath(basePath); | ||
} else { | ||
if((clusterMode == false) && (defaultClientMode == false) && (defaultKubeConfigMode == false)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't throw here, I would just do:
if (client.getBasePath().length() == 0) {
client.setBasePath("http://localhost:8080")
}
|
||
if(certificateAuthorityFile != null) { | ||
try { | ||
client.setSslCaCert(new FileInputStream(certificateAuthorityFile)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this exception up to the setCertificateAuthority
call...
A few more comments, thanks for your patience, this is getting close! |
This look great! An oddity about |
Also any thoughts on doing something like lewisheadden@ac7c1b5? It seems like it's hard to know which set of fields should be set for which auth method and this might simplify it. |
ClientBuilder sounds apt. |
That approach seems reasonable... |
ok i will change it to ClientBuilder. |
@kondapally1989 I can open a PR afterwards if that's easier for you. The example I pushed needs cleaned up. |
@lewisheadden just changed the classname and few changes, you can create PR for the changes you suggested after this PR is done. |
LGTM, thanks for the patience. There are a couple more cleanups, but they can wait for a follow-on PR. |
return this; | ||
} | ||
|
||
public ApiClient build() throws FileNotFoundException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see this get to a point where it doesn't throw FileNotFoundException
I think that means moving the cert loading to the setter function.
custom ConfigBuilder. issue: #168