-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat: Use PartialObjectMetadata for Configmaps #2468
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mrueg The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
1231b8b
to
4d9ee4b
Compare
We can't use partialobjectmetadata for secrets unfortunately, since we have metrics for the secrets type that we expose. |
d479370
to
cd9a7c2
Compare
151ede1
to
a08c6b8
Compare
Secret supports I wonder if we could make a sort of informer that does a metadata-only watch per known Secret type, plus one that watches for unknown types and doesn't use partial object metadata. Should be quite a bit more efficient overall, at the cost of turning one watch into n. |
/assign |
I still lack seeing the hoped memory improvements with this PR.
|
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.
Few comments, but I am a fan of this change! :)
@@ -541,6 +561,46 @@ func (b *Builder) buildStores( | |||
return stores | |||
} | |||
|
|||
func (b *Builder) buildMetadataOnlyStores( |
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 might be missing something, but it seems you could call buildStores
right away since this is an exact copy of its code.
Going even further, maybe we don't even need buildMetadataOnlyStores
and could just call buildStores
directly when building resource specific stores like:
- return b.buildStoresFunc(configMapMetricFamilies(b.allowAnnotationsList["configmaps"], b.allowLabelsList["configmaps"]), &v1.ConfigMap{}, createConfigMapListWatch, b.useAPIServerCache)
+ return b.buildStoresFunc(configMapMetricFamilies(b.allowAnnotationsList["configmaps"], b.allowLabelsList["configmaps"]), &metav1.PartialObjectMetadata{}, createConfigMapListWatch, b.useAPIServerCache)
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 reason I created that is the different signature of the listWatchFunc (using metadata.Interface not clientset.Interface). Is there's a different way to do that, I'm all ears :)
} | ||
} | ||
config.UserAgent = fmt.Sprintf("%s/%s (%s/%s) kubernetes/%s", "kube-state-metrics (metadataonly)", version.Version, runtime.GOOS, runtime.GOARCH, version.Revision) | ||
config.AcceptContentTypes = "application/vnd.kubernetes.protobuf;as=PartialObjectMetadataList;g=meta.k8s.io;v=v1,application/json;as=PartialObjectMetadataList;g=meta.k8s.io;v=v1,application/json,application/vnd.kubernetes.protobuf;as=PartialObjectMetadata;g=meta.k8s.io;v=v1,application/json;as=PartialObjectMetadata;g=meta.k8s.io;v=v1" |
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.
Do we really need to do that ourselves? The client seems to already set the Accept header accordingly: https://github.com/kubernetes/kubernetes/blob/0b3b733c8437a946b7300a346ac948fec2e0b3ff/staging/src/k8s.io/client-go/metadata/metadata.go#L222
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.
This was mainly copying from the CreateKubeClient() func, I'm not sure if we need it here additionally.
Will metadata.List()/Watch() be called eventually or is that overwritten by ListWatchFunc?
Great to hear! I'm still looking for better ideas to verify that it saves network traffic and reduces memory consumption on ksm. |
487fc1f
to
ebbecee
Compare
ebbecee
to
e1da6f6
Compare
e1da6f6
to
722a81c
Compare
722a81c
to
f2135e1
Compare
What this PR does / why we need it:
This PR introduces a metadataonly client, which can be used to fetch sparse data for large objects like configmaps.
How does this change affect the cardinality of KSM: (increases, decreases or does not change cardinality)
None
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #2463