Skip to content

Commit

Permalink
Bugfix: Treating npe at networks mapping when network hasn't a gatewa…
Browse files Browse the repository at this point in the history
…y ip #580 (#592)

* treating npe at network without gateway ip mapping

* release notes

* [Gradle Release Plugin] - new version commit:  '3.30.5-snapshot'.
  • Loading branch information
mageddo authored Oct 31, 2024
1 parent 97f2824 commit ff5a0c8
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
3 changes: 3 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.30.5
* Bugfix: Treating npe at networks mapping when network hasn't a gateway ip #580.

## 3.30.4
* Adjusting binary generation to compatibility. #586

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=3.30.4-snapshot
version=3.30.5-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static IP findGatewayIp(com.github.dockerjava.api.model.Network network, IP.Vers
.getConfig()
.stream()
.map(com.github.dockerjava.api.model.Network.Ipam.Config::getGateway)
.filter(Objects::nonNull)
.map(NetworkMapper::extractIpIfNeedledWhenGatewayIsSubnet)
.map(IP::of)
.filter(it -> it.version() == version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,18 @@ void mustExtractIpWhenASubnetIsSetAtIpv6TheGatewayIp(){
assertEquals("[172.19.0.1, fddb:21e4:36d4:2:0:0:0:1]", network.getGateways().toString());
}

@Test
void mustMapFromCustomNetworkWithoutGateway(){

// arrange
final var dockerNetwork = NetworkTemplates.buildCustomIpv4NetworkWithoutGateway();

// act
final var network = NetworkMapper.of(dockerNetwork);

// assert
assertNotNull(network);
assertFalse(network.hasAnyGateway());
}

}
4 changes: 4 additions & 0 deletions src/test/java/testing/templates/docker/NetworkTemplates.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ public static Network buildHostNetworkWithNoIpam() {
public static Network buildBridgeWithSubnetIPAtGatewayProp() {
return JsonUtils.readValue(readString("/templates/docker/network/004.json"), Network.class);
}

public static Network buildCustomIpv4NetworkWithoutGateway() {
return JsonUtils.readValue(readString("/templates/docker/network/005.json"), Network.class);
}
}
39 changes: 39 additions & 0 deletions src/test/resources/templates/docker/network/005.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"Name": "tmp_my_network",
"Id": "4832d0e4bb48513ee3fde20aaecfaf6b8ac83476d4365f82fae4001517b20cce",
"Created": "2024-10-31T14:47:27.608173734-03:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "171.18.0.0/16"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"2343a2ab9f8f1898674f349e21316593f31fce539b2b804d7e97cc16d3bf8a3b": {
"Name": "tmp-dns-proxy-1",
"EndpointID": "a809c879ba3dc31d0c387f47eb4f817745534bcf4cf7385a9916832452db4bae",
"MacAddress": "02:42:ab:12:00:0a",
"IPv4Address": "171.18.0.10/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "my_network",
"com.docker.compose.project": "tmp",
"com.docker.compose.version": "2.26.1"
}
}

0 comments on commit ff5a0c8

Please sign in to comment.