File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,9 +2,7 @@ package webhook
22
33import (
44 "context"
5- "fmt"
65 "net/http"
7- "net/url"
86
97 "sigs.k8s.io/controller-runtime/pkg/webhook"
108 "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
@@ -22,17 +20,12 @@ var _ webhook.Server = &clusterAwareWebhookServer{}
2220
2321func (s * clusterAwareWebhookServer ) Register (path string , hook http.Handler ) {
2422 if h , ok := hook .(* admission.Webhook ); ok {
25- h .WithContextFunc = func (ctx context.Context , req * http.Request ) context.Context {
26- clusterName , err := url .QueryUnescape (req .PathValue ("cluster_name" ))
27- if err != nil {
28- return ctx
29- }
30- return mccontext .WithCluster (ctx , clusterName )
31- }
32- }
33-
34- if s .discoveryMode != multiclusterproviders .ProviderSingle {
35- path = fmt .Sprintf ("/clusters/{cluster_name}%s" , path )
23+ orig := h .Handler
24+ h .Handler = admission .HandlerFunc (func (ctx context.Context , req admission.Request ) admission.Response {
25+ c := clusterFromExtra (req .UserInfo .Extra )
26+ ctx = mccontext .WithCluster (ctx , c )
27+ return orig .Handle (ctx , req )
28+ })
3629 }
3730
3831 s .Server .Register (path , hook )
Original file line number Diff line number Diff line change 1+ package webhook
2+
3+ import authv1 "k8s.io/api/authentication/v1"
4+
5+ const (
6+ ParentNameExtraKey = "iam.miloapis.com/parent-name"
7+ )
8+
9+ func clusterFromExtra (extra map [string ]authv1.ExtraValue ) string {
10+ if v , ok := extra [ParentNameExtraKey ]; ok && len (v ) > 0 && v [0 ] != "" {
11+ return v [0 ]
12+ }
13+ return ""
14+ }
You can’t perform that action at this time.
0 commit comments