Set CONTAINER_ENVIRONMENT_SETTINGS envirnment variable
Set environment variable in container (use json, so we can add stuff
as we go along, we probably need more data here). Set node type
so we can use that in entry point to have different behavior for
tenant nodes and config server nodes
// Copyright 2017 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.docker;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.yahoo.collections.Pair;
import com.yahoo.system.ProcessExecuter;
import com.yahoo.vespa.hosted.dockerapi.Container;
@@ -114,7 +117,8 @@ public class DockerOperationsImpl implements DockerOperations {
containerName,
nodeSpec.hostname)
.withManagedBy(MANAGER_NAME)
- .withEnvironment("CONFIG_SERVER_ADDRESS", configServers)
+ .withEnvironment("CONFIG_SERVER_ADDRESS", configServers) // TODO: Remove when all images support CONTAINER_ENVIRONMENT_SETTINGS
+ .withEnvironment("CONTAINER_ENVIRONMENT_SETTINGS", createContainerEnvironmentSettings(environment, nodeSpec))
.withUlimit("nofile", 262_144, 262_144)
.withUlimit("nproc", 32_768, 409_600)
.withUlimit("core", -1, -1)
@@ -340,4 +344,30 @@ public class DockerOperationsImpl implements DockerOperations {
public void deleteUnusedDockerImages() {
docker.deleteUnusedDockerImages();
}
+
+ private String createContainerEnvironmentSettings(Environment environment, ContainerNodeSpec nodeSpec) {
+ ObjectMapper objectMapper = new ObjectMapper();
+
+ String configServers = environment.getConfigServerUris().stream()
+ .map(URI::getHost)
+ .collect(Collectors.joining(","));
+ ContainerEnvironmentSettings settings = new ContainerEnvironmentSettings();
+ settings.set("configServerAddresses", configServers);
+ settings.set("nodeType", nodeSpec.nodeType);
+
+ try {
+ return objectMapper.writeValueAsString(settings);
+ } catch (JsonProcessingException e) {
+ throw new IllegalArgumentException("Could not write " + settings, e);
+ }
+ }
+
+ private class ContainerEnvironmentSettings {
+ @JsonProperty(value="environmentVariables")
+ private final Map<String, Object> variables = new HashMap<>();
+
+ void set(String argument, Object value) {
+ variables.put(argument, value);
+ }
+ }
}
