Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if the docker config is nil, fixes #13371 #13373

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions plugins/providers/docker/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ def network_defined?(subnet_string)

network_info = inspect_network(all_networks)
network_info.each do |network|
config = Array(network["IPAM"]["Config"])
if (config.size > 0 &&
config.first["Subnet"] == subnet_string)
config = Array(network.dig("IPAM", "Config"))
next if config.empty? || !config.first.is_a?(Hash)
if (config.first["Subnet"] == subnet_string)
@logger.debug("Found existing network #{network["Name"]} already configured with #{subnet_string}")
return network["Name"]
end
Expand Down
44 changes: 44 additions & 0 deletions test/unit/plugins/providers/docker/driver_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,50 @@
expect { subject.network_defined?(subnet_string) }.not_to raise_error
end
end

context "when IPAM information is missing" do
let(:docker_network_struct) do
[
{
"Name": "bridge",
"Id": "ae74f6cc18bbcde86326937797070b814cc71bfc4a6d8e3e8cf3b2cc5c7f4a7d",
"Created": "2019-03-20T14:10:06.313314662-07:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"a1ee9b12bcea8268495b1f43e8d1285df1925b7174a695075f6140adb9415d87": {
"Name": "vagrant-sandbox_docker-1_1553116237",
"EndpointID": "fc1b0ed6e4f700cf88bb26a98a0722655191542e90df3e3492461f4d1f3c0cae",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": ""
},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
},
}
].to_json
end

it "should not raise an error" do
expect { subject.network_defined?(subnet_string) }.not_to raise_error
end
end
end

describe '#network_containing_address' do
Expand Down