@@ -3,11 +3,14 @@ package machines
33import (
44 "context"
55 "fmt"
6+ "net"
67 "path/filepath"
78 "strings"
9+ "time"
810
911 "github.com/pkg/errors"
1012 "github.com/sirupsen/logrus"
13+ "github.com/vmware/govmomi/vim25/soap"
1114 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1215 "k8s.io/utils/ptr"
1316 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -301,10 +304,41 @@ func (c *ClusterAPI) Generate(dependencies asset.Parents) error {
301304 mpool .Set (pool .Platform .VSphere )
302305
303306 platform := ic .VSphere
307+ resolver := & net.Resolver {
308+ PreferGo : true ,
309+ }
304310
305311 for _ , v := range platform .VCenters {
306- err := installConfig .VSphere .Networks (ctx , v , platform .FailureDomains )
312+ // Defense against potential issues with assisted installer
313+ // If the installer is unable to resolve vCenter there is a good possibility
314+ // that the installer's install-config has been provided with bogus values.
315+
316+ // Timeout context for Lookup
317+ ctx , cancel := context .WithTimeout (context .TODO (), 30 * time .Second )
318+ defer cancel ()
319+
320+ _ , err := resolver .LookupHost (ctx , v .Server )
321+ if err != nil {
322+ logrus .Warnf ("unable to resolve vSphere server %s" , v .Server )
323+ return nil
324+ }
325+
326+ // Timeout context for Networks
327+ // vCenter APIs can be unreliable in performance, extended this context
328+ // timeout to 60 seconds.
329+ ctx , cancel = context .WithTimeout (context .TODO (), 60 * time .Second )
330+ defer cancel ()
331+
332+ err = installConfig .VSphere .Networks (ctx , v , platform .FailureDomains )
307333 if err != nil {
334+ // If we are receiving an error as a Soap Fault this is caused by
335+ // incorrect credentials and in the scenario of assisted installer
336+ // the credentials are never valid. Since vCenter hostname is
337+ // incorrect as well we shouldn't get this far.
338+ if soap .IsSoapFault (err ) {
339+ logrus .Warn ("authentication failure to vCenter, Cluster API machine manifests not created, cluster may not install" )
340+ return nil
341+ }
308342 return err
309343 }
310344 }
0 commit comments