Skip to content

Commit

Permalink
fix: CRD WebhookConversion respect WEBHOOK_HOST env (#2217)
Browse files Browse the repository at this point in the history
Signed-off-by: fungaren <[email protected]>
  • Loading branch information
fungaren authored Dec 23, 2024
1 parent d6aeb2f commit 2432e74
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/yurtmanager/webhook/util/controller/webhook_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit 2432e74

Please sign in to comment.