@@ -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"
@@ -303,10 +306,41 @@ func (c *ClusterAPI) Generate(dependencies asset.Parents) error {
303306 mpool .Set (pool .Platform .VSphere )
304307
305308 platform := ic .VSphere
309+ resolver := & net.Resolver {
310+ PreferGo : true ,
311+ }
306312
307313 for _ , v := range platform .VCenters {
308- err := installConfig .VSphere .Networks (ctx , v , platform .FailureDomains )
314+ // Defense against potential issues with assisted installer
315+ // If the installer is unable to resolve vCenter there is a good possibility
316+ // that the installer's install-config has been provided with bogus values.
317+
318+ // Timeout context for Lookup
319+ ctx , cancel := context .WithTimeout (context .TODO (), 30 * time .Second )
320+ defer cancel ()
321+
322+ _ , err := resolver .LookupHost (ctx , v .Server )
323+ if err != nil {
324+ logrus .Warnf ("unable to resolve vSphere server %s" , v .Server )
325+ return nil
326+ }
327+
328+ // Timeout context for Networks
329+ // vCenter APIs can be unreliable in performance, extended this context
330+ // timeout to 60 seconds.
331+ ctx , cancel = context .WithTimeout (context .TODO (), 60 * time .Second )
332+ defer cancel ()
333+
334+ err = installConfig .VSphere .Networks (ctx , v , platform .FailureDomains )
309335 if err != nil {
336+ // If we are receiving an error as a Soap Fault this is caused by
337+ // incorrect credentials and in the scenario of assisted installer
338+ // the credentials are never valid. Since vCenter hostname is
339+ // incorrect as well we shouldn't get this far.
340+ if soap .IsSoapFault (err ) {
341+ logrus .Warn ("authentication failure to vCenter, Cluster API machine manifests not created, cluster may not install" )
342+ return nil
343+ }
310344 return err
311345 }
312346 }
0 commit comments