mirror of
https://github.com/rancher/steve.git
synced 2025-07-31 06:23:11 +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,
|
||||
summaryCache *summarycache.SummaryCache,
|
||||
asl accesscontrol.AccessSetLookup,
|
||||
namespaceCache corecontrollers.NamespaceCache,
|
||||
sqlCache bool) schema.Template {
|
||||
namespaceCache corecontrollers.NamespaceCache) schema.Template {
|
||||
return schema.Template{
|
||||
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.
|
||||
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{
|
||||
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()
|
||||
}
|
||||
|
||||
func formatter(summarycache *summarycache.SummaryCache, sqlCache bool) types.Formatter {
|
||||
func formatter(summarycache *summarycache.SummaryCache) types.Formatter {
|
||||
return func(request *types.APIRequest, resource *types.RawResource) {
|
||||
if resource.Schema == nil {
|
||||
return
|
||||
@ -105,20 +104,19 @@ func formatter(summarycache *summarycache.SummaryCache, sqlCache bool) types.For
|
||||
}
|
||||
|
||||
if unstr, ok := resource.APIObject.Object.(*unstructured.Unstructured); ok {
|
||||
if !sqlCache {
|
||||
// with the sql cache, these were already added by the indexer
|
||||
s, rel := summarycache.SummaryAndRelationship(unstr)
|
||||
data.PutValue(unstr.Object, map[string]interface{}{
|
||||
"name": s.State,
|
||||
"error": s.Error,
|
||||
"transitioning": s.Transitioning,
|
||||
"message": strings.Join(s.Message, ":"),
|
||||
}, "metadata", "state")
|
||||
data.PutValue(unstr.Object, rel, "metadata", "relationships")
|
||||
// with the sql cache, these were already added by the indexer. However, the sql cache
|
||||
// is only used for lists, so we need to re-add here for get/watch
|
||||
s, rel := summarycache.SummaryAndRelationship(unstr)
|
||||
data.PutValue(unstr.Object, map[string]interface{}{
|
||||
"name": s.State,
|
||||
"error": s.Error,
|
||||
"transitioning": s.Transitioning,
|
||||
"message": strings.Join(s.Message, ":"),
|
||||
}, "metadata", "state")
|
||||
data.PutValue(unstr.Object, rel, "metadata", "relationships")
|
||||
|
||||
summary.NormalizeConditions(unstr)
|
||||
summary.NormalizeConditions(unstr)
|
||||
|
||||
}
|
||||
includeFields(request, unstr)
|
||||
excludeFields(request, unstr)
|
||||
excludeValues(request, unstr)
|
||||
|
@ -49,7 +49,7 @@ func DefaultSchemaTemplates(cf *client.Factory,
|
||||
discovery discovery.DiscoveryInterface,
|
||||
namespaceCache corecontrollers.NamespaceCache) []schema.Template {
|
||||
return []schema.Template{
|
||||
common.DefaultTemplate(cf, summaryCache, lookup, namespaceCache, false),
|
||||
common.DefaultTemplate(cf, summaryCache, lookup, namespaceCache),
|
||||
apigroups.Template(discovery),
|
||||
{
|
||||
ID: "configmap",
|
||||
@ -79,7 +79,7 @@ func DefaultSchemaTemplatesForStore(store types.Store,
|
||||
discovery discovery.DiscoveryInterface) []schema.Template {
|
||||
|
||||
return []schema.Template{
|
||||
common.DefaultTemplateForStore(store, summaryCache, true),
|
||||
common.DefaultTemplateForStore(store, summaryCache),
|
||||
apigroups.Template(discovery),
|
||||
{
|
||||
ID: "configmap",
|
||||
|
Loading…
Reference in New Issue
Block a user