1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-27 15:53:59 +00:00

[v2.10] SQL cache backports (#435)

Co-authored-by: Tom Lebreux <tom.lebreux@suse.com>
This commit is contained in:
Silvio Moioli
2025-01-11 12:26:12 +01:00
committed by GitHub
parent a672f2f12a
commit c48ac64c4d
6 changed files with 158 additions and 24 deletions

View File

@@ -41,6 +41,7 @@ import (
"github.com/rancher/wrangler/v3/pkg/summary"
"github.com/rancher/steve/pkg/attributes"
controllerschema "github.com/rancher/steve/pkg/controllers/schema"
"github.com/rancher/steve/pkg/resources/common"
"github.com/rancher/steve/pkg/resources/virtual"
virtualCommon "github.com/rancher/steve/pkg/resources/virtual/common"
@@ -59,6 +60,8 @@ var (
paramScheme = runtime.NewScheme()
paramCodec = runtime.NewParameterCodec(paramScheme)
typeSpecificIndexedFields = map[string][][]string{
gvkKey("", "v1", "ConfigMap"): {
{"metadata", "labels[harvesterhci.io/cloud-init-template]"}},
gvkKey("", "v1", "Event"): {
{"_type"},
{"involvedObject", "kind"},
@@ -70,11 +73,43 @@ var (
gvkKey("", "v1", "Node"): {
{"status", "nodeInfo", "kubeletVersion"},
{"status", "nodeInfo", "operatingSystem"}},
gvkKey("", "v1", "PersistentVolume"): {
{"status", "reason"},
{"spec", "persistentVolumeReclaimPolicy"},
},
gvkKey("", "v1", "PersistentVolumeClaim"): {
{"spec", "volumeName"}},
gvkKey("", "v1", "Pod"): {
{"spec", "containers", "image"},
{"spec", "nodeName"}},
gvkKey("", "v1", "ConfigMap"): {
{"metadata", "labels[harvesterhci.io/cloud-init-template]"}},
gvkKey("", "v1", "Service"): {
{"spec", "clusterIP"},
{"spec", "type"},
},
gvkKey("apps", "v1", "DaemonSet"): {
{"metadata", "annotations[field.cattle.io/publicEndpoints]"},
},
gvkKey("apps", "v1", "Deployment"): {
{"metadata", "annotations[field.cattle.io/publicEndpoints]"},
},
gvkKey("apps", "v1", "StatefulSet"): {
{"metadata", "annotations[field.cattle.io/publicEndpoints]"},
},
gvkKey("autoscaling", "v2", "HorizontalPodAutoscaler"): {
{"spec", "scaleTargetRef", "name"},
{"spec", "minReplicas"},
{"spec", "maxReplicas"},
{"status", "currentReplicas"},
},
gvkKey("batch", "v1", "CronJob"): {
{"metadata", "annotations[field.cattle.io/publicEndpoints]"},
},
gvkKey("batch", "v1", "Job"): {
{"metadata", "annotations[field.cattle.io/publicEndpoints]"},
},
gvkKey("catalog.cattle.io", "v1", "App"): {
{"spec", "chart", "metadata", "name"},
},
gvkKey("catalog.cattle.io", "v1", "ClusterRepo"): {
{"metadata", "annotations[clusterrepo.cattle.io/hidden]"},
{"spec", "gitBranch"},
@@ -87,18 +122,30 @@ var (
},
gvkKey("cluster.x-k8s.io", "v1beta1", "Machine"): {
{"spec", "clusterName"}},
gvkKey("management.cattle.io", "v3", "Cluster"): {
{"metadata", "labels[provider.cattle.io]"},
{"spec", "internal"},
{"spec", "displayName"},
{"status", "provider"},
},
gvkKey("management.cattle.io", "v3", "Node"): {
{"status", "nodeName"}},
gvkKey("management.cattle.io", "v3", "NodePool"): {
{"spec", "clusterName"}},
gvkKey("management.cattle.io", "v3", "NodeTemplate"): {
{"spec", "clusterName"}},
gvkKey("networking.k8s.io", "v1", "Ingress"): {
{"spec", "rules", "host"},
{"spec", "ingressClassName"},
},
gvkKey("provisioning.cattle.io", "v1", "Cluster"): {
{"metadata", "labels[provider.cattle.io]"},
{"status", "clusterName"},
{"status", "provider"},
{"status", "allocatable", "cpu"},
{"status", "allocatable", "memory"},
{"status", "allocatable", "pods"},
},
gvkKey("storage.k8s.io", "v1", "StorageClass"): {
{"provisioner"},
{"metadata", "annotations[storageclass.kubernetes.io/is-default-class]"},
},
}
commonIndexFields = [][]string{
@@ -184,7 +231,7 @@ type Store struct {
type CacheFactoryInitializer func() (CacheFactory, error)
type CacheFactory interface {
CacheFor(fields [][]string, transform cache.TransformFunc, client dynamic.ResourceInterface, gvk schema.GroupVersionKind, namespaced bool) (factory.Cache, error)
CacheFor(fields [][]string, transform cache.TransformFunc, client dynamic.ResourceInterface, gvk schema.GroupVersionKind, namespaced bool, watchable bool) (factory.Cache, error)
Reset() error
}
@@ -262,7 +309,7 @@ func (s *Store) initializeNamespaceCache() error {
transformFunc := s.transformBuilder.GetTransformFunc(gvk)
// get the ns informer
nsInformer, err := s.cacheFactory.CacheFor(fields, transformFunc, &tablelistconvert.Client{ResourceInterface: client}, attributes.GVK(&nsSchema), false)
nsInformer, err := s.cacheFactory.CacheFor(fields, transformFunc, &tablelistconvert.Client{ResourceInterface: client}, attributes.GVK(&nsSchema), false, true)
if err != nil {
return err
}
@@ -702,7 +749,7 @@ func (s *Store) ListByPartitions(apiOp *types.APIRequest, schema *types.APISchem
fields = append(fields, getFieldForGVK(gvk)...)
transformFunc := s.transformBuilder.GetTransformFunc(gvk)
inf, err := s.cacheFactory.CacheFor(fields, transformFunc, &tablelistconvert.Client{ResourceInterface: client}, attributes.GVK(schema), attributes.Namespaced(schema))
inf, err := s.cacheFactory.CacheFor(fields, transformFunc, &tablelistconvert.Client{ResourceInterface: client}, attributes.GVK(schema), attributes.Namespaced(schema), controllerschema.IsListWatchable(schema))
if err != nil {
return nil, 0, "", err
}