mirror of
https://github.com/rancher/steve.git
synced 2025-08-11 19:21:36 +00:00
Re-adding formatter when SQL cache is enabled (#300)
Previously, the formatter for state/relationships was disabled when the sql cache was enabled, since a transform function was adding those values before they were added to the cache. However, the get/watch calls currently don't use the cache, causing the state/relationships to be missing.
This commit is contained in:
parent
8fc2dd4f74
commit
f6c6ca839c
@ -23,19 +23,18 @@ import (
|
|||||||
func DefaultTemplate(clientGetter proxy.ClientGetter,
|
func DefaultTemplate(clientGetter proxy.ClientGetter,
|
||||||
summaryCache *summarycache.SummaryCache,
|
summaryCache *summarycache.SummaryCache,
|
||||||
asl accesscontrol.AccessSetLookup,
|
asl accesscontrol.AccessSetLookup,
|
||||||
namespaceCache corecontrollers.NamespaceCache,
|
namespaceCache corecontrollers.NamespaceCache) schema.Template {
|
||||||
sqlCache bool) schema.Template {
|
|
||||||
return schema.Template{
|
return schema.Template{
|
||||||
Store: metricsStore.NewMetricsStore(proxy.NewProxyStore(clientGetter, summaryCache, asl, namespaceCache)),
|
Store: metricsStore.NewMetricsStore(proxy.NewProxyStore(clientGetter, summaryCache, asl, namespaceCache)),
|
||||||
Formatter: formatter(summaryCache, sqlCache),
|
Formatter: formatter(summaryCache),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultTemplateForStore provides a default schema template which uses a provided, pre-initialized store. Primarily used when creating a Template that uses a Lasso SQL store internally.
|
// DefaultTemplateForStore provides a default schema template which uses a provided, pre-initialized store. Primarily used when creating a Template that uses a Lasso SQL store internally.
|
||||||
func DefaultTemplateForStore(store types.Store, summaryCache *summarycache.SummaryCache, sqlCache bool) schema.Template {
|
func DefaultTemplateForStore(store types.Store, summaryCache *summarycache.SummaryCache) schema.Template {
|
||||||
return schema.Template{
|
return schema.Template{
|
||||||
Store: store,
|
Store: store,
|
||||||
Formatter: formatter(summaryCache, sqlCache),
|
Formatter: formatter(summaryCache),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +71,7 @@ func selfLink(gvr schema2.GroupVersionResource, meta metav1.Object) (prefix stri
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatter(summarycache *summarycache.SummaryCache, sqlCache bool) types.Formatter {
|
func formatter(summarycache *summarycache.SummaryCache) types.Formatter {
|
||||||
return func(request *types.APIRequest, resource *types.RawResource) {
|
return func(request *types.APIRequest, resource *types.RawResource) {
|
||||||
if resource.Schema == nil {
|
if resource.Schema == nil {
|
||||||
return
|
return
|
||||||
@ -105,20 +104,19 @@ func formatter(summarycache *summarycache.SummaryCache, sqlCache bool) types.For
|
|||||||
}
|
}
|
||||||
|
|
||||||
if unstr, ok := resource.APIObject.Object.(*unstructured.Unstructured); ok {
|
if unstr, ok := resource.APIObject.Object.(*unstructured.Unstructured); ok {
|
||||||
if !sqlCache {
|
// with the sql cache, these were already added by the indexer. However, the sql cache
|
||||||
// with the sql cache, these were already added by the indexer
|
// is only used for lists, so we need to re-add here for get/watch
|
||||||
s, rel := summarycache.SummaryAndRelationship(unstr)
|
s, rel := summarycache.SummaryAndRelationship(unstr)
|
||||||
data.PutValue(unstr.Object, map[string]interface{}{
|
data.PutValue(unstr.Object, map[string]interface{}{
|
||||||
"name": s.State,
|
"name": s.State,
|
||||||
"error": s.Error,
|
"error": s.Error,
|
||||||
"transitioning": s.Transitioning,
|
"transitioning": s.Transitioning,
|
||||||
"message": strings.Join(s.Message, ":"),
|
"message": strings.Join(s.Message, ":"),
|
||||||
}, "metadata", "state")
|
}, "metadata", "state")
|
||||||
data.PutValue(unstr.Object, rel, "metadata", "relationships")
|
data.PutValue(unstr.Object, rel, "metadata", "relationships")
|
||||||
|
|
||||||
summary.NormalizeConditions(unstr)
|
summary.NormalizeConditions(unstr)
|
||||||
|
|
||||||
}
|
|
||||||
includeFields(request, unstr)
|
includeFields(request, unstr)
|
||||||
excludeFields(request, unstr)
|
excludeFields(request, unstr)
|
||||||
excludeValues(request, unstr)
|
excludeValues(request, unstr)
|
||||||
|
@ -49,7 +49,7 @@ func DefaultSchemaTemplates(cf *client.Factory,
|
|||||||
discovery discovery.DiscoveryInterface,
|
discovery discovery.DiscoveryInterface,
|
||||||
namespaceCache corecontrollers.NamespaceCache) []schema.Template {
|
namespaceCache corecontrollers.NamespaceCache) []schema.Template {
|
||||||
return []schema.Template{
|
return []schema.Template{
|
||||||
common.DefaultTemplate(cf, summaryCache, lookup, namespaceCache, false),
|
common.DefaultTemplate(cf, summaryCache, lookup, namespaceCache),
|
||||||
apigroups.Template(discovery),
|
apigroups.Template(discovery),
|
||||||
{
|
{
|
||||||
ID: "configmap",
|
ID: "configmap",
|
||||||
@ -79,7 +79,7 @@ func DefaultSchemaTemplatesForStore(store types.Store,
|
|||||||
discovery discovery.DiscoveryInterface) []schema.Template {
|
discovery discovery.DiscoveryInterface) []schema.Template {
|
||||||
|
|
||||||
return []schema.Template{
|
return []schema.Template{
|
||||||
common.DefaultTemplateForStore(store, summaryCache, true),
|
common.DefaultTemplateForStore(store, summaryCache),
|
||||||
apigroups.Template(discovery),
|
apigroups.Template(discovery),
|
||||||
{
|
{
|
||||||
ID: "configmap",
|
ID: "configmap",
|
||||||
|
Loading…
Reference in New Issue
Block a user