summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorValerij Fredriksen <freva@users.noreply.github.com>2018-11-16 16:40:33 +0100
committerGitHub <noreply@github.com>2018-11-16 16:40:33 +0100
commite71b311a5a54be38ff4538edfe53b7b46a974c8b (patch)
treed8c5b017f0f940c55dd09914cdb978cc30b21536
parent2ae6038eae0b7f9af5dcdb28a0813d0ccbd8a44b (diff)
parent5b8fb908a043b15d8f8039e7517cd2c7521cda2b (diff)
Merge pull request #7683 from vespa-engine/freva/set-container-env
Revert "Remove ContainerEnvironmentResolver"
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/ContainerEnvironmentResolver.java44
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java5
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImplTest.java4
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerTester.java2
4 files changed, 53 insertions, 2 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/ContainerEnvironmentResolver.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/ContainerEnvironmentResolver.java
new file mode 100644
index 00000000000..f1218efa67c
--- /dev/null
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/ContainerEnvironmentResolver.java
@@ -0,0 +1,44 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.hosted.node.admin.component;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.yahoo.vespa.hosted.node.admin.configserver.noderepository.NodeSpec;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * For creating environment variables that should be available inside a Docker container.
+ * An environment variable CONTAINER_ENVIRONMENT_SETTINGS with the settings here will be
+ * available inside the container. Serializing happens in ContainerEnvironmentSetting in this interface.
+ *
+ * @author hmusum
+ */
+@FunctionalInterface
+public interface ContainerEnvironmentResolver {
+
+ String createSettings(NodeSpec node);
+
+ class ContainerEnvironmentSettings {
+
+ @JsonProperty(value = "environmentVariables")
+ private final Map<String, Object> variables = new HashMap<>();
+
+ public ContainerEnvironmentSettings set(String argument, Object value) {
+ variables.put(argument, value);
+ return this;
+ }
+
+ public String build() {
+ ObjectMapper objectMapper = new ObjectMapper();
+ try {
+ return objectMapper.writeValueAsString(this);
+ } catch (JsonProcessingException e) {
+ throw new IllegalArgumentException("Could not write " + this, e);
+ }
+ }
+ }
+
+}
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java
index cf5937579db..26d162fd1a0 100644
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java
@@ -12,6 +12,7 @@ import com.yahoo.vespa.hosted.dockerapi.ContainerStats;
import com.yahoo.vespa.hosted.dockerapi.Docker;
import com.yahoo.vespa.hosted.dockerapi.DockerImage;
import com.yahoo.vespa.hosted.dockerapi.ProcessResult;
+import com.yahoo.vespa.hosted.node.admin.component.ContainerEnvironmentResolver;
import com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgentContext;
import com.yahoo.vespa.hosted.node.admin.configserver.noderepository.NodeSpec;
import com.yahoo.vespa.hosted.node.admin.nodeagent.ContainerData;
@@ -46,13 +47,16 @@ public class DockerOperationsImpl implements DockerOperations {
private final Docker docker;
private final ProcessExecuter processExecuter;
+ private final ContainerEnvironmentResolver containerEnvironmentResolver;
private final List<String> configServerHostnames;
private final IPAddresses ipAddresses;
public DockerOperationsImpl(Docker docker, ProcessExecuter processExecuter,
+ ContainerEnvironmentResolver containerEnvironmentResolver,
List<String> configServerHostnames, IPAddresses ipAddresses) {
this.docker = docker;
this.processExecuter = processExecuter;
+ this.containerEnvironmentResolver = containerEnvironmentResolver;
this.configServerHostnames = configServerHostnames;
this.ipAddresses = ipAddresses;
}
@@ -75,6 +79,7 @@ public class DockerOperationsImpl implements DockerOperations {
node.getHostname())
.withManagedBy(MANAGER_NAME)
.withEnvironment("VESPA_CONFIGSERVERS", configServers)
+ .withEnvironment("CONTAINER_ENVIRONMENT_SETTINGS", containerEnvironmentResolver.createSettings(node))
.withUlimit("nofile", 262_144, 262_144)
// The nproc aka RLIMIT_NPROC resource limit works as follows:
// - A process has a (soft) nproc limit, either inherited by the parent or changed with setrlimit(2).
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImplTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImplTest.java
index d93d33617e3..6e8cfce6c37 100644
--- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImplTest.java
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImplTest.java
@@ -9,6 +9,7 @@ import com.yahoo.vespa.hosted.dockerapi.ContainerName;
import com.yahoo.vespa.hosted.dockerapi.Docker;
import com.yahoo.vespa.hosted.dockerapi.DockerImage;
import com.yahoo.vespa.hosted.dockerapi.ProcessResult;
+import com.yahoo.vespa.hosted.node.admin.component.ContainerEnvironmentResolver;
import com.yahoo.vespa.hosted.node.admin.nodeagent.ContainerData;
import com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgentContext;
import com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgentContextImpl;
@@ -38,9 +39,10 @@ import static org.mockito.Mockito.when;
public class DockerOperationsImplTest {
private final Docker docker = mock(Docker.class);
private final ProcessExecuter processExecuter = mock(ProcessExecuter.class);
+ private final ContainerEnvironmentResolver containerEnvironmentResolver = node -> "";
private final IPAddresses ipAddresses = new IPAddressesMock();
private final DockerOperationsImpl dockerOperations = new DockerOperationsImpl(
- docker, processExecuter, Collections.emptyList(), ipAddresses);
+ docker, processExecuter, containerEnvironmentResolver, Collections.emptyList(), ipAddresses);
@Test
public void processResultFromNodeProgramWhenSuccess() {
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerTester.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerTester.java
index 9385e604142..e22606104f1 100644
--- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerTester.java
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerTester.java
@@ -90,7 +90,7 @@ public class DockerTester implements AutoCloseable {
Clock clock = Clock.systemUTC();
FileSystem fileSystem = TestFileSystem.create();
- DockerOperations dockerOperations = new DockerOperationsImpl(docker, processExecuter, Collections.emptyList(), ipAddresses);
+ DockerOperations dockerOperations = new DockerOperationsImpl(docker, processExecuter, node -> "", Collections.emptyList(), ipAddresses);
MetricReceiverWrapper mr = new MetricReceiverWrapper(MetricReceiver.nullImplementation);
Function<String, NodeAgent> nodeAgentFactory = (hostName) -> new NodeAgentImpl(