Skip to content

Commit

Permalink
Re-adding formatter when SQL cache is enabled (#300)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MbolotSuse authored Oct 18, 2024
1 parent 8fc2dd4 commit f6c6ca8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
36 changes: 17 additions & 19 deletions pkg/resources/common/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")

summary.NormalizeConditions(unstr)
// 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)

}
includeFields(request, unstr)
excludeFields(request, unstr)
excludeValues(request, unstr)
Expand Down
4 changes: 2 additions & 2 deletions pkg/resources/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit f6c6ca8

Please sign in to comment.