Skip to content

Commit eff92dd

Browse files
committed
Set ExternalAddress based on listener address
Signed-off-by: Nelo-T. Wallus <[email protected]>
1 parent 7814220 commit eff92dd

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pkg/server/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ type CompletedConfig struct {
155155
// Complete fills in any fields not set that are required to have valid data. It's mutating the receiver.
156156
func (c *Config) Complete() (CompletedConfig, error) {
157157
miniAggregator := c.MiniAggregator.Complete()
158+
158159
return CompletedConfig{&completedConfig{
159160
Options: c.Options,
160161

pkg/server/options/options.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,22 @@ func (o *Options) Complete(ctx context.Context, rootDir string) (*CompletedOptio
287287
}
288288
}
289289

290+
// ExternalAddress is the address used e.g. when generating
291+
// kubeconfigs. It defaults to the default interface, usually the
292+
// first non-loopback interface, e.g. 192.168.0.1.
293+
// BindAddress is the address the server binds to, it defaults to
294+
// 0.0.0.0 or ::.
295+
//
296+
// If BindAddress is set to a specific address, e.g. the loopback
297+
// 127.0.0.1 the ExternalAddress is invalid and all URLs generated
298+
// from it will not work.
299+
//
300+
// To prevent this ExternalAddress is set to the value of
301+
// BindAddress if it wasn't set to a specific address.
302+
if o.GenericControlPlane.GenericServerRunOptions.ExternalHost == "" && !o.GenericControlPlane.SecureServing.BindAddress.IsUnspecified() {
303+
o.GenericControlPlane.GenericServerRunOptions.ExternalHost = o.GenericControlPlane.SecureServing.BindAddress.String()
304+
}
305+
290306
if o.Extra.ExperimentalBindFreePort {
291307
listener, _, err := genericapiserveroptions.CreateListener("tcp", fmt.Sprintf("%s:0", o.GenericControlPlane.SecureServing.BindAddress), net.ListenConfig{})
292308
if err != nil {

0 commit comments

Comments
 (0)