Skip to content

Commit 3de85fd

Browse files
committed
Ref #34029: support default-container-network in swarm
1 parent 2a3bd1f commit 3de85fd

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

src/main/java/eu/openanalytics/containerproxy/backend/docker/AbstractDockerBackend.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ public abstract class AbstractDockerBackend extends AbstractContainerBackend {
5858
protected static final String PROPERTY_PORT_RANGE_MAX = "port-range-max";
5959
protected static final String PROPERTY_TARGET_URL = "target-url";
6060
protected static final String DEFAULT_TARGET_URL = DEFAULT_TARGET_PROTOCOL + "://localhost";
61+
protected static final String PROPERTY_CONTAINER_NETWORK = "default-container-network";
6162
private static final String PROPERTY_PREFIX = "proxy.docker.";
6263
@Inject
6364
protected IPortAllocator portAllocator;
6465
protected DockerClient dockerClient;
6566

67+
protected String containerNetwork;
6668
protected Integer portRangeFrom;
6769
protected Integer portRangeTo;
6870
protected String nonInternalNetworkTargetProtocol;
@@ -100,6 +102,7 @@ public void initialize() throws ContainerProxyException {
100102
}
101103

102104
dockerClient = builder.build();
105+
containerNetwork = environment.getProperty(getPropertyPrefix() + PROPERTY_CONTAINER_NETWORK);
103106
portRangeFrom = environment.getProperty(getPropertyPrefix() + PROPERTY_PORT_RANGE_START, Integer.class, 20000);
104107
portRangeTo = environment.getProperty(getPropertyPrefix() + PROPERTY_PORT_RANGE_MAX, Integer.class, -1);
105108

src/main/java/eu/openanalytics/containerproxy/backend/docker/DockerEngineBackend.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,18 @@
7575
public class DockerEngineBackend extends AbstractDockerBackend {
7676

7777
private static final String PROPERTY_IMG_PULL_POLICY = "image-pull-policy";
78-
private static final String PROPERTY_CONTAINER_NETWORK = "default-container-network";
7978
private static final String PROPERTY_LOKI_URL = "loki-url";
8079
private static final String PROPERTY_TARGET_BIND_IP = "target-bind-ip";
8180
private static final String DEFAULT_TARGET_BIND_IP = "127.0.0.1";
8281

8382
private ImagePullPolicy imagePullPolicy;
84-
private String containerNetwork;
8583
private String lokiUrl;
8684
private String nonInternalTargetBindIp;
8785

8886
@PostConstruct
8987
public void initialize() {
9088
super.initialize();
9189
imagePullPolicy = environment.getProperty(getPropertyPrefix() + PROPERTY_IMG_PULL_POLICY, ImagePullPolicy.class, ImagePullPolicy.IfNotPresent);
92-
containerNetwork = environment.getProperty(getPropertyPrefix() + PROPERTY_CONTAINER_NETWORK);
9390
lokiUrl = environment.getProperty(getPropertyPrefix() + PROPERTY_LOKI_URL);
9491
nonInternalTargetBindIp = environment.getProperty(getPropertyPrefix() + PROPERTY_TARGET_BIND_IP, DEFAULT_TARGET_BIND_IP);
9592
}

src/main/java/eu/openanalytics/containerproxy/backend/docker/DockerSwarmBackend.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ public Proxy startContainer(Authentication user, Container initialContainer, Con
143143

144144
if (spec.getNetwork().isPresent()) {
145145
networks.add(NetworkAttachmentConfig.builder().target(spec.getNetwork().getValue()).build());
146+
} else if (containerNetwork != null) {
147+
networks.add(NetworkAttachmentConfig.builder().target(containerNetwork).build());
146148
}
147149

148150
Reservations.Builder reservationsBuilder = Reservations.builder();

0 commit comments

Comments
 (0)