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

CHE-26: Initial OpenShift integration #3798

Merged
merged 3 commits into from
Jan 27, 2017
Merged

Conversation

ibuziuk
Copy link
Member

@ibuziuk ibuziuk commented Jan 18, 2017

What does this PR do?

Initial OpenshiftConnector implementation

What issues does this PR fix or reference?

https://issues.jboss.org/browse/CHE-26

NOTE: Do not merge until PR with io.fabric8 dependencies is applied - eclipse-che/che-dependencies#23

New behavior

Provides a possibility to use openshift io.fabric8 API for container management

# Which implementation of DockerConnector to use in managing containers. In general,
# the base implementation of DockerConnector is appropriate, but OpenShiftConnector
# is necessary for deploying Che on OpenShift. Options:
#     - 'default'   : Use DockerConnector
#     - 'openshift' : use OpenShiftConnector
che.docker.connector=default

Tests written?

Yes

Changelog and Release Note Information

Changelog

Add OpenShiftConnector to support io.fabric8 API for container management.

Release Notes:
[no release notes since this is part of a work in progress]

Docs Pull Request:

Docs issue is here, but docs won't be created until #2847 is complete.

@codenvy-ci
Copy link

Can one of the admins verify this patch?

@ibuziuk
Copy link
Member Author

ibuziuk commented Jan 18, 2017

@l0rd @amisevsk could you please verify? Just do not forget to build che-dependencies from https://issues.jboss.org/browse/CHE-26 first

@TylerJewell
Copy link

FYI, we are implementing a new maintenance policy for PRs where each PR will need to have completed changelog, docs linked PR, and release notes included within it before merge. We are documenting this now and how maintainers + PR submitters are to work through these items. But as this is significant, wanted to give this heads up.

@gorkem
Copy link
Contributor

gorkem commented Jan 18, 2017

@TylerJewell Since this is the initial implementation and we will have a few more iterations until this is completed. Perhaps we can open an issue and for the missing docs and assign it to @ibuziuk or @l0rd.

@TylerJewell
Copy link

Like larger projects, we have moved all of the docs into a separate repository. It seems essential so that the core repository doesn't end up with a lot of large image or animated gif files that complicates cloning and fetching with git. So, we have moved everything into github.com/codenvy/che-docs as a repository and it will be moved into github.com/eclipse/che-docs as soon as the repository has been created and CQ passed, which should be this week.

But in the mean time, we ask that every core PR have a matching che-docs PR linked into it, and then both PRs are merged at the same time. If you'd like a separate issue for just that work, that makes sense.

@ibuziuk
Copy link
Member Author

ibuziuk commented Jan 18, 2017

@TylerJewell @gorkem I would be glad to work on documentation part

@TylerJewell
Copy link

Thanks, @gorkem and @ibuziuk for being flexible with us as we work to get our documentation processes better refined. I know they are in a state of flux right now, so having ambiguous rules that must be passed in order to get something merged is not good for anyone.

The basic rules of what we are thinking for docs is the following three things provided within the PR:

  1. A single line to be used in the Changelog
  2. If a new feature, then a cross-link PR to github.com/codenvy/che-docs with the docs improvements and suggestions.
  3. A section that includes what we should include in the Release Notes for the next release. This can be small or long markdown. We think of release notes as a marketing tool.

In this case for the documentation, I think there are probably a few pages of the docs that should be updated:

  1. The configuration page of the setup section, about how to set this property.
  2. Then the user pages that we currently have talking about OpenShift. We have dedicated pages that currently cover how to use Che to integrate with OpenShift, but we should add another page dedicated to how to deploy Che onto OpenShift.

@benoitf
Copy link
Contributor

benoitf commented Jan 19, 2017

ci-build

@ibuziuk
Copy link
Member Author

ibuziuk commented Jan 19, 2017

Issue for documenting the process of deployment Che on OpenShift has been created https://github.com/codenvy/che-docs/issues/76

@l0rd l0rd mentioned this pull request Jan 19, 2017
14 tasks
@codenvy-ci
Copy link

this.nameGenerator = nameGenerator;
this.runtimes = workspaceRuntimes;
this.runtimes = workspaceRuntimes;
Copy link
Contributor

Choose a reason for hiding this comment

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

indent looks like incorrect

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@@ -104,7 +105,7 @@
private final MachineRuntimeInfoImpl machineRuntime;

@Inject
public DockerInstance(DockerConnector docker,
public DockerInstance(DockerConnectorProvider dockerProvider,
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need guice Providers vs named connector ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure I got the comment :( We do need to inject provider because now it is in charge of providing suitable connector (DockerConnector / OpenShiftConnector) based on che.docker_connector.provider property

Copy link
Member Author

Choose a reason for hiding this comment

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

@benoitf BTW, similar approach is used for obtaining ServerEvaluationStrategy (default / docker-local) - https://github.com/eclipse/che/blob/master/plugins/plugin-docker/che-plugin-docker-machine/src/main/java/org/eclipse/che/plugin/docker/machine/local/LocalDockerModule.java#L52
And I think it is relevant to also use MapBinder for DockerConnector use-case (default / openshift)

Copy link
Contributor

Choose a reason for hiding this comment

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

@ibuziuk I agree

Choose a reason for hiding this comment

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

I agree with Florent that it would look prettier if we get rid of injecting provider. There is always a way to reduce distraction. But up to you.

Copy link
Member Author

Choose a reason for hiding this comment

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

@garagatyi For initial implementation I would rather leave it this way. The usage of DockerConnectorProvider will be changed once OpenShiftConnector is decoupled from DockerConnector and there will be a good time for rethinking the whole approach

<build>
<resources>
<resource>
<directory>src/main/java</directory>
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to specify this directory as a resource item ?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

private final KubernetesContainer kubernetesContainer;
private final KubernetesService kubernetesService;
private final String cheOpenShiftProjectName;
private final String cheOpenShiftServiceAccount;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure indent of previous lines are compliant with code style

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@Named("che.openshift.username") String openShiftUserName,
@Named("che.openshift.password") String openShiftUserPassword,
@Named("che.openshift.project") String cheOpenShiftProjectName,
@Named("che.openshift.serviceaccountname") String cheOpenShiftServiceAccount) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason why some of attributes for che.* are starting with che and others by openShift ?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed. All attributes are now starting with openShift.*

LOG.warn("Expected CreateContainerParams label key " + entry.getKey() +
" to start with " + CHE_SERVER_LABEL_PREFIX);
} else if (key.contains(".") || key.contains("_") || value.contains("_")) {
LOG.error(String.format("Cannot convert label %s to DNS Name: "
Copy link
Contributor

Choose a reason for hiding this comment

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

do not use format and +

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

value = String.format(CHE_SERVER_LABEL_PADDING, value);

if (!key.matches(KUBERNETES_ANNOTATION_REGEX) || !value.matches(KUBERNETES_ANNOTATION_REGEX)) {
LOG.error(String.format("Could not convert label %s into Kubernetes annotation: "
Copy link
Contributor

Choose a reason for hiding this comment

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

do not use + and format

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

import io.fabric8.kubernetes.api.model.IntOrString;
import io.fabric8.kubernetes.api.model.ServicePort;

public class KubernetesService {
Copy link
Contributor

Choose a reason for hiding this comment

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

javadoc is missing

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

public class KubernetesService {

public List<ServicePort> getServicePortsFrom(Set<String> exposedPorts) {
List<ServicePort> servicePorts = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

size is known so we can define it

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@@ -1214,23 +1214,6 @@
</configuration>
</execution>
<execution>
<id>distribution-management-used</id>
Copy link
Contributor

Choose a reason for hiding this comment

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

why is it removed ?

@ibuziuk
Copy link
Member Author

ibuziuk commented Jan 20, 2017

@benoitf thank you for review. Working on improvements..

@ibuziuk ibuziuk force-pushed the CHE-26 branch 2 times, most recently from b8ccae9 to 0275d07 Compare January 20, 2017 17:54
@ibuziuk
Copy link
Member Author

ibuziuk commented Jan 20, 2017

ci-build

@benoitf benoitf added the kind/enhancement A feature request - must adhere to the feature request template. label Jan 23, 2017
@benoitf benoitf dismissed their stale review January 23, 2017 13:12

most of the comments were addressed

@benoitf
Copy link
Contributor

benoitf commented Jan 23, 2017

ci-build

@codenvy-ci
Copy link

Build # 1737 - FAILED

Please check console output at https://ci.codenvycorp.com/job/che-pullrequests-build/1737/ to view the results.

@ibuziuk
Copy link
Member Author

ibuziuk commented Jan 23, 2017

@l0rd could you please push the build ? it seems to be working only for committers. There is one regression test failure, but all tests pass on my machine

@ibuziuk
Copy link
Member Author

ibuziuk commented Jan 23, 2017

@garagatyi @gazarenkov guys, could you please review the PR ?

@benoitf
Copy link
Contributor

benoitf commented Jan 23, 2017

ci-build

1 similar comment
@garagatyi
Copy link

ci-build

@garagatyi
Copy link

Guys how do you want to merge this PR? Are you going to do merge with rebase or squash or just merge?

@garagatyi
Copy link

@gazarenkov @benoitf Can you take one more look?

@ibuziuk
Copy link
Member Author

ibuziuk commented Jan 24, 2017

@garagatyi thanks for review. I would rather opt for "just merge" as there are commits from different authors in the PR. @l0rd WDYT ?

@garagatyi
Copy link

Maybe you can try to rebase with newest master at the time you will merge and if there will be no conflicts then merge this PR with Github's merge with rebase? @l0rd WDYT?

@ibuziuk
Copy link
Member Author

ibuziuk commented Jan 24, 2017

@garagatyi after some discussion it was decided to squash last three commits and use "Rebase and Merge" strategy for applying the PR. Also, there is some problem with ip-validation - all commits have "Signed-off-by" section but the check still fails

@benoitf
Copy link
Contributor

benoitf commented Jan 24, 2017

@ibuziuk sometimes the script is failing

@l0rd
Copy link
Contributor

l0rd commented Jan 24, 2017

@garagatyi Yes we would like to keep the 3 significant commit and squash last two commits. Then rebase + merge as soon as soon as review is complete.

@ibuziuk
Copy link
Member Author

ibuziuk commented Jan 24, 2017

@benoitf oh, ok
@garagatyi yes, we have also decided to do it this way. PR has been rebased on top of master

Copy link
Contributor

@benoitf benoitf left a comment

Choose a reason for hiding this comment

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

@gazarenkov @benoitf Can you take one more look?

I give a new look at it
I've commented with some errors reported by FindBugs or SonarLint
OpenShift connector class is tested at:
7% method, 6% lines covered

while DockerConnector is tested at
100% methods, 95% line covered

Note: the kubernetes module is better tested: 100% classes, 89% lines covered

openShiftClient.resource(replicaSet).delete();
}

if (pod != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

using SonarLint, I have the warning that this variable is always non null

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed


String containerID = waitAndRetrieveContainerID(deploymentName);
if (containerID == null) {
throw new RuntimeException("Failed to get the ID of the container running in the OpenShift pod");
Copy link
Contributor

Choose a reason for hiding this comment

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

sonarlint hint is to subclass this exception

Using such generic exceptions as Error, RuntimeException, Throwable, and Exception prevents calling methods from handling true, system-generated exceptions differently than application-generated errors.
Noncompliant Code Example
public void foo(String bar) throws Throwable {  // Noncompliant
  throw new RuntimeException("My Message");     // Noncompliant
}
Compliant Solution
public void foo(String bar) {
  throw new MyOwnRuntimeException("My Message");
}

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

*/
public Map<String, String> labelsToNames(Map<String, String> labels) {
Map<String, String> names = new HashMap<>();
for (Map.Entry<String, String> entry : labels.entrySet()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

SonarLint is flagging this loop as error

Loops should not contain more than a single "break" or "continue" statement
squid:S135 
Restricting the number of break and continue statements in a loop is done in the interest of good structured programming.
One break and continue statement is acceptable in a loop, since it facilitates optimal coding. If there is more than one, the code should be refactored to increase readability.

Copy link
Member Author

Choose a reason for hiding this comment

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

the method has been refactored

}

private Pod getChePodByContainerId(String containerId) throws IOException {
Map<String, String> podLabels = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

findbugs shows that podLabels is initialized but never used in that method

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

l0rd and others added 3 commits January 26, 2017 18:58
Adds class so that choice between DockerConnector and OpenShiftConnector
can be made via setting a property in che.properties. The provider is
injected instead of DockerConnector, and provides the appropriate
implementation through a get() method.

Signed-off-by: Angel Misevski <[email protected]>
…resources (KubernetesContainer, KubernetesService, KubernetesEnvVar)

Signed-off-by: Ilya Buziuk <[email protected]>
@ibuziuk
Copy link
Member Author

ibuziuk commented Jan 26, 2017

@benoitf thanks again for reviewing. PR has been updated with fixes and rebased on the current master branch. In terms of test coverage there are several reasons why OpenShiiftConnector is not well-covered in comparison with kubernetes package:

  1. kubernetes package is better tested because most of it's functionality is coupled with String manipulations (adjusting labels, ports, env. vars from / to kubernetes API). However, for OpenshiftConnector meaningful integration tests against minishift cluster are required and it simply can not be properly tested via unit tests
  2. For now OpenShiftConnector extends DockerConnector and there are a bunch of methods that are (will be) either empty of throw UnsupportedOperationException e.g. Network create / remove / update. Once SPI for Che runtime management is defined I believe the code will be much cleaner and with better test coverage.

Basically, this PR is just initial minimal OpenShift integration piece and most of the code together with tests will be changed / refactored once Service Provider Interface is defined.

@benoitf
Copy link
Contributor

benoitf commented Jan 26, 2017

@ibuziuk ok thanks for the fixes.
about tests I will wait the service provider interface then.

@l0rd l0rd merged commit 1ec641a into eclipse-che:master Jan 27, 2017
@benoitf benoitf added this to the 5.2.0 milestone Jan 27, 2017
@riuvshin
Copy link
Contributor

riuvshin commented Jan 27, 2017

hey guys we have problems with compilation of https://github.com/codenvy/codenvy project seems due to those changes. @garagatyi @benoitf can you guys please take a look

01:03:40 /home/codenvy/workspace/codenvy-ci-master/plugins/plugin-hosted/codenvy-machine-hosted/src/main/java/com/codenvy/machine/HostedDockerInstance.java:61: error: incompatible types: DockerConnector cannot be converted to DockerConnectorProvider
01:03:40         super(docker,
01:03:40               ^

more info:

https://ci.codenvycorp.com/job/codenvy-ci-master/1293/console

@amisevsk
Copy link
Contributor

Hi @riuvshin.

One of the changes this PR makes is to inject DockerConnectorProvider instead of DockerConnector. This is done because OpenShiftConnector is a replacement for DockerConnector when running Che on OpenShift.

This means changing the method signature for constructors using DockerConnector to use DockerConnectorProvider instead, and calling DockerConnectorProvider.get() to get the DockerConnector instance. To accommodate this change in Codenvy, classes calling these constructors will have to be changed.

I'll be available later to explain the required fixes in more detail.

@garagatyi
Copy link

@riuvshin We missed this as consequence of missing QA cycle.

@benoitf
Copy link
Contributor

benoitf commented Jan 27, 2017

I've created a PR codenvy/codenvy#1636
you may commit on my branch if it does not fix all issues or do whatever you want with that PR

garagatyi pushed a commit to codenvy/codenvy that referenced this pull request Jan 28, 2017
Update code based on CHE #3798 updates
@amisevsk
Copy link
Contributor

If it helps, the classes in the main codebase that are affected are KeysInjector, CgroupOOMDetector, DockerInstance, DockerInstanceProvider, DockerInstanceStopDetector, DockerProcess, MachineProviderImpl, DockerAbandonedResourcesCleaner, and LocalDockerModule.

Any classes calling these constructors directly would need to be modified, as in @benoitf's PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement A feature request - must adhere to the feature request template.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants