-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Support for using both an external control plane and automatic webhooks together #1265
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,9 @@ type WebhookInstallOptions struct { | |
// CAData is the CA that can be used to trust the serving certificates in LocalServingCertDir. | ||
LocalServingCAData []byte | ||
|
||
// LocalServingHostExternalName is the hostname to use to reach the webhook server. | ||
LocalServingHostExternalName string | ||
|
||
// MaxTime is the max time to wait | ||
MaxTime time.Duration | ||
|
||
|
@@ -137,13 +140,19 @@ func modifyWebhook(webhook map[string]interface{}, caData []byte, hostPort strin | |
} | ||
|
||
func (o *WebhookInstallOptions) generateHostPort() (string, error) { | ||
port, host, err := addr.Suggest() | ||
if err != nil { | ||
return "", fmt.Errorf("unable to grab random port for serving webhooks on: %v", err) | ||
if o.LocalServingPort == 0 { | ||
port, host, err := addr.Suggest(o.LocalServingHost) | ||
if err != nil { | ||
return "", fmt.Errorf("unable to grab random port for serving webhooks on: %v", err) | ||
} | ||
o.LocalServingPort = port | ||
o.LocalServingHost = host | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about reusing this field instead? It would be generated IF not provided. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean re: adding the new struct field? LocalServingHost has to be a name or IP for the webhook server bind to, in most cases I would expect it to be set to |
||
} | ||
host := o.LocalServingHostExternalName | ||
if host == "" { | ||
host = o.LocalServingHost | ||
} | ||
o.LocalServingPort = port | ||
o.LocalServingHost = host | ||
return net.JoinHostPort(host, fmt.Sprintf("%d", port)), nil | ||
return net.JoinHostPort(host, fmt.Sprintf("%d", o.LocalServingPort)), nil | ||
} | ||
|
||
// PrepWithoutInstalling does the setup parts of Install (populating host-port, | ||
|
@@ -266,7 +275,8 @@ func (o *WebhookInstallOptions) setupCA() ([]byte, error) { | |
return nil, fmt.Errorf("unable to set up webhook CA: %v", err) | ||
} | ||
|
||
hookCert, err := hookCA.NewServingCert() | ||
names := []string{"localhost", o.LocalServingHost, o.LocalServingHostExternalName} | ||
hookCert, err := hookCA.NewServingCert(names...) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to set up webhook serving certs: %v", err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any case where it is sensible to have the port be 0 and use and external name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like to actually set it to 0 in the OS? I don't think so, the reason for this check is the reverse, allowing passing in a fixed port if you are willing to take ownership of any collisions (ex. running just one suite in a CI job) while leaving the default still be "pick me a random port" like the OS would do, but without reuse collisions.