Skip to content

Private registries support#9962

Merged
davidfestal merged 10 commits intomasterfrom
private-registries-support
Jun 11, 2018
Merged

Private registries support#9962
davidfestal merged 10 commits intomasterfrom
private-registries-support

Conversation

@davidfestal
Copy link
Copy Markdown
Contributor

What does this PR do?

This PR adds support of private docker registries when running on the Kubernetes and OpenShift infrastructure.

What issues does this PR fix or reference?

redhat-developer/rh-che#680

Related to issue redhat-developer/rh-che#680

Signed-off-by: David Festal <dfestal@redhat.com>
Signed-off-by: David Festal <dfestal@redhat.com>
Signed-off-by: David Festal <dfestal@redhat.com>
Signed-off-by: David Festal <dfestal@redhat.com>
@davidfestal davidfestal requested a review from garagatyi as a code owner June 7, 2018 20:33
@codenvy-ci
Copy link
Copy Markdown

Can one of the admins verify this patch?

@davidfestal davidfestal requested review from ibuziuk and l0rd June 7, 2018 20:35
@davidfestal
Copy link
Copy Markdown
Contributor Author

ci-test

@davidfestal davidfestal self-assigned this Jun 7, 2018
@benoitf benoitf added status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. kind/enhancement A feature request - must adhere to the feature request template. labels Jun 7, 2018
@codenvy-ci
Copy link
Copy Markdown

ci-test build report:
Build details
Test report
selenium tests report data
docker image: eclipseche/che-server:9962
https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

@garagatyi garagatyi requested a review from sleshchenko June 8, 2018 06:37
davidfestal added a commit to redhat-developer/rh-che that referenced this pull request Jun 8, 2018
Adapt to changes made in upstream PR
eclipse-che/che#9962

Signed-off-by: David Festal <dfestal@redhat.com>
Copy link
Copy Markdown

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

Overall looks good. I would love to see code been improved from the support side. I added inlined comments about that.

import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment;
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespaceFactory;

/** @author David Festal */
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please, add javadocs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

throws InfrastructureException {

AuthConfigs authConfigs = userSpecificDockerRegistryCredentialsProvider.getCredentials();
if (authConfigs.getConfigs().isEmpty()) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You may get an NPE here. Please, add a check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Base64.Encoder encoder = Base64.getEncoder();

String config;
try (StringWriter strWriter = new StringWriter();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This class contains multiple levels of abstraction - usage of provider, manipulating strings, usage of k8s objects. This makes it too complex. Please, move conversion of AuthConfigs to Secret into a separate class.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe private method could be enough

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed with a private method

(name, authConfig) -> {
try {
if (!name.startsWith("https://")) {
name = "https://" + name;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

if the name starts from http:// we add "https://" in front of it. Should we really do that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

jsonWriter.value(authConfig.getPassword());
jsonWriter.name("email");
jsonWriter.value("email@email");
String auth =
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you point me to a doc that describes how this object should look like - I don't understand by looking at the code. This also indicates that this code is not clear and might require additional code simplifications or comments to ease support of this code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added an example in the Javadoc of the extracted private method

k8sEnv.getPods().values().forEach(this::provision);
}

public void provision(Pod pod) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It looks like this method should be private

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

.getBytes());
}

@SuppressWarnings("unchecked")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If you use suppressing of warnings, please, add a comment to the doc that explains why it is safe to suppress warnings.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

BTW it's not good practice to use SuppressWarnings for the whole method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed the warnings completely, so no more SuppressWarnings :-)

verifyZeroInteractions(podSpec);
}

private static class TestAuthConfig implements AuthConfig {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please, move auxiliary methods down. It is easier to read test when test cases are higher and all other methods are lower in the class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

</dependency>
<dependency>
<groupId>org.eclipse.che.infrastructure.docker</groupId>
<artifactId>docker-client</artifactId>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this dependency can potentially bring some issues in future. I suggest to move docker auth related code in separate maven module and replace this dependency with it.
@sleshchenko @garagatyi @gazarenkov wdyt?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@skabashnyuk the same applies to the docker-environment dependency that is just below right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would say that not the same. It is supposed that docker-environment may be reused by another infrastructure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is it a blocker for this PR or could this new module refactoring be done in a next PR ?

Copy link
Copy Markdown
Contributor

@skabashnyuk skabashnyuk Jun 8, 2018

Choose a reason for hiding this comment

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

Yes. Could you do that please in this PR. I really appreciate your efforts. I guess it will take less time then we spend writing this comments and protect us with potential binding/classloading/configuration issues.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I extracted the docker auth-related classes to a new docker-auth maven module.
@skabashnyuk does it correspond to what you were expecting ?

static final String SECRET_NAME = "workspace-private-registries";

private final UserSpecificDockerRegistryCredentialsProvider
userSpecificDockerRegistryCredentialsProvider;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

quite a long variable name =)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

is it a problem ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

tiny one. I don't like such long names 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I reduced its length :-D

.getBytes());
}

@SuppressWarnings("unchecked")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

BTW it's not good practice to use SuppressWarnings for the whole method.

return;
}

Gson gson = new Gson();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please explain why do you need to create it here instead of a single line where it is used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in other code changes.


Base64.Encoder encoder = Base64.getEncoder();

String config;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do you need a declaration of this variable here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not needed. Fixed.

Base64.Encoder encoder = Base64.getEncoder();

String config;
try (StringWriter strWriter = new StringWriter();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe private method could be enough

jsonWriter.value(encoder.encodeToString(auth.getBytes()));
jsonWriter.endObject();
} catch (IOException e) {
throw new RuntimeException(e);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please don't throw RuntimeException. InfrastructureException only is expected to be thrown by this method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Replacing the forEach with a for loop removed the need for a RuntimeException

Signed-off-by: David Festal <dfestal@redhat.com>
@davidfestal
Copy link
Copy Markdown
Contributor Author

@garagatyi @sleshchenko I mainly did the changes you requested. Is it OK for you OK now ?

@skabashnyuk The only remaining comment that I didn't fix is this one

@l0rd wdyt ? could be postpone this to a next PR ?

jsonWriter.value(encoder.encodeToString(auth.getBytes()));
jsonWriter.endObject();
} catch (IOException e) {
throw new InfrastructureException(e);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think that IOException message here won't be user-friendly. Can you wrap it with an introduction appropriate for a user?

jsonWriter.flush();
return strWriter.toString();
} catch (IOException e) {
throw new InfrastructureException(e);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think that IOException message here won't be user-friendly. Can you wrap it with an introduction appropriate for a user?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added a message to the wrapping exception.

Signed-off-by: David Festal <dfestal@redhat.com>
as requested by @skabashnyuk
[here](#9962 (review))

Signed-off-by: David Festal <dfestal@redhat.com>
Signed-off-by: David Festal <dfestal@redhat.com>
@davidfestal
Copy link
Copy Markdown
Contributor Author

ci-test

@codenvy-ci
Copy link
Copy Markdown

ci-test build report:
Build details
Test report
selenium tests report data
docker image: eclipseche/che-server:9962
https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

Copy link
Copy Markdown
Member

@sleshchenko sleshchenko left a comment

Choose a reason for hiding this comment

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

LGTM. Please take a look my inlined comments especially about DockerComposeEnvironmentConverter.

<packaging>jar</packaging>
<name>Infrastructure :: Docker :: Docker Auth</name>
<properties>
<findbugs.failonerror>false</findbugs.failonerror>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can it be removed?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It should be! Please, do not use this property unless you have strong arguments why we should use it!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This came from a copy/paste of the docker-client pom.xml file.
I just removed it.

* @author Anton Korneta
*/
@Singleton
public class DockerComposeEnvironmentConverter {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks exactly the same as DockerImageEnvironmentConverter but with another name. Please check these changes, I guess it should be reverted.

* @author Anton Korneta
*/
@Singleton
public class DockerComposeEnvironmentConverter {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This class seems to be unrelated to your PR. Can you elaborate why we need it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, it was added by mistake. I just removed it.

Signed-off-by: David Festal <dfestal@redhat.com>
Signed-off-by: David Festal <dfestal@redhat.com>
@davidfestal
Copy link
Copy Markdown
Contributor Author

ci-test

Copy link
Copy Markdown

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

LGTM

@codenvy-ci
Copy link
Copy Markdown

ci-test build report:
Build details
Test report
selenium tests report data
docker image: eclipseche/che-server:9962
https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

@davidfestal davidfestal merged commit 7c3d432 into master Jun 11, 2018
@benoitf benoitf added this to the 6.7.0 milestone Jun 11, 2018
@benoitf benoitf removed the status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. label Jun 11, 2018
davidfestal added a commit to redhat-developer/rh-che that referenced this pull request Jun 12, 2018
Adapt to changes made in upstream PR
eclipse-che/che#9962

Signed-off-by: David Festal <dfestal@redhat.com>
riuvshin pushed a commit that referenced this pull request Jun 13, 2018
* Support private docker registry in Che on Kubernetes / Openshift : related to issue redhat-developer/rh-che#680

* Extract the `AuthConfig` and related classes to a new module

Signed-off-by: David Festal <dfestal@redhat.com>
davidfestal added a commit to redhat-developer/rh-che that referenced this pull request Jun 13, 2018
* Support private docker registries in OSIO : adapt to changes made in upstream PR
eclipse-che/che#9962

* Now upgrade to the `6.6.1` bugfix release the contains required upstream changes

Signed-off-by: David Festal <dfestal@redhat.com>
@benoitf benoitf deleted the private-registries-support branch July 11, 2018 07:52
hbhargav pushed a commit to hbhargav/che that referenced this pull request Dec 5, 2018
* Support private docker registry in Che on Kubernetes / Openshift : related to issue redhat-developer/rh-che#680

* Extract the `AuthConfig` and related classes to a new module

Signed-off-by: David Festal <dfestal@redhat.com>
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.

8 participants