From 70f9613dab67cd7ca347cb1a642cf67e17d66961 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Tue, 23 Jun 2020 17:52:14 +0200 Subject: [PATCH] Trying to fix defensively a panic @nebuk89 encountered on ACI, but could not reproduce it. --- azure/convert/ports.go | 2 +- azure/convert/ports_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/azure/convert/ports.go b/azure/convert/ports.go index b6fd12d3b..6c0f70906 100644 --- a/azure/convert/ports.go +++ b/azure/convert/ports.go @@ -37,7 +37,7 @@ func ToPorts(ipAddr *containerinstance.IPAddress, ports []containerinstance.Cont protocol = string(port.Protocol) } ip := "" - if ipAddr != nil { + if ipAddr != nil && ipAddr.IP != nil { ip = *ipAddr.IP } diff --git a/azure/convert/ports_test.go b/azure/convert/ports_test.go index cce29d302..78af6ed6d 100644 --- a/azure/convert/ports_test.go +++ b/azure/convert/ports_test.go @@ -72,6 +72,26 @@ func TestPortConvert(t *testing.T) { }, }, }, + { + name: "with nil ip value", + ip: &containerinstance.IPAddress{ + IP: nil, + }, + ports: []containerinstance.ContainerPort{ + { + Protocol: "tcp", + Port: to.Int32Ptr(80), + }, + }, + expected: []containers.Port{ + { + HostPort: 80, + ContainerPort: 80, + HostIP: "", + Protocol: "tcp", + }, + }, + }, { name: "skip nil ports", ip: nil,