1
0
mirror of https://github.com/rancher/steve.git synced 2025-06-29 16:27:15 +00:00
Commit Graph

20 Commits

Author SHA1 Message Date
Tom Lebreux
e3f207ddc2
Add basic watch functionality for SQL cache (#653)
* Remove unused method

* Add basic watch functionality

* Remove TestWatchNamesErrReceive test
2025-06-03 18:07:18 -04:00
Tom Lebreux
2672969496
Add object to RegisterAfterDelete and introduce RegisterAfterDeleteAll (#649)
* Add object to AfterDelete callbacks

* Add RegisterAfterDeleteAll
2025-06-03 17:32:43 -04:00
Tom Lebreux
a8f3ce48d6
Convert tests to real SQL store (#652) 2025-06-02 16:01:45 -06:00
Tom Lebreux
55a1b940a0
Split RegisterAfterUpsert into RegisterAfterAdd and RegisterAfterUpdate (#644)
* Split RegisterAfterUpsert into two

We're going to need to be able to differentiate between Add and Update
for storing events in the _events table.

* Update mocks
2025-05-30 08:25:12 -04:00
Tom Lebreux
cb0d9d6d54
Remove limit and continue param for SQL cache (#643) 2025-05-27 09:53:10 -04:00
Tom Lebreux
1e5018e31a
Fix returning error for empty ingresses.spec.rules.host (#642)
* Fix returning error for empty ingresses.spec.rules.host

* Fix error format

* Use require instead of assert
2025-05-20 16:14:19 -04:00
Eric Promislow
57ce685118
Sort-indirect PR broken into smaller parts: part 3/6 - pass listOptions by reference (#612)
* Move types related to list options and sql queries into their own package.

The problem having these in the informer package is that eventually code
in other packages will need to import `informer` only for constants or types,
but some members of the informer package may already depend on those. Best to
move type definitions into their own simpler package.

* Fix the ListOptions sort field.

Instead of making it a single array-ish field, convert it into a
true array of Sort Directives.  Easier to read, less bending backwards.

* Pass the listOptions struct by reference to avoid copying.

We never update the ListOptions struct once it's created so there's
no need to pass it by value.

This might be a near-useless optimization...
2025-04-25 11:19:34 -07:00
Eric Promislow
89268ba86b
Sort-indirect PR broken into smaller parts: part 2/6 - fix the Sort part of ListOptions (#611)
* Move types related to list options and sql queries into their own package.

The problem having these in the informer package is that eventually code
in other packages will need to import `informer` only for constants or types,
but some members of the informer package may already depend on those. Best to
move type definitions into their own simpler package.

* Fix the ListOptions sort field.

Instead of making it a single array-ish field, convert it into a
true array of Sort Directives.  Easier to read, less bending backwards.

* Rebasing (or human error) duplicated 'NewSortList'.
2025-04-25 10:15:20 -07:00
Eric Promislow
2b227dbd22
Move types related to list options and sql queries into their own package. (#610)
The problem having these in the informer package is that eventually code
in other packages will need to import `informer` only for constants or types,
but some members of the informer package may already depend on those. Best to
move type definitions into their own simpler package.
2025-04-25 09:11:09 -07:00
Eric Promislow
f486902100
Add support for another field: (#532)
provisioning.cattle.io.clusters\
metadata.annotations[provisioning.cattle.io/management-cluster-display-name]

Needed to add another character to the subfieldRegex in
listoption_indexer to allow hyphens in annotation field names.
2025-03-05 12:53:59 -08:00
Eric Promislow
2711fd1f46
Added more fields - part 6. (#485)
* Added more fields - part 6.

* Tweaks needed to get 'batch.cronjobs' working

* Add a clarifying comment on pulling values out of an array.

* Use the correct capitalization for the etcd-snapshot kind.
2025-03-04 09:31:21 -08:00
Eric Promislow
0edba0da3e
Sort labels (#527)
* Support sorting on metadata.labels.NAME

The key to doing this is if we want to sort on, say, `metadata.labels.foo`, we need to
search for all rows with a label of the name `foo` in all the various
join tables we create for each label the query references.

We ignore nulls by giving them lowest priority using "NULLS LAST"
("NULLS FIRST" if sorting in descending order).

* Ensure labels that are mentioned only in sort params are still selected.

If we don't do this -- say we sort on metadata.labels.foo but never
make a test on it, the sort resuilts are ignored.

* Remove extraneous debugger statements.
2025-03-04 09:30:14 -08:00
Eric Promislow
3b45729415
Generate field names with brackets when needed. (#477)
* Generate field names with brackets when needed.

* Stop hard-wiring complex selectors as `["field1", "field2[sub-field3]"]`

and instead represent them as a more consistent `["field1", "field2", "sub-field3"]`

* Convert all filter strings ending with square brackets to an array.

Stop special-casing 'metadata.labels[X]' and handle any query string that ends with '[...]'.

* Stop checking for pre-bracketed terms in constant field-accessor arrays.

In this commit we stop converting string arrays like
`["metadata", "labels[k8s.io/deepcode]"]` into the database field
`"metadata.labels[k8s.io/deepcode]"` and instead will do a
naive `join` to give `metadata[labels[k8s.io/deepcode]]`.  The solution
is to never express the above terms in separate fields, like
`["metadata", "labels", "k8s.io/deepcode"]`. This also better reflects
the stucture of the referenced object.

* gofmt changes

* Simplify comment about 'smartJoin'.
2025-02-25 10:39:29 -08:00
Eric Promislow
c906c36bc3
support unwatchables in vai (#458)
* Create and use a synthetic watcher for non-watchable resources.

* Write unit tests for the synthetic watcher.

* Make the refresh interval for synthetic watchers configurable.

The default is to call `client.List(...)` every 5 seconds for each unwatchable GVK.

There are currently only 3 such GVKs right now so this will be informative
enough but not really noticeable.

* Pass the context into the synthetic watch func.

* Restore changes lost in rebasing.

---------

Co-authored-by: Tom Lebreux <tom.lebreux@suse.com>
2025-02-20 12:45:58 -08:00
Silvio Moioli
3350323f91
sql: propagate and use contexts (#465)
Previous SQLite-related code used context.Background() and context.TODO() because it was not developed with context awareness.

This commit propagates the main Steve context so that it can be used when interacting with SQL context-aware functions.

This PR removes all production-code use of context.Background() and context.TODO() and replaces test-code use of TODO with Background.

Contributes to rancher/rancher#47825
2025-02-12 09:46:10 +01:00
Silvio Moioli
9139e492e0
vai: do not discard closing statement errors (#462) 2025-02-07 08:31:08 +01:00
Silvio Moioli
772dc7577e
sql: use a closure to wrap transactions (#469)
This introduces the a `WithTransaction` function, which is then used for all transactional work in Steve.

Because `WithTransaction` takes care of all `Begin`s, `Commit`s and `Rollback`s, it eliminates the problem where forgotten open transactions can block all other operations (with long stalling and `SQLITE_BUSY` errors).

This also:

- merges together the disparate `DBClient` interfaces in one only `db.Client` interface with one unexported non-test implementation. I found this much easier to follow
- refactors the transaction package in order to make it as minimal as possible, and as close to the wrapped `sql.Tx` and `sql.Stmt` functions as possible, in order to reduce cognitive load when working with this part of the codebase
- simplifies tests accordingly
- adds a couple of known files to `.gitignore`
    
Credits to @tomleb for suggesting the approach: https://github.com/rancher/lasso/pull/121#pullrequestreview-2515872507
2025-02-05 10:05:52 +01:00
Silvio Moioli
6a46a1e091
sql: encrypt Tokens by default (#467)
Co-authored-by: Eric Promislow <epromislow@suse.com>
2025-02-03 09:12:02 +01:00
Silvio Moioli
ae4153b712
vai: document resync period (#463) 2025-01-28 09:02:38 +01:00
Tom Lebreux
9dd9b0f625
Move lasso SQL cache in Steve (#452)
* Copy pkg/cache/sql from lasso to pkg/sqlcache

* Rename import from github.com/rancher/lasso/pkg/cache/sql to github.com/rancher/steve/pkg/sqlcache

* Fix filter.Match -> filter.Matches

* go mod tidy

* Fix lint errors

* Remove lasso SQL cache mentions

* Fix more CI lint errors

* fix goimports

Signed-off-by: Silvio Moioli <silvio@moioli.net>

* fix tests (Match -> Matches)

Signed-off-by: Silvio Moioli <silvio@moioli.net>

* Fix Sort order

---------

Signed-off-by: Silvio Moioli <silvio@moioli.net>
Co-authored-by: Silvio Moioli <silvio@moioli.net>
2025-01-17 09:34:48 -05:00