Skip to content

Commit f46cfa5

Browse files
committed
Adjust to webhook.Server changes
Signed-off-by: Stefan Büringer [email protected]
1 parent fd538aa commit f46cfa5

File tree

7 files changed

+52
-40
lines changed

7 files changed

+52
-40
lines changed

bootstrap/kubeadm/main.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,13 @@ func main() {
202202
},
203203
},
204204
},
205-
WebhookServer: &webhook.Server{
206-
Port: webhookPort,
207-
CertDir: webhookCertDir,
208-
TLSOpts: tlsOptionOverrides,
209-
},
205+
WebhookServer: webhook.NewServer(
206+
webhook.Options{
207+
Port: webhookPort,
208+
CertDir: webhookCertDir,
209+
TLSOpts: tlsOptionOverrides,
210+
},
211+
),
210212
}
211213

212214
mgr, err := ctrl.NewManager(restConfig, ctrlOptions)

controlplane/kubeadm/main.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,13 @@ func main() {
210210
},
211211
},
212212
},
213-
WebhookServer: &webhook.Server{
214-
Port: webhookPort,
215-
CertDir: webhookCertDir,
216-
TLSOpts: tlsOptionOverrides,
217-
},
213+
WebhookServer: webhook.NewServer(
214+
webhook.Options{
215+
Port: webhookPort,
216+
CertDir: webhookCertDir,
217+
TLSOpts: tlsOptionOverrides,
218+
},
219+
),
218220
}
219221

220222
mgr, err := ctrl.NewManager(restConfig, ctrlOptions)

exp/runtime/server/server.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var DefaultPort = 9443
4444
// Server is a runtime webhook server.
4545
type Server struct {
4646
catalog *runtimecatalog.Catalog
47-
server *webhook.Server
47+
server webhook.Server
4848
handlers map[string]ExtensionHandler
4949
}
5050

@@ -81,19 +81,21 @@ func New(options Options) (*Server, error) {
8181
options.CertDir = filepath.Join(os.TempDir(), "k8s-webhook-server", "serving-certs")
8282
}
8383

84-
webhookServer := &webhook.Server{
85-
Port: options.Port,
86-
Host: options.Host,
87-
CertDir: options.CertDir,
88-
CertName: "tls.crt",
89-
KeyName: "tls.key",
90-
WebhookMux: http.NewServeMux(),
91-
TLSOpts: []func(*tls.Config){
92-
func(cfg *tls.Config) {
93-
cfg.MinVersion = tls.VersionTLS13
84+
webhookServer := webhook.NewServer(
85+
webhook.Options{
86+
Port: options.Port,
87+
Host: options.Host,
88+
CertDir: options.CertDir,
89+
CertName: "tls.crt",
90+
KeyName: "tls.key",
91+
WebhookMux: http.NewServeMux(),
92+
TLSOpts: []func(*tls.Config){
93+
func(cfg *tls.Config) {
94+
cfg.MinVersion = tls.VersionTLS13
95+
},
9496
},
9597
},
96-
}
98+
)
9799

98100
return &Server{
99101
catalog: options.Catalog,

internal/controllers/topology/cluster/structuredmerge/serversidepathhelper_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ func TestServerSideApplyWithDefaulting(t *testing.T) {
785785
// It also calculates and returns the corresponding MutatingWebhookConfiguration.
786786
// Note: To activate the webhook, the MutatingWebhookConfiguration has to be deployed.
787787
func setupWebhookWithManager(ns *corev1.Namespace) (*KubeadmConfigTemplateTestDefaulter, *admissionv1.MutatingWebhookConfiguration, error) {
788-
webhookServer := env.Manager.GetWebhookServer()
788+
webhookServer := env.Manager.GetWebhookServer().(*webhook.DefaultServer)
789789

790790
// Calculate webhook host and path.
791791
// Note: This is done the same way as in our envtest package.
@@ -802,7 +802,7 @@ func setupWebhookWithManager(ns *corev1.Namespace) (*KubeadmConfigTemplateTestDe
802802
admission.WithCustomDefaulter(env.Manager.GetScheme(), &bootstrapv1.KubeadmConfigTemplate{}, defaulter))
803803

804804
// Calculate the MutatingWebhookConfiguration
805-
caBundle, err := os.ReadFile(filepath.Join(webhookServer.CertDir, webhookServer.CertName))
805+
caBundle, err := os.ReadFile(filepath.Join(webhookServer.Options.CertDir, webhookServer.Options.CertName))
806806
if err != nil {
807807
return nil, nil, err
808808
}
@@ -816,7 +816,7 @@ func setupWebhookWithManager(ns *corev1.Namespace) (*KubeadmConfigTemplateTestDe
816816
{
817817
Name: ns.Name + ".kubeadmconfigtemplate.bootstrap.cluster.x-k8s.io",
818818
ClientConfig: admissionv1.WebhookClientConfig{
819-
URL: pointer.String(fmt.Sprintf("https://%s%s", net.JoinHostPort(webhookHost, strconv.Itoa(webhookServer.Port)), webhookPath)),
819+
URL: pointer.String(fmt.Sprintf("https://%s%s", net.JoinHostPort(webhookHost, strconv.Itoa(webhookServer.Options.Port)), webhookPath)),
820820
CABundle: caBundle,
821821
},
822822
Rules: []admissionv1.RuleWithOperations{

internal/test/envtest/environment.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,13 @@ func newEnvironment(uncachedObjs ...client.Object) *Environment {
257257
DisableFor: objs,
258258
},
259259
},
260-
WebhookServer: &webhook.Server{
261-
Port: env.WebhookInstallOptions.LocalServingPort,
262-
CertDir: env.WebhookInstallOptions.LocalServingCertDir,
263-
Host: host,
264-
},
260+
WebhookServer: webhook.NewServer(
261+
webhook.Options{
262+
Port: env.WebhookInstallOptions.LocalServingPort,
263+
CertDir: env.WebhookInstallOptions.LocalServingCertDir,
264+
Host: host,
265+
},
266+
),
265267
}
266268

267269
mgr, err := ctrl.NewManager(env.Config, options)

main.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,13 @@ func main() {
274274
},
275275
},
276276
},
277-
WebhookServer: &webhook.Server{
278-
Port: webhookPort,
279-
CertDir: webhookCertDir,
280-
TLSOpts: tlsOptionOverrides,
281-
},
277+
WebhookServer: webhook.NewServer(
278+
webhook.Options{
279+
Port: webhookPort,
280+
CertDir: webhookCertDir,
281+
TLSOpts: tlsOptionOverrides,
282+
},
283+
),
282284
}
283285

284286
mgr, err := ctrl.NewManager(restConfig, ctrlOptions)

test/infrastructure/docker/main.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,13 @@ func main() {
208208
},
209209
},
210210
},
211-
WebhookServer: &webhook.Server{
212-
Port: webhookPort,
213-
CertDir: webhookCertDir,
214-
TLSOpts: tlsOptionOverrides,
215-
},
211+
WebhookServer: webhook.NewServer(
212+
webhook.Options{
213+
Port: webhookPort,
214+
CertDir: webhookCertDir,
215+
TLSOpts: tlsOptionOverrides,
216+
},
217+
),
216218
}
217219

218220
mgr, err := ctrl.NewManager(restConfig, ctrlOptions)

0 commit comments

Comments
 (0)