File tree Expand file tree Collapse file tree 2 files changed +20
-11
lines changed
Expand file tree Collapse file tree 2 files changed +20
-11
lines changed 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"
@@ -18,17 +16,14 @@ var _ webhook.Server = &clusterAwareWebhookServer{}
1816
1917func (s * clusterAwareWebhookServer ) Register (path string , hook http.Handler ) {
2018 if h , ok := hook .(* admission.Webhook ); ok {
21- h .WithContextFunc = func (ctx context.Context , req * http.Request ) context.Context {
22- clusterName , err := url .QueryUnescape (req .PathValue ("cluster_name" ))
23- if err != nil {
24- return ctx
25- }
26- return WithClusterName (ctx , clusterName )
27- }
19+ orig := h .Handler
20+ h .Handler = admission .HandlerFunc (func (ctx context.Context , req admission.Request ) admission.Response {
21+ c := clusterFromExtra (req .UserInfo .Extra )
22+ ctx = WithClusterName (ctx , c )
23+ return orig .Handle (ctx , req )
24+ })
2825 }
2926
30- path = fmt .Sprintf ("/clusters/{cluster_name}%s" , path )
31-
3227 s .Server .Register (path , hook )
3328}
3429
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