| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -73,6 +73,9 @@ public static HostConfig newHostConfig() { | |||
| 73 | 73 | @JsonProperty("NanoCpus") | |
| 74 | 74 | private Long nanoCPUs; | |
| 75 | 75 | ||
| 76 | + @JsonProperty("Annotations") | ||
| 77 | + private Map<String, String> annotations; | ||
| 78 | + | ||
| 76 | 79 | @JsonProperty("CapAdd") | |
| 77 | 80 | private Capability[] capAdd; | |
| 78 | 81 | ||
@@ -304,6 +307,11 @@ public Integer getBlkioWeight() { | |||
| 304 | 307 | return blkioWeight; | |
| 305 | 308 | } | |
| 306 | 309 | ||
| 310 | + @CheckForNull | ||
| 311 | + public Map<String, String> getAnnotations() { | ||
| 312 | + return annotations; | ||
| 313 | + } | ||
| 314 | + | ||
| 307 | 315 | public Capability[] getCapAdd() { | |
| 308 | 316 | return capAdd; | |
| 309 | 317 | } | |
@@ -636,6 +644,11 @@ public HostConfig withBlkioWeightDevice(List<BlkioWeightDevice> blkioWeightDevic | |||
| 636 | 644 | return this; | |
| 637 | 645 | } | |
| 638 | 646 | ||
| 647 | + public HostConfig withAnnotations(Map<String, String> annotations) { | ||
| 648 | + this.annotations = annotations; | ||
| 649 | + return this; | ||
| 650 | + } | ||
| 651 | + | ||
| 639 | 652 | /** | |
| 640 | 653 | * @see #capAdd | |
| 641 | 654 | */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,8 @@ | |||
| 10 | 10 | import com.github.dockerjava.api.command.InspectContainerResponse; | |
| 11 | 11 | import com.github.dockerjava.api.exception.ConflictException; | |
| 12 | 12 | import com.github.dockerjava.api.exception.DockerException; | |
| 13 | + import com.github.dockerjava.api.DockerClient; | ||
| 14 | + import com.github.dockerjava.core.DefaultDockerClientConfig; | ||
| 13 | 15 | import com.github.dockerjava.api.exception.InternalServerErrorException; | |
| 14 | 16 | import com.github.dockerjava.api.exception.NotFoundException; | |
| 15 | 17 | import com.github.dockerjava.api.model.AuthConfig; | |
@@ -58,6 +60,7 @@ | |||
| 58 | 60 | import static com.github.dockerjava.api.model.HostConfig.newHostConfig; | |
| 59 | 61 | import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_23; | |
| 60 | 62 | import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_24; | |
| 63 | + import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_43; | ||
| 61 | 64 | import static com.github.dockerjava.junit.DockerMatchers.isGreaterOrEqual; | |
| 62 | 65 | import static com.github.dockerjava.junit.DockerMatchers.mountedVolumes; | |
| 63 | 66 | import static com.github.dockerjava.core.DockerRule.DEFAULT_IMAGE; | |
@@ -1141,4 +1144,33 @@ public void shouldHandleANetworkAliasWithoutACustomNetworkGracefully() { | |||
| 1141 | 1144 | .withCmd("sleep", "9999") | |
| 1142 | 1145 | .exec(); | |
| 1143 | 1146 | } | |
| 1147 | + | ||
| 1148 | + @Test | ||
| 1149 | + public void createContainerWithAnnotations() throws DockerException { | ||
| 1150 | + DefaultDockerClientConfig forcedConfig = DefaultDockerClientConfig.createDefaultConfigBuilder() | ||
| 1151 | + .withApiVersion(VERSION_1_43) | ||
| 1152 | + .withRegistryUrl("https://index.docker.io/v1/") | ||
| 1153 | + .build(); | ||
| 1154 | + | ||
| 1155 | + DockerClient forcedClient = CmdIT.createDockerClient(forcedConfig); | ||
| 1156 | + Map<String, String> annotations = new HashMap<>(); | ||
| 1157 | + annotations.put("com.example.key1", "value1"); | ||
| 1158 | + annotations.put("com.example.key2", "value2"); | ||
| 1159 | + | ||
| 1160 | + CreateContainerResponse container = forcedClient.createContainerCmd(DEFAULT_IMAGE) | ||
| 1161 | + .withCmd("sleep", "9999") | ||
| 1162 | + .withHostConfig(newHostConfig() | ||
| 1163 | + .withAnnotations(annotations)) | ||
| 1164 | + .exec(); | ||
| 1165 | + | ||
| 1166 | + LOG.info("Created container {}", container.toString()); | ||
| 1167 | + | ||
| 1168 | + assertThat(container.getId(), not(is(emptyString()))); | ||
| 1169 | + | ||
| 1170 | + InspectContainerResponse inspectContainerResponse = forcedClient.inspectContainerCmd(container.getId()).exec(); | ||
| 1171 | + | ||
| 1172 | + assertThat(inspectContainerResponse.getHostConfig().getAnnotations(), equalTo(annotations)); | ||
| 1173 | + assertThat(inspectContainerResponse.getHostConfig().getAnnotations().get("com.example.key1"), equalTo("value1")); | ||
| 1174 | + assertThat(inspectContainerResponse.getHostConfig().getAnnotations().get("com.example.key2"), equalTo("value2")); | ||
| 1175 | + } | ||
| 1144 | 1176 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments