Skip to content

Commit c57137b

Browse files
committed
Pass BindAddress to GenericControlPlane.Complete as alternateDNS and IP
Signed-off-by: Nelo-T. Wallus <[email protected]>
1 parent 5a2508c commit c57137b

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

pkg/server/options/options.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,34 @@ func (o *Options) Complete(ctx context.Context, rootDir string) (*CompletedOptio
327327
o.GenericControlPlane.ServiceAccountSigningKeyFile = o.Controllers.SAController.ServiceAccountKeyFile
328328
}
329329

330-
completedGenericOptions, err := o.GenericControlPlane.Complete(ctx, nil, nil)
330+
// o.GenericControlPlane.Complete creates self-signed certificates
331+
// with the advertise address by default. This can cause spurious
332+
// errors if the server binds on multiple interfaces.
333+
possibleIPs := []net.IP{
334+
o.GenericControlPlane.GenericServerRunOptions.AdvertiseAddress,
335+
o.GenericControlPlane.SecureServing.BindAddress,
336+
o.GenericControlPlane.SecureServing.ExternalAddress,
337+
}
338+
if o.GenericControlPlane.SecureServing.Listener != nil {
339+
host, _, err := net.SplitHostPort(o.GenericControlPlane.SecureServing.Listener.Addr().String())
340+
if err != nil {
341+
return nil, err
342+
}
343+
possibleIPs = append(possibleIPs, net.ParseIP(host))
344+
}
345+
346+
alternateIPs := []net.IP{}
347+
alternateDNS := []string{}
348+
349+
for _, ip := range possibleIPs {
350+
if ip == nil || ip.IsUnspecified() {
351+
continue
352+
}
353+
alternateIPs = append(alternateIPs, ip)
354+
alternateDNS = append(alternateDNS, ip.String())
355+
}
356+
357+
completedGenericOptions, err := o.GenericControlPlane.Complete(ctx, alternateDNS, alternateIPs)
331358
if err != nil {
332359
return nil, err
333360
}

0 commit comments

Comments
 (0)