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

feat: Container network configuration support #3983

Conversation

GregoryIvo
Copy link
Contributor

@GregoryIvo GregoryIvo commented May 12, 2022

Allows the user to specify a network driver when creating a container.

From the docker API:
NetworkMode - Sets the networking mode for the container. Supported standard values are: bridge, host, none, and container:<name|id>. Any other value is taken as a custom network’s name to which this container should connect to.

TLDR: add support for NetworkMode Parameter.

image

image

* {@link ContainerNetworkConfiguration}.
*
* @return
* @since 2.7
Copy link
Contributor

Choose a reason for hiding this comment

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

The @since tag should be set to the version of the org.eclipse.kura.api bundle that introduces the new API, so I think it should be 2.4 here. Probably the tag should be changed also in other places (all of the new APIs that have been introduced since Kura 5.1.0 release).

@GregoryIvo
Copy link
Contributor Author

@nicolatimeus should I modify the meta-type UI? I feel like a dropdown is better suited, but you lose the ability to parameters like what is needed for the container mode.
Abe Suggested I use two input boxes: a list box with a Custom option and another text box used when the list box is set to custom. Seems like a good solution, but with only three enum types I don't know if it's worth it?
what are your thoughts?

@nicolatimeus
Copy link
Contributor

I think it can depend on which options are the most frequently used. If the enum variants in the list box are the most frequently used this will improve user experience and make things less error prone. If the custom one is the most frequently used this might clutter the ui with no additional benefits.

@nicolatimeus
Copy link
Contributor

Are the network types that would be put in the list box Docker-specific or standard (e.g. OCI) or supported also by other engines?


public static final class ContainerNetworkConfigurationBuilder {

private String networkMode = "bridge";
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 that using this default is ok, setting it might introduce a change in behavior since the previous version, which did not configure a network mode explicitly.
If we use it we must be sure that bridge is the default for this parameter for all container engines.

Otherwise we could use the empty string as a default value or maybe changing the type of ContainerNetworkConfiguration.networkMode to Optional<String>, update public APIs accordingly and keeping Optional.empty() as default.

A Optional.empty() value means that the implementation must not supply the network mode parameter to the container engine, relying on its defaults (the current behavior).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an excellent point. By default, containers do use the bridge configuration, but it probably makes more sense to leave it empty as per the default. Implementing these suggested changes.


public static final class ContainerNetworkConfigurationBuilder {

private String networkMode = "bridge";
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 that using this default is ok, setting it might introduce a change in behavior since the previous version, which did not configure a network mode explicitly.
If we use it we must be sure that bridge is the default for this parameter for all container engines.

Otherwise we could use the empty string as a default value or maybe changing the type of ContainerNetworkConfiguration.networkMode to Optional<String>, update public APIs accordingly and keeping Optional.empty() as default.

A Optional.empty() value means that the implementation must not supply the network mode parameter to the container engine, relying on its defaults (the current behavior).

@@ -101,6 +104,7 @@ public ContainerInstanceOptions(final Map<String, Object> properties) {
this.registryUsername = REGISTRY_USERNAME.getOptional(properties);
this.registryPassword = REGISTRY_PASSWORD.getOptional(properties);
this.imageDownloadTimeout = IMAGES_DOWNLOAD_TIMEOUT.get(properties);
this.containerNetworkingMode = CONTAINER_NETWORKING_MODE.get(properties);
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 can use Property.getOptional() 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.

Fancy, okay will give it a shot.

/**
*
* returns the network mode a container will be created with. supported modes
* include: 'bridge', 'none', 'container:', 'host'.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just: Returns the network mode a container will be created with (e.g. 'bridge', 'none', 'container:', 'host').

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion, changes made!

@nicolatimeus nicolatimeus merged commit 972cfd8 into eclipse-kura:develop May 17, 2022
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