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

Fixes various problems usage of OpenShift client #7629

Merged
merged 4 commits into from
Nov 30, 2017
Merged

Fixes various problems usage of OpenShift client #7629

merged 4 commits into from
Nov 30, 2017

Conversation

akorneta
Copy link
Contributor

What does this PR do?

Replaces the usage of one OpenShiftClient per action to one client per che-server. The reason why we do that is the OpenShiftClient holds an instance of OkHttpClient inside and each time when we create new OpenShiftClient we create new OkHttpClient with all the components inside, on close, the OpenShiftClient prevent cancel all calls currently that are executed by OkHttpClient, close all the connections and stop the dispatcher executor service (that undoubtedly is overhead).
Adds closing of watcher on pod removing.
Disables abnormal stop and container events watching.
Launches bootstrapper as a detached process.

What issues does this PR fix or reference?

#7418
This problem is not reproduced in case of using one OpenShift client per che server: #5902

@akorneta akorneta added kind/bug Outline of a bug - must adhere to the bug report template. status/in-progress This issue has been taken by an engineer and is under active development. target/che6 labels Nov 29, 2017
@akorneta akorneta self-assigned this Nov 29, 2017
@@ -103,7 +103,8 @@ protected void doBootstrapAsync(String installerWebsocketEndpoint, String output
+ Integer.toString(installerTimeoutSeconds)
+ " -file "
+ BOOTSTRAPPER_DIR
+ CONFIG_FILE);
+ CONFIG_FILE
+ " &>/dev/null &");

Choose a reason for hiding this comment

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

Please add a comment why you've added this. It is not obvious that it is a way to make process detached.

@@ -107,8 +107,9 @@ protected void internalStart(Map<String, String> startOptions) throws Infrastruc
for (Route route : osEnv.getRoutes().values()) {
createdRoutes.add(project.routes().create(route));
}
project.pods().watch(new AbnormalStopHandler());
project.pods().watchContainers(new MachineLogsPublisher());
// TODO link with issue

Choose a reason for hiding this comment

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

Please add the corresponding issue.

@@ -52,7 +59,7 @@ public OpenShiftClientFactory(
if (doTrustCerts != null) {
configBuilder.withTrustCerts(doTrustCerts);
}
config = configBuilder.build();
this.client = new DefaultOpenShiftClient(configBuilder.build());

Choose a reason for hiding this comment

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

Consider adding a decorator that would eliminate the risk of calling close on the client.

@@ -65,6 +64,9 @@
private static final Pattern CONTAINER_FIELD_PATH_PATTERN =
Pattern.compile("spec.containers\\{(?<" + CONTAINER_NAME_GROUP + ">.*)}");

// TODO make it configurable
public static final int POD_REMOVAL_TIMEOUT_MIN = 5;

Choose a reason for hiding this comment

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

Please create an issue for this todo or remove it

} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new InfrastructureException(
"Interrupted while waiting for pod removal. " + e.getMessage());
} catch (ExecutionException e) {
throw new InfrastructureException(
"Error occurred while waiting for pod removing. " + e.getMessage());
} catch (TimeoutException ex) {
throw new InfrastructureException("Pods removal timeout reached " + ex.getMessage());

Choose a reason for hiding this comment

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

Can you elaborate on what will happen in this situation with cleanup of other resources and with the possible following start of the same workspace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is similar to other exception that is possible on cleanup, I would say that we should revise cleanup in general. Because if any step of cleanup is failed then, other resources won't be cleaned. I'll create an issue for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

return deleteFuture
.thenAccept((v) -> watch.close())
.exceptionally(
e -> {

Choose a reason for hiding this comment

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

Shouldn't we also log the 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.

added exception logging

Copy link

@garagatyi garagatyi 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. The investigation is cool!

return deleteFuture;

return deleteFuture
.thenAccept((v) -> watch.close())
Copy link
Member

Choose a reason for hiding this comment

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

Looks like it's the same as

      return deleteFuture
          .handle((v, e) -> {
            watch.close();
            return null;
          });

But it will supress rethrowing of exception from original delete future. Is it OK?

@akorneta akorneta added status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. and removed status/in-progress This issue has been taken by an engineer and is under active development. labels Nov 30, 2017
/** Decorates the {@link DefaultOpenShiftClient} so that it can not be closed from the outside. */
private static class UnclosableOpenShiftClient extends DefaultOpenShiftClient {

public UnclosableOpenShiftClient(OpenShiftConfig build) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's rename it to config =)


/** @author Sergii Leshchenko */
@Singleton
Copy link
Member

Choose a reason for hiding this comment

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

Don't be shy to add yourself as an author 😉

Copy link

@garagatyi garagatyi left a comment

Choose a reason for hiding this comment

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

Good job!

@akorneta akorneta merged commit 09df5d5 into che6 Nov 30, 2017
@akorneta akorneta deleted the CHE-5902 branch November 30, 2017 16:27
@akorneta akorneta removed the status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. label Nov 30, 2017
@benoitf benoitf added this to the 6.0.0-M3 milestone Nov 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Outline of a bug - must adhere to the bug report template.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants