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

Service integration #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LarsAndereggIMS
Copy link

-integration of kubernetes Service
-PodWaitLogStrategy timeout strikes even if no logs lines are received
-Pods are also removed even if waitStrategy runs into timeout

-PodWaitLogStrategy timeout strikes even if no logs lines are received
-Pods are also removed even if waitStrategy runs into timeout
@LarsAndereggIMS LarsAndereggIMS marked this pull request as ready for review March 22, 2021 20:45
Copy link
Owner

@JeanBaptisteWATENBERG JeanBaptisteWATENBERG left a comment

Choose a reason for hiding this comment

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

Hi @LarsAndereggIMS,

Thanks a lot for your contribution 💯 !

Could you describe me your use case and what you are trying to achieve by adding the possibility to create a service in the tests ? Until now my approach was to create a service automatically for each pod referenced in a test and I would like to see how it complements with your suggested approach.

I didn't yet manage to test your modifications but gave you an early review on some area we likely would want to improve. Please feel free to tell me if you have some time to look into this or else I could manage to work a bit on this in next week end.

Additionally to those comments you may want to check why the build failed (https://github.com/JeanBaptisteWATENBERG/junit5-kubernetes/runs/2169846205#step:6:71) and add some test to cover the service feature. Also adding a sample in the readme to document it would be great.

Thank you,
Jean-Baptiste

if (retrievedService.getStatus() == null) {
throw new RuntimeException("Can't get ip of a non running object.");
}
//Anhand der Umgebungsvariable entscheiden, ob der Test im Cluster oder lokal ausgeführt wird

Choose a reason for hiding this comment

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

Suggested change
//Anhand der Umgebungsvariable entscheiden, ob der Test im Cluster oder lokal ausgeführt wird
//Use the environment variable to decide whether to run the test in the cluster or locally

Comment on lines +39 to +66
private static CoreV1Api initiateCoreV1Api() {
CoreV1Api coreV1Api;
try {
ApiClient client = Config.defaultClient();
if (DEBUG != null && DEBUG.equalsIgnoreCase("true")) {
client.setDebugging(true);
}
// infinite timeout
OkHttpClient.Builder builder = client.getHttpClient().newBuilder()
.readTimeout(0, TimeUnit.SECONDS);

if (DISABLE_HTTP2 != null && DISABLE_HTTP2.equalsIgnoreCase("true")) {
builder.protocols(Collections.singletonList(Protocol.HTTP_1_1));
}

client.setVerifyingSsl(false);

OkHttpClient httpClient = builder.build();
client.setHttpClient(httpClient);
Configuration.setDefaultApiClient(client);

coreV1Api = new CoreV1Api(client);

} catch (IOException e) {
throw new RuntimeException(e);
}
return coreV1Api;
}

Choose a reason for hiding this comment

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

We may want to factorize this client initiation in kubernetesGenericObject to avoid duplicating it from Pod.java.

if(System.getenv("KUBERNETES_PORT") != null) {
return retrievedService.getSpec().getClusterIP();
}else{
return retrievedService.getSpec().getExternalIPs().get(0);

Choose a reason for hiding this comment

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

In some clusters a service may not have any externalIps and under those circumstances I think we should raise an exception with an explicit message.

}

if (!serviceSuccessfullyStarted) {
throw new RuntimeException("Failed to run pod " + this + " before timeout " + this.getTimeout());

Choose a reason for hiding this comment

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

Suggested change
throw new RuntimeException("Failed to run pod " + this + " before timeout " + this.getTimeout());
throw new RuntimeException("Failed to run service " + this + " before timeout " + this.getTimeout());

Comment on lines +161 to +165
protected static RuntimeException logAndThrowApiException(ApiException e) {
LOGGER.severe("Kubernetes API replied with " + e.getCode() + " status code and body " + e.getResponseBody());
System.out.println("Kubernetes API replied with " + e.getCode() + " status code and body " + e.getResponseBody());
return new RuntimeException(e.getResponseBody(), e);
}
Copy link
Owner

@JeanBaptisteWATENBERG JeanBaptisteWATENBERG Mar 23, 2021

Choose a reason for hiding this comment

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

I believe we should factorize this as well in the abstract class

Copy link
Author

Choose a reason for hiding this comment

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

Hi @JeanBaptisteWATENBERG,

thank you for your quick response! Hopefully this week I will find some time to look closer at your Points.

I needed to create a more specific service for the pods. Instead of extending the service config over a pod, I thougth making an explictit service would be clearer.

Best regards
Lars

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.

2 participants