1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-12 13:31:57 +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:
Eric Promislow
2024-10-18 11:06:29 -07:00
committed by GitHub
parent f6c6ca839c
commit 06c2eb50d1
11 changed files with 433 additions and 49 deletions

View File

@@ -9,11 +9,10 @@ import (
"github.com/stretchr/testify/require"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/cache"
)
func TestTransform(t *testing.T) {
func TestTransformCommonObjects(t *testing.T) {
tests := []struct {
name string
input any
@@ -160,29 +159,29 @@ func TestTransform(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
fakeCache := fakeSummaryCache{
summarizedObject: test.hasSummary,
relationships: test.hasRelationships,
fakeCache := common.FakeSummaryCache{
SummarizedObject: test.hasSummary,
Relationships: test.hasRelationships,
}
df := common.DefaultFields{
Cache: &fakeCache,
}
output, err := df.GetTransform()(test.input)
require.Equal(t, test.wantOutput, output)
raw, isSignal, err := common.GetUnstructured(test.input)
if err != nil {
require.True(t, test.wantError)
return
}
if isSignal {
require.Equal(t, test.input, test.wantOutput)
return
}
output, err := df.TransformCommon(raw)
if test.wantError {
require.Error(t, err)
} else {
require.Equal(t, test.wantOutput, output)
require.NoError(t, err)
}
})
}
}
type fakeSummaryCache struct {
summarizedObject *summary.SummarizedObject
relationships []summarycache.Relationship
}
func (f *fakeSummaryCache) SummaryAndRelationship(runtime.Object) (*summary.SummarizedObject, []summarycache.Relationship) {
return f.summarizedObject, f.relationships
}