Closed
Conversation
Signed-off-by: Ivan Milchev <ivan@mondoo.com>
Contributor
Signed-off-by: Ivan Milchev <ivan@mondoo.com>
Signed-off-by: Ivan Milchev <ivan@mondoo.com>
4 tasks
Member
Author
|
this is now included in #6949 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OptionStagedDiscoveryinproviders-sdk/v1/pluginso any provider can opt in to staged discoveryMotivation
K8s discovery currently runs everything in a single pass: cluster + all namespaces + all workloads in every namespace. For large clusters this is expensive and doesn't allow clients to control the discovery granularity.
Staged discovery lets clients discover cluster and namespaces first, then connect to individual namespaces to discover their workloads on demand. This enables:
Design
Toggle mechanism: The
plugin.OptionStagedDiscoverykey is set on the connection config's Options map. Providers check for its presence (not value) to decide which path to take.Stage routing: When staged discovery is enabled, the provider checks whether
OPTION_NAMESPACEis already set on the config:discoverClusterStage): returns cluster asset + namespace assets WITH platform IDs and discovery targets. Each namespace's connection config hasOPTION_NAMESPACEset.discoverNamespaceStage): returns only workloads for that namespace. The namespace asset was already emitted by stage 1.Legacy path: When
OptionStagedDiscoveryis absent (old clients),discoverLegacyruns the original single-pass logic unchanged.Changes
providers-sdk/v1/plugin/connection.go— AddedOptionStagedDiscoveryconstant, reusable across all providersproviders/k8s/resources/discovery.go— RefactoredDiscover()into three paths:discoverLegacy(),discoverClusterStage(),discoverNamespaceStage()cli/providers/providers.go— SetsOptionStagedDiscoveryon all connection configs from CLI commandsTest plan
mql run k8s -c "k8s.deployments { name namespace }"works identically to mainmql run k8s --discover namespaces -c "asset.name"returns namespacesmql run k8s --namespaces kube-system -c "k8s.pods { name }"works in both pathsgo test ./providers/k8s/...passes🤖 Generated with Claude Code