Skip to content
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

Merged
merged 4 commits into from
Feb 2, 2018
Merged

adding custom ConfigBuilder #171

merged 4 commits into from
Feb 2, 2018

Conversation

karthikkondapally
Copy link
Contributor

custom ConfigBuilder. issue: #168

@karthikkondapally
Copy link
Contributor Author

karthikkondapally commented Jan 22, 2018

sorry, will correct unit tests...

return this;
}

public String getbasePath() {
Copy link
Contributor

@brendandburns brendandburns Jan 24, 2018

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

setBasePath(...)

}

public ApiClient build() {

Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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;

Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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 {
Copy link
Contributor

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) {
Copy link
Contributor

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() {
Copy link
Contributor

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 {
Copy link
Contributor

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 {
Copy link
Contributor

@brendandburns brendandburns Jan 26, 2018

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.

Copy link
Contributor

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.

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
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());
}
...
}

Copy link
Contributor

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());
}

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
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();
Copy link
Contributor

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();
Copy link
Contributor

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)) {
Copy link
Contributor

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));
Copy link
Contributor

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...

@brendandburns
Copy link
Contributor

A few more comments, thanks for your patience, this is getting close!

@lewisheadden
Copy link
Contributor

lewisheadden commented Jan 27, 2018

This look great!

An oddity about Config which has bothered me is that it returns ApiClient not configurations and I was wondering whether this should really be called ClientBuilder or similar given that it returns an ApiClient?

@lewisheadden
Copy link
Contributor

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.

@karthikkondapally
Copy link
Contributor Author

ClientBuilder sounds apt.
and
lewisheadden@ac7c1b5
@brendanburns ?

@brendandburns
Copy link
Contributor

That approach seems reasonable...

@karthikkondapally
Copy link
Contributor Author

karthikkondapally commented Feb 1, 2018

ok i will change it to ClientBuilder.
@lewisheadden is it okay if I push the changes you suggested or will you push after this is completed ?

@lewisheadden
Copy link
Contributor

@kondapally1989 I can open a PR afterwards if that's easier for you. The example I pushed needs cleaned up.

@karthikkondapally
Copy link
Contributor Author

@lewisheadden just changed the classname and few changes, you can create PR for the changes you suggested after this PR is done.

@brendandburns
Copy link
Contributor

LGTM, thanks for the patience. There are a couple more cleanups, but they can wait for a follow-on PR.

@brendandburns brendandburns merged commit 3b9000b into kubernetes-client:master Feb 2, 2018
return this;
}

public ApiClient build() throws FileNotFoundException {
Copy link
Contributor

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.

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