diff --git a/pkg/ibm/ibmz_helpers.go b/pkg/ibm/ibmz_helpers.go index 8f6dee5b0..ed2822ab1 100644 --- a/pkg/ibm/ibmz_helpers.go +++ b/pkg/ibm/ibmz_helpers.go @@ -82,6 +82,7 @@ func checkIfIpIsLive(ctx context.Context, ip string) error { server, err := net.ResolveTCPAddr("tcp", ip+":22") if err != nil { log.Error(err, "failed to resolve ip address") + return err } conn, err := net.DialTimeout(server.Network(), server.String(), 5*time.Second) if err != nil { diff --git a/pkg/ibm/ibmz_helpers_test.go b/pkg/ibm/ibmz_helpers_test.go index c7d73d747..0cf43f636 100644 --- a/pkg/ibm/ibmz_helpers_test.go +++ b/pkg/ibm/ibmz_helpers_test.go @@ -1,6 +1,7 @@ package ibm import ( + "context" "fmt" "regexp" @@ -101,4 +102,17 @@ var _ = Describe("IBM s390x Helper Functions", func() { "System Z Max Tag Length"), ) }) + + Describe("The checkIfIpIsLive function", func() { + When("the DNS resolution of the host fails", func() { + It("should return an error instead of panicking", func() { + ctx := context.Background() + // "a b c" contains spaces, which are invalid in DNS names + // — this causes net.ResolveTCPAddr to fail immediately + // (0ms, pure local resolution) without any network call. + err := checkIfIpIsLive(ctx, "a b c") + Expect(err).Should(HaveOccurred()) + }) + }) + }) })