mirror of
https://github.com/rancher/steve.git
synced 2025-09-01 15:37:31 +00:00
Index more sqlite cache fields (#271)
* Add more fields to index when sql-caching is on. Misc changes: - Use the builtin Event class, not events.k8s.io (by looking at the dashboard client code) - Specify full path to the management.cattle.io fields. - Map `Event.type` to `Event._type` for indexing. Use a compound transform-func to first check for a "signal", and then to run all the relevant transformers until either one fails or the list is exhausted. - Includes moving the fakeSummaryCache type into a common area. Use a simpler way of running transforms. * Inline the function to get the gvk key. * Create a '--sql-cache' flag to turn on caching for the steve CLI. * Improve error-handling in object transformer. * Drop the 'GetTransform' function. * Inline the code that transforms a payload into a k8s-unstructured object.
This commit is contained in:
@@ -59,12 +59,47 @@ var (
|
||||
paramScheme = runtime.NewScheme()
|
||||
paramCodec = runtime.NewParameterCodec(paramScheme)
|
||||
typeSpecificIndexedFields = map[string][][]string{
|
||||
"_v1_Namespace": {{`metadata`, `labels[field.cattle.io/projectId]`}},
|
||||
"_v1_Node": {{`status`, `nodeInfo`, `kubeletVersion`}, {`status`, `nodeInfo`, `operatingSystem`}},
|
||||
"_v1_Pod": {{`spec`, `containers`, `image`}, {`spec`, `nodeName`}},
|
||||
"_v1_ConfigMap": {{`metadata`, `labels[harvesterhci.io/cloud-init-template]`}},
|
||||
|
||||
"management.cattle.io_v3_Node": {{`status`, `nodeName`}},
|
||||
gvkKey("", "v1", "Event"): {
|
||||
{"_type"},
|
||||
{"involvedObject", "kind"},
|
||||
{"message"},
|
||||
{"reason"},
|
||||
},
|
||||
gvkKey("", "v1", "Namespace"): {
|
||||
{"metadata", "labels[field.cattle.io/projectId]"}},
|
||||
gvkKey("", "v1", "Node"): {
|
||||
{"status", "nodeInfo", "kubeletVersion"},
|
||||
{"status", "nodeInfo", "operatingSystem"}},
|
||||
gvkKey("", "v1", "Pod"): {
|
||||
{"spec", "containers", "image"},
|
||||
{"spec", "nodeName"}},
|
||||
gvkKey("", "v1", "ConfigMap"): {
|
||||
{"metadata", "labels[harvesterhci.io/cloud-init-template]"}},
|
||||
gvkKey("catalog.cattle.io", "v1", "ClusterRepo"): {
|
||||
{"metadata", "annotations[clusterrepo.cattle.io/hidden]"},
|
||||
{"spec", "gitBranch"},
|
||||
{"spec", "gitRepo"},
|
||||
},
|
||||
gvkKey("catalog.cattle.io", "v1", "Operation"): {
|
||||
{"status", "action"},
|
||||
{"status", "namespace"},
|
||||
{"status", "releaseName"},
|
||||
},
|
||||
gvkKey("cluster.x-k8s.io", "v1beta1", "Machine"): {
|
||||
{"spec", "clusterName"}},
|
||||
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("provisioning.cattle.io", "v1", "Cluster"): {
|
||||
{"metadata", "labels[provider.cattle.io]"},
|
||||
{"status", "provider"},
|
||||
{"status", "allocatable", "cpu"},
|
||||
{"status", "allocatable", "memory"},
|
||||
{"status", "allocatable", "pods"},
|
||||
},
|
||||
}
|
||||
commonIndexFields = [][]string{
|
||||
{`id`},
|
||||
@@ -239,15 +274,15 @@ func (s *Store) initializeNamespaceCache() error {
|
||||
func getFieldForGVK(gvk schema.GroupVersionKind) [][]string {
|
||||
fields := [][]string{}
|
||||
fields = append(fields, commonIndexFields...)
|
||||
typeFields := typeSpecificIndexedFields[keyFromGVK(gvk)]
|
||||
typeFields := typeSpecificIndexedFields[gvkKey(gvk.Group, gvk.Version, gvk.Kind)]
|
||||
if typeFields != nil {
|
||||
fields = append(fields, typeFields...)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
func keyFromGVK(gvk schema.GroupVersionKind) string {
|
||||
return gvk.Group + "_" + gvk.Version + "_" + gvk.Kind
|
||||
func gvkKey(group, version, kind string) string {
|
||||
return group + "_" + version + "_" + kind
|
||||
}
|
||||
|
||||
// getFieldsFromSchema converts object field names from types.APISchema's format into lasso's
|
||||
|
Reference in New Issue
Block a user