adding custom ConfigBuilder#171
Conversation
|
sorry, will correct unit tests... |
| return this; | ||
| } | ||
|
|
||
| public String getbasePath() { |
| return basePath; | ||
| } | ||
|
|
||
| public ConfigBuilder setbasePath(String basePath) { |
| } | ||
|
|
||
| public ApiClient build() { | ||
|
|
|
|
||
| if( kubeConfig !=null) { | ||
| client = Config.fromConfig(kubeConfig); | ||
| return client; |
There was a problem hiding this comment.
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; |
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| return client; |
| e.printStackTrace(); | ||
| } | ||
| return client; | ||
|
|
There was a problem hiding this comment.
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.
why are you setting verifyingSsl here?
There was a problem hiding this comment.
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.
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.
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.
This doesn't seem to do anything. Delete?
| return this; | ||
| } | ||
|
|
||
| public ConfigBuilder setKubeConfig(String fileName) throws FileNotFoundException { |
There was a problem hiding this comment.
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.
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.
Better: move KubeConfig.loadDefaultKubeConfig() up into the setDefaultMode() function.
There was a problem hiding this comment.
@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.
@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.
@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(); |
|
|
||
| if(defaultClientMode ==true ) { | ||
| try { | ||
| client = Config.defaultClient(); |
| } | ||
| client.setBasePath(basePath); | ||
| } else { | ||
| if((clusterMode == false) && (defaultClientMode == false) && (defaultKubeConfigMode == false)) { |
There was a problem hiding this comment.
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.
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.
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