Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Nov 18, 2024
1 parent 44adf54 commit 91d285a
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ helm install kube-ui-server appscode/kube-ui-server
## Usage

```console
$ kubectl create -f artifacts/whoami.yaml -o yaml
$ kubectl create -f artifacts/whoami.yaml -o yaml --validate=false

apiVersion: authentication.k8s.io/v1
kind: SelfSubjectReview
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ require (
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0
kmodules.xyz/apiversion v0.2.0
kmodules.xyz/authorizer v0.29.1
kmodules.xyz/client-go v0.30.38-0.20241117075231-750051a8f0b9
kmodules.xyz/client-go v0.30.38-0.20241118085432-c54b8a32c3c5
kmodules.xyz/custom-resources v0.30.0
kmodules.xyz/go-containerregistry v0.0.12
kmodules.xyz/monitoring-agent-api v0.30.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,8 @@ kmodules.xyz/apiversion v0.2.0 h1:vAQYqZFm4xu4pbB1cAdHbFEPES6EQkcR4wc06xdTOWk=
kmodules.xyz/apiversion v0.2.0/go.mod h1:oPX8g8LvlPdPX3Yc5YvCzJHQnw3YF/X4/jdW0b1am80=
kmodules.xyz/authorizer v0.29.1 h1:uByGGoryKbZcfiEAhjcK/Y345I9mygNQP7DVpkMbNQQ=
kmodules.xyz/authorizer v0.29.1/go.mod h1:kZRhclL8twzyt2bQuJQJbpYww2sc+qFr8I5PPoq/sWY=
kmodules.xyz/client-go v0.30.38-0.20241117075231-750051a8f0b9 h1:8qSZylUUBcY1rKlVLgm3mRjw3/mG8QT0tSuCCflmIeU=
kmodules.xyz/client-go v0.30.38-0.20241117075231-750051a8f0b9/go.mod h1:CAu+JlA8RVGtj6LQHu0Q1w2mnFUajuti49c7T1AvGdM=
kmodules.xyz/client-go v0.30.38-0.20241118085432-c54b8a32c3c5 h1:HC1VTk5wkfctbx8Con82exu+/zvYVFvWsqPjaEwuNiQ=
kmodules.xyz/client-go v0.30.38-0.20241118085432-c54b8a32c3c5/go.mod h1:CAu+JlA8RVGtj6LQHu0Q1w2mnFUajuti49c7T1AvGdM=
kmodules.xyz/crd-schema-fuzz v0.29.1 h1:zJTlWYOrT5dsVVHW8HGcnR/vaWfxQfNh11QwTtkYpcs=
kmodules.xyz/crd-schema-fuzz v0.29.1/go.mod h1:n708z9YQqLMP2KNLQVgBcRJw1QpSWLvpNCEi+KJDOYE=
kmodules.xyz/custom-resources v0.30.0 h1:vR3CbseHMLwR4GvtcJJuRuwIV8voKqFqNii27rMcm1o=
Expand Down
6 changes: 5 additions & 1 deletion pkg/graph/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ func renderPageBlock(ctx context.Context, kc client.Client, oc openvizcs.Interfa
}

func _renderPageBlock(ctx context.Context, kc client.Client, oc openvizcs.Interface, srcRID *kmapi.ResourceID, srcObj *unstructured.Unstructured, block *rsapi.PageBlockLayout, convertToTable bool) (*rsapi.PageBlockView, error) {
cc, err := getClient(ctx, kc, block.Impersonate)
var impersonate bool
if block != nil && block.ResourceLocator != nil && block.Impersonate {
impersonate = true
}
cc, err := getClient(ctx, kc, impersonate)
if err != nil {
return nil, err
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/graph/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,18 @@ func getClient(ctx context.Context, kc client.Client, impersonate bool) (client.
return kc, nil
}

fmt.Printf("impersonating: %v\n", u.GetName())

if rw, ok := kc.(*cu.DelegatingClient); ok {
return rw.Impersonate(u)
}
return nil, fmt.Errorf("can't impersonate client")
}

func NewUserContext(in context.Context) context.Context {
ctx := context.TODO()
if u, ok := request.UserFrom(in); ok {
ctx = request.WithUser(ctx, u)
}
return ctx
}
4 changes: 2 additions & 2 deletions pkg/registry/meta/render/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (r *Storage) Create(ctx context.Context, obj runtime.Object, _ rest.Validat
autoColumns = true
}

bv, err := graph.RenderPageBlock(ctx, r.kc, r.oc, req.Source, req.Block, req.ConvertToTable)
bv, err := graph.RenderPageBlock(graph.NewUserContext(ctx), r.kc, r.oc, req.Source, req.Block, req.ConvertToTable)
if err != nil {
return nil, err
}
Expand All @@ -121,7 +121,7 @@ func (r *Storage) Create(ctx context.Context, obj runtime.Object, _ rest.Validat
renderBlocks.Insert(string(k))
}
rv, err := graph.RenderLayout(
ctx,
graph.NewUserContext(ctx),
r.kc,
r.oc,
req.Source,
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/meta/renderdashboard/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (r *Storage) Create(ctx context.Context, obj runtime.Object, _ rest.Validat
}
}

dg, err := graph.RenderDashboard(ctx, r.kc, r.oc, rd, src, req.EmbeddedLink)
dg, err := graph.RenderDashboard(graph.NewUserContext(ctx), r.kc, r.oc, rd, src, req.EmbeddedLink)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/registry/meta/resourcequery/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (r *Storage) Create(ctx context.Context, obj runtime.Object, _ rest.Validat
src := kmapi.NewObjectID(&out)

if req.OutputFormat == rsapi.OutputFormatRef {
_, refs, err := graph.ExecRawQuery(ctx, r.kc, src.OID(), *req.Target)
_, refs, err := graph.ExecRawQuery(graph.NewUserContext(ctx), r.kc, src.OID(), *req.Target)
if err != nil {
return nil, err
}
Expand All @@ -116,7 +116,7 @@ func (r *Storage) Create(ctx context.Context, obj runtime.Object, _ rest.Validat
}
in.Response = &runtime.RawExtension{Raw: data}
} else {
rid2, items, err := graph.ExecQuery(ctx, r.kc, src.OID(), *req.Target)
rid2, items, err := graph.ExecQuery(graph.NewUserContext(ctx), r.kc, src.OID(), *req.Target)
if err != nil {
return nil, err
}
Expand Down
11 changes: 10 additions & 1 deletion vendor/kmodules.xyz/client-go/client/delegated.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,16 @@ func (d *DelegatingClient) Impersonate(u user.Info) (client.Client, error) {
Groups: u.GetGroups(),
Extra: u.GetExtra(),
}
return NewClient(config, d.options)
// share the transport between all clients
httpClient, err := restclient.HTTPClientFor(config)
if err != nil {
return nil, err
}

optionsShallowCopy := d.options
optionsShallowCopy.HTTPClient = httpClient

return NewClient(config, optionsShallowCopy)
}

// GroupVersionKindFor returns the GroupVersionKind for the given object.
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2020,7 +2020,7 @@ kmodules.xyz/authorizer/apiserver
kmodules.xyz/authorizer/rbac
kmodules.xyz/authorizer/rbac/helpers
kmodules.xyz/authorizer/rbac/validation
# kmodules.xyz/client-go v0.30.38-0.20241117075231-750051a8f0b9
# kmodules.xyz/client-go v0.30.38-0.20241118085432-c54b8a32c3c5
## explicit; go 1.22.0
kmodules.xyz/client-go
kmodules.xyz/client-go/api/v1
Expand Down

0 comments on commit 91d285a

Please sign in to comment.