mirror of
https://github.com/rancher/steve.git
synced 2025-09-16 07:18:28 +00:00
Show resource relationships
This commit is contained in:
@@ -7,48 +7,49 @@ import (
|
||||
"github.com/rancher/steve/pkg/accesscontrol"
|
||||
"github.com/rancher/steve/pkg/schema"
|
||||
"github.com/rancher/steve/pkg/stores/proxy"
|
||||
"github.com/rancher/steve/pkg/summarycache"
|
||||
"github.com/rancher/wrangler/pkg/data"
|
||||
"github.com/rancher/wrangler/pkg/summary"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
func DefaultTemplate(clientGetter proxy.ClientGetter, asl accesscontrol.AccessSetLookup) schema.Template {
|
||||
func DefaultTemplate(clientGetter proxy.ClientGetter,
|
||||
summaryCache *summarycache.SummaryCache,
|
||||
asl accesscontrol.AccessSetLookup) schema.Template {
|
||||
return schema.Template{
|
||||
Store: proxy.NewProxyStore(clientGetter, asl),
|
||||
Formatter: Formatter,
|
||||
Store: proxy.NewProxyStore(clientGetter, summaryCache, asl),
|
||||
Formatter: formatter(summaryCache),
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultFormatter(next types.Formatter) types.Formatter {
|
||||
return types.FormatterChain(Formatter, next)
|
||||
}
|
||||
func formatter(summarycache *summarycache.SummaryCache) types.Formatter {
|
||||
return func(request *types.APIRequest, resource *types.RawResource) {
|
||||
meta, err := meta.Accessor(resource.APIObject.Object)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
func Formatter(request *types.APIRequest, resource *types.RawResource) {
|
||||
meta, err := meta.Accessor(resource.APIObject.Object)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
selfLink := meta.GetSelfLink()
|
||||
if selfLink == "" {
|
||||
return
|
||||
}
|
||||
|
||||
selfLink := meta.GetSelfLink()
|
||||
if selfLink == "" {
|
||||
return
|
||||
}
|
||||
u := request.URLBuilder.RelativeToRoot(selfLink)
|
||||
resource.Links["view"] = u
|
||||
|
||||
u := request.URLBuilder.RelativeToRoot(selfLink)
|
||||
resource.Links["view"] = u
|
||||
if _, ok := resource.Links["update"]; !ok {
|
||||
resource.Links["update"] = u
|
||||
}
|
||||
|
||||
if _, ok := resource.Links["update"]; !ok {
|
||||
resource.Links["update"] = u
|
||||
}
|
||||
|
||||
if unstr, ok := resource.APIObject.Object.(*unstructured.Unstructured); ok {
|
||||
summary := summary.Summarize(unstr)
|
||||
data.PutValue(unstr.Object, map[string]interface{}{
|
||||
"name": summary.State,
|
||||
"error": summary.Error,
|
||||
"transitioning": summary.Transitioning,
|
||||
"message": strings.Join(summary.Message, ":"),
|
||||
}, "metadata", "state")
|
||||
if unstr, ok := resource.APIObject.Object.(*unstructured.Unstructured); ok {
|
||||
summary, rel := summarycache.SummaryAndRelationship(unstr)
|
||||
data.PutValue(unstr.Object, map[string]interface{}{
|
||||
"name": summary.State,
|
||||
"error": summary.Error,
|
||||
"transitioning": summary.Transitioning,
|
||||
"message": strings.Join(summary.Message, ":"),
|
||||
}, "metadata", "state")
|
||||
data.PutValue(unstr.Object, rel, "metadata", "relationships")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user