-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[receiver/k8scluster] Add support for observing multiple namespaces #40220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[receiver/k8scluster] Add support for observing multiple namespaces #40220
Conversation
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feature makes sense to me and the code-changes look mostly good from my perspective. I would be fine making this feature happen if other code-owners do not have any concern with this.
@povilasv @TylerHelmuth @dmitryax please a look when you get the chance. |
Co-authored-by: Christos Markou <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
if len(namespaces) == 1 { | ||
// if there is only ony namespace in the provided namespaces array, use the deprecated field to still cover the code related to that | ||
config.Namespace = namespaces[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really sure if this is needed? Why use old field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left that here for now to still cover the deprecated field in the tests as well, until it is removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we need to do it, since we want to remove it in future, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes probably, since it's going to be removed anyway I will update the PR to remove that
return nil | ||
var job any | ||
var err error | ||
exists := false | ||
|
||
// first, check if there is a store for all namespaces | ||
if jobStore, ok := jobStores[""]; ok { | ||
job, exists, err = jobStore.GetByKey(utils.GetIDForCache(pod.Namespace, jobRef.Name)) | ||
if err != nil { | ||
logError(err, jobRef, pod.UID, logger) | ||
return nil | ||
} | ||
} | ||
if !exists { | ||
// check if there is a store for the namespace of the pod | ||
if jobStore, ok := jobStores[pod.Namespace]; ok { | ||
job, exists, err = jobStore.GetByKey(utils.GetIDForCache(pod.Namespace, jobRef.Name)) | ||
if err != nil { | ||
logError(err, jobRef, pod.UID, logger) | ||
return nil | ||
} | ||
} | ||
if !exists { | ||
logDebug(jobRef, pod.UID, logger) | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this logic be abstracted away somehow into one method?
as we are repeating it on all stores
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i now moved that logic into the internal/utils
package, along with some tests for it
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Description
This PR adapts the k8scluster receiver to support retrieving resources from multiple namespaces.
Due to the way the informer stores are maintained internally the required changes for this feature are more complex than anticipated: previously, as there was only the option to either observe all namespaces, or only one, there was one informer per GVK, whose store was used to regularly collect the metrics for the observed resources. Now, as the informers provided by the k8s library can only observe either one, or all namespaces, we can potentially have multiple informers per namespace for the same GVK. This is now done as a
map[GVK]map[string]informer.Store
, where the string represents the namespace.Link to tracking issue
Fixes #40089
Testing
Added unit tests and a new e2e test
Documentation
Adapted readme to describe the added option