diff --git a/pkg/yurtmanager/webhook/util/controller/webhook_controller.go b/pkg/yurtmanager/webhook/util/controller/webhook_controller.go index baa8617ee2e..d0ab8c72850 100644 --- a/pkg/yurtmanager/webhook/util/controller/webhook_controller.go +++ b/pkg/yurtmanager/webhook/util/controller/webhook_controller.go @@ -312,7 +312,24 @@ func ensureCRDConversionCA(client apiextensionsclientset.Interface, crd *apiexte } crd.Spec.Conversion.Webhook.ClientConfig.CABundle = newCABundle + + // Apply changes just like ValidatingWebhookConfiguration. + convertCRDConversionWebhookClientConfig(crd.Spec.Conversion.Webhook.ClientConfig) + // update crd _, err := client.ApiextensionsV1().CustomResourceDefinitions().Update(context.TODO(), crd, metav1.UpdateOptions{}) return err } + +func convertCRDConversionWebhookClientConfig(clientConfig *apiextensionsv1.WebhookClientConfig) { + if clientConfig.Service != nil { + clientConfig.Service.Namespace = webhookutil.GetNamespace() + clientConfig.Service.Name = webhookutil.GetServiceName() + + if host := webhookutil.GetHost(); len(host) > 0 { + url := fmt.Sprintf("https://%s%s", host, *clientConfig.Service.Path) + clientConfig.URL = &url + clientConfig.Service = nil + } + } +}