* Continue rebasing.
* Wrote unit tests for external associations.
* Fix the generated SQL.
Some syntactic sugar (capitalizing the keywords), but use the 'ON' syntax on JOINs.
* We want "management.cattle.io.projects:spec.displayName" not "...spec.clusterName"
* Implement hard-wired external associations:
* The table is in sqlproxy.proxy_store
- externalGVKDependencies - a map of GVKs to dependencies.
When the key GVK is updated, it triggers the updates in the database for the dependent GVKs,
replacing fields as specified in the table.
* This is done in an afterUpsert handler, but it's done after the transaction for the core
GVK update is finished, because most likely the dependent GVK updates will depend on the
final database values for the GVK being updated, and if we do it as part of the transaction
the new values won't be committed to the database.
* When an object is modified/created, check for external deps that need updating.
* Stop emitting errors when joining tables if one of the tables doesn't exist.
* Update unit test syntax for SQL queries.
* And an override check
This ensures we don't overwrite good data when
pulling data from one table to another.
* Drop labels, and use mgmt.cattle.io/spec.displayName
There's no need to hardwire labels in proxy_store:typeSpecificIndexedFields
because all labels are indexed in the shadow labels table.
* Keep clusterName, add displayName for mgmt.cattle.io
* Fix rebase/merge breakage.
* Finish the merge: add the 'selfUpdateInfo' param where it didn't get inserted during merge.
* Patch up rebase failures.
* Now gomock generates named args. I give up.
* Continue rebasing.
* Wrote unit tests for external associations.
* Fix the generated SQL.
Some syntactic sugar (capitalizing the keywords), but use the 'ON' syntax on JOINs.
* whitespace fix post rebase
* We want "management.cattle.io.projects:spec.displayName" not "...spec.clusterName"
* Fix the database calls: drop the key
* Fix breakage during automatic rebase merging gone wrong.
* ws fix - NFC
* Post rebase-merge fixes
* Fix rebase-driven merge.
* Fix rebase breakage.
* go-uber v0.5.2 prefers real arg names to '<argN>'
* Return watch error instead of logging it
The UI needs to know about watch error like `resourceversion too old` so
we need to return it.
* Sort by resourceVersion as number
The UI makes some assumption on resourceVersion. It assumes they are a
number and they are ordered by the number value. We'll want to fix this
at some point most likely but for now let's give something in a way that
UI wants.
* Remove -d suffix
After much testing, a delete of an object seems to have its own
resourceVersion so we don't need the -d suffix, we can simply use the
new resourceVersion.
* Add vai access-control for tokens.
* Check for both Token and Kubeconfig resources
* Add a unit test for verifying the generated filters for restricted resources.
* Remove a TODO comment as Tom points out we no longer need it.
* Return error if we can't get userinfo from apiOp.Request.Context
* Stop using camelCase for the user ID label.
* Add a test for the admin user.
* And fold the two user-access tests into a single parameterized test.
* Address reviewer comments.
* post-rebase merge fixes
* WIP - add a comment about determining admin users.
---------
Co-authored-by: Peter Matseykanets <peter.matseykanets@suse.com>
* Add ListOptionIndexerOptions to create ListOptionIndexer
* Remove unused function
* Implement configurable garbage collection on ListOptionIndexer
* Propagate Steve options from Server
* 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...
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.
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.
* 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.
* 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'.
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
* Add more fields to index when sql-caching is on.
* Restore the gvkKey helper, add event fields.
The UI team wasn't sure whether the event fields should go in the empty-string group or in 'events.k8s.io',
so let's go with both until/unless specified otherwise.
* More fixes to the fields to index:
- Remove the erroneously added management.cattle.io.nodes fields
- Use the builtin Event class, not events.k8s.io (by looking at the dashboard client code)
* Start on the virtual-field work.
* Map `Event.type` to `Event._type` for indexing.
* Add a unit test for field replacement for Event.type
* Add label processing.
* Don't test for transformation of event objects in the common module.
* Parse metadata.label queries differently.
* Improve a variable name that turned out to not be temporary.
* No need to specifically cache certain labels, as all are now cached.
* Add a test to verify simple label (m.labels.foo=blah) queries work.
* 'addLabelFields' never returns an error.
* Delete superseded function.
* Was calling 'addLabelFields' one time too many.
* Start using k8s ParseToRequirements
* Pull in the k8s parser.
* Successfully test for quotation marks.
* Add quoted strings to the lexer.
* Move to a forked k8s label lexer to include non-label tests.
* Improve and test the way quoted strings in the query are detected.
* Reinstate the original Apache license in the derived code.
Following clause 4.3 of the Apache license:
"You must cause any modified files to carry prominent notices stating that You changed the files..."
* Ignore case for operators.
* Test IN multiple-target-values
* Test the not-in operator.
* Ignore case for operators.
SQL is case-insensitive on field names and values, so this just adds consistency.
* Added tests for parsing EXISTS and NOT-EXISTS queries.
* Parse less-than and greater-than ops
* Lasso's `CacheFor` now takes a `watchable` argument.
* Support 'gt' and 'lt' as synonyms for '<' and '>'.
I see both types of operators being bandied about -- it's easy to support the aliases.
* typo fix
* Have the filter parser allow exist tests only on labels.
Also reduce the case where there's no namespace function.
* Specify hard-wired fields to index alphabetically.
* Remove unused variable.
* Parser: 'metadata.labels[FIELD]' is valid
* Pull in new gvk fields from main (and keep in alpha order).
* Fixed a couple of drops done during the last rebase.
* Add a reminder to keep the entries in alpha order.
* Test TransformLabels
* Remove TransformLabels
* Remove unused/unneeded code.
* Describe diffs between our label-selector parser and upstream's.
* Use the merged lasso 46333 work.
* Drop unused field.
* Tighten up the code.
* Specify which commit the label selector parser is based on.
* Allow both single-quoted and double-quoted value matching, doc difference.
* More review-driven changes:
- Stricter processing of m.l.name keys:
Require ending close-bracket for a start-bracket
- Comment fix
- Moving sql processing from lasso to steve: some changes missed in rebase
* Drop support for double-quotes for string values.
For now on only single-quotes (or none where possible) are allowed.
* Renaming and dropping an init block.
* Quoted strings are dropped from the filter queries
In particular, label values have a specific syntax: they must
start and end with a letter, and their innards may contain
only alnums '.', '-' and '_'. So there's no need for quoting.
And that means now that `=` and `==` do exact matches,
and the `~` operator does a partial match.
`!=` and `!~` negate -- note that `!~` is a stricter operation than `!=`,
in that given a set of possible string values, `!=` will accept more
of them than `!~`. Maybe I shouldn't have gone here, but these operators
reminded me of learning about `nicht durfen` and `nicht sollen` in German,
or something like that.
* Move a constant definition to the module level.
* Remove commented-out code.
* Remove unused func and adjacent redundant comment.
* Replace primary/secondary sort fields with an array of sort directives.
* Allow more than 2 sort-params in a search query.
* Add a virtual 'status.ready' field to clusters.
* Rename status.ready -> status.connected
* Set virtual field 'spec.internal' <- spec.displayName == 'local'
* Need to declare all virtual fields to index.
* Ready clusters have condition[type==Ready && status=True]
* Update the README to reflect generalized sorting.
* Bump lasso to get revised sort directives.
* Review-driven changes, mostly comments and drop unneeded code.
* Add unit tests to verify sort-order stringification.
* Ignore empty-string sort components.
* Fix a rebase mishap.
* Drop unneeded commented-out code.
* Clusters have a 'spec.internal' field, no need to synthesize one.
* Added a note on square-brackets for label references.
This should be added to the README for filter queries in the PR for 46333.
* Bump to latest sqlcache-free lasso
* bump lasso to include pull #111
Signed-off-by: Silvio Moioli <silvio@moioli.net>
* Make IsListWatchable public to be reused in other packages
Signed-off-by: Silvio Moioli <silvio@moioli.net>
* Let lasso know whether a type is watchable upon requesting a cache
Signed-off-by: Silvio Moioli <silvio@moioli.net>
* Adapt existing tests
Signed-off-by: Silvio Moioli <silvio@moioli.net>
* Add a test to check watchability is detected correctly
Signed-off-by: Silvio Moioli <silvio@moioli.net>
---------
Signed-off-by: Silvio Moioli <silvio@moioli.net>
* 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.
* added namespace check to proxy_store create
* added namespaced resources checks and create tests
* Update pkg/stores/proxy/proxy_store.go
* changed error message and added missing name only test
* updated sql/proxy_store
* changed return to use apierror.NewAPIError
---------
Co-authored-by: Felipe C. Gehrke <felipe@localhost.localdomain>
Co-authored-by: Tom Lebreux <tom.lebreux@suse.com>
Adds logic which adds virtual fields resources. This allows these fields
to be sorted/filtered on when the SQL cache is enabled. Id and
metadata.state.name were added as the first two fields.
This uses SQLite-backed informers provided by Lasso with https://github.com/rancher/lasso/pull/65 to implement Steve API (/v1/) functionality.
This new functionality is available behind a feature flag to be specified at Steve startup
See https://confluence.suse.com/pages/viewpage.action?pageId=1359086083
Co-authored-by: Ricardo Weir <ricardo.weir@suse.com>
Co-authored-by: Michael Bolot <michael.bolot@suse.com>
Co-authored-by: Silvio Moioli <silvio@moioli.net>
Signed-off-by: Silvio Moioli <silvio@moioli.net>