FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Annotations option added to hostconfig by emirhandurmus · Pull Request #2422 · docker-java/docker-java · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public static HostConfig newHostConfig() {
@JsonProperty("NanoCpus")
private Long nanoCPUs;

@JsonProperty("Annotations")
private Map<String, String> annotations;

@JsonProperty("CapAdd")
private Capability[] capAdd;

Expand Down Expand Up @@ -304,6 +307,11 @@ public Integer getBlkioWeight() {
return blkioWeight;
}

@CheckForNull
public Map<String, String> getAnnotations() {
return annotations;
}

public Capability[] getCapAdd() {
return capAdd;
}
Expand Down Expand Up @@ -636,6 +644,11 @@ public HostConfig withBlkioWeightDevice(List<BlkioWeightDevice> blkioWeightDevic
return this;
}

public HostConfig withAnnotations(Map<String, String> annotations) {
this.annotations = annotations;
return this;
}

/**
* @see #capAdd
*/
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.github.dockerjava.api.command.InspectContainerResponse;
import com.github.dockerjava.api.exception.ConflictException;
import com.github.dockerjava.api.exception.DockerException;
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.core.DefaultDockerClientConfig;
import com.github.dockerjava.api.exception.InternalServerErrorException;
import com.github.dockerjava.api.exception.NotFoundException;
import com.github.dockerjava.api.model.AuthConfig;
Expand Down Expand Up @@ -58,6 +60,7 @@
import static com.github.dockerjava.api.model.HostConfig.newHostConfig;
import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_23;
import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_24;
import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_43;
import static com.github.dockerjava.junit.DockerMatchers.isGreaterOrEqual;
import static com.github.dockerjava.junit.DockerMatchers.mountedVolumes;
import static com.github.dockerjava.core.DockerRule.DEFAULT_IMAGE;
Expand Down Expand Up @@ -1141,4 +1144,33 @@ public void shouldHandleANetworkAliasWithoutACustomNetworkGracefully() {
.withCmd("sleep", "9999")
.exec();
}

@Test
public void createContainerWithAnnotations() throws DockerException {
DefaultDockerClientConfig forcedConfig = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withApiVersion(VERSION_1_43)
.withRegistryUrl("https://index.docker.io/v1/")
.build();

DockerClient forcedClient = CmdIT.createDockerClient(forcedConfig);
Map<String, String> annotations = new HashMap<>();
annotations.put("com.example.key1", "value1");
annotations.put("com.example.key2", "value2");

CreateContainerResponse container = forcedClient.createContainerCmd(DEFAULT_IMAGE)
.withCmd("sleep", "9999")
.withHostConfig(newHostConfig()
.withAnnotations(annotations))
.exec();

LOG.info("Created container {}", container.toString());

assertThat(container.getId(), not(is(emptyString())));

InspectContainerResponse inspectContainerResponse = forcedClient.inspectContainerCmd(container.getId()).exec();

assertThat(inspectContainerResponse.getHostConfig().getAnnotations(), equalTo(annotations));
assertThat(inspectContainerResponse.getHostConfig().getAnnotations().get("com.example.key1"), equalTo("value1"));
assertThat(inspectContainerResponse.getHostConfig().getAnnotations().get("com.example.key2"), equalTo("value2"));
}
}

Back | FazBrowse Home | New Git URL