@@ -32,7 +32,7 @@ import (
3232)
3333
3434// webhookPathPrefix is the path prefix at which the handler should be registered.
35- const webhookPathPrefix = "/webhooks/sharder/"
35+ const webhookPathPrefix = "/webhooks/sharder/controllerring/ "
3636
3737// AddToManager adds Handler to the given manager.
3838func (h * Handler ) AddToManager (mgr manager.Manager ) error {
@@ -53,12 +53,10 @@ func (h *Handler) AddToManager(mgr manager.Manager) error {
5353 return nil
5454}
5555
56- const pathControllerRing = "controllerring"
57-
5856// WebhookPathForControllerRing returns the webhook handler path that should be used for implementing the given
5957// ControllerRing. It is the reverse of ControllerRingForWebhookPath.
6058func WebhookPathForControllerRing (ring * shardingv1alpha1.ControllerRing ) string {
61- return path .Join (webhookPathPrefix , pathControllerRing , ring .Name )
59+ return path .Join (webhookPathPrefix , ring .Name )
6260}
6361
6462// ControllerRingForWebhookPath returns the ControllerRing that is associated with the given webhook handler path.
@@ -68,18 +66,12 @@ func ControllerRingForWebhookPath(requestPath string) (*shardingv1alpha1.Control
6866 return nil , fmt .Errorf ("unexpected request path: %s" , requestPath )
6967 }
7068
71- parts := strings .SplitN (strings .TrimPrefix (requestPath , webhookPathPrefix ), "/" , 3 )
72- if len (parts ) != 2 {
73- return nil , fmt .Errorf ("unexpected request path: %s" , requestPath )
74- }
75- if parts [0 ] != pathControllerRing {
76- return nil , fmt .Errorf ("unexpected request path: %s" , requestPath )
77- }
78- if parts [1 ] == "" {
69+ name := strings .TrimPrefix (requestPath , webhookPathPrefix )
70+ if name == "" {
7971 return nil , fmt .Errorf ("unexpected request path: %s" , requestPath )
8072 }
8173
82- return & shardingv1alpha1.ControllerRing {ObjectMeta : metav1.ObjectMeta {Name : parts [ 1 ] }}, nil
74+ return & shardingv1alpha1.ControllerRing {ObjectMeta : metav1.ObjectMeta {Name : name }}, nil
8375}
8476
8577type ctxKey int
0 commit comments