Skip to content
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

get calls are causing many requests #251

Closed
benedikt-bartscher opened this issue Dec 13, 2023 · 2 comments · Fixed by #252
Closed

get calls are causing many requests #251

benedikt-bartscher opened this issue Dec 13, 2023 · 2 comments · Fixed by #252
Labels
bug Something isn't working

Comments

@benedikt-bartscher
Copy link
Contributor

Which project are you reporting a bug for?

kr8s

What happened?

Every get call with kr8s seems to fetch all crd endpoints once. Even if i use the Secret object directly. Is this intended behaviour?

>>> import logging
>>> from kr8s.objects import Secret
>>> logging.basicConfig(level=logging.INFO)
>>> Secret.get("regcred")
INFO:httpx:HTTP Request: GET https://8.8.8.8/api/ "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/api/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/ "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/acid.zalan.do/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/acme.cert-manager.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/admissionregistration.k8s.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/agent.k8s.elastic.co/v1alpha1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/apiextensions.k8s.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/apiregistration.k8s.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/apm.k8s.elastic.co/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/apps/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/authentication.k8s.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/authorization.k8s.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/autoscaling/v2 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/autoscaling.k8s.elastic.co/v1alpha1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/batch/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/beat.k8s.elastic.co/v1beta1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/cert-manager.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/certificates.k8s.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/cilium.io/v2 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/clusterctl.cluster.x-k8s.io/v1alpha3 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/coordination.k8s.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/discovery.k8s.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/elasticsearch.k8s.elastic.co/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/enterprisesearch.k8s.elastic.co/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/events.k8s.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/external-secrets.io/v1beta1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/flowcontrol.apiserver.k8s.io/v1beta3 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/flux.kluctl.io/v1alpha1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/generators.external-secrets.io/v1alpha1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/gitops.kluctl.io/v1beta1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/grafana.integreatly.org/v1beta1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/helm.toolkit.fluxcd.io/v2beta1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/kibana.k8s.elastic.co/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/kustomize.toolkit.fluxcd.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/logstash.k8s.elastic.co/v1alpha1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/maps.k8s.elastic.co/v1alpha1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/mariadb.mmontes.io/v1alpha1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/metrics.k8s.io/v1beta1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/minio.min.io/v2 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/monitoring.coreos.com/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/networking.k8s.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/node.k8s.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/notification.toolkit.fluxcd.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/policy/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/rbac.authorization.k8s.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/redhatcop.redhat.io/v1alpha1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/scheduling.k8s.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/secrets.hashicorp.com/v1beta1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/source.toolkit.fluxcd.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/stackconfigpolicy.k8s.elastic.co/v1alpha1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/storage.k8s.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/sts.min.io/v1alpha1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/vault.banzaicloud.com/v1alpha1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/apis/velero.io/v1 "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://8.8.8.8/api/v1/namespaces/pgadmin/secrets "HTTP/1.1 200 OK"
<Secret regcred>

Anything else?

No response

@benedikt-bartscher benedikt-bartscher added the bug Something isn't working label Dec 13, 2023
@jacobtomlinson
Copy link
Member

jacobtomlinson commented Dec 14, 2023

This many calls is definitely not intended. We look up all of the API resources so that we can expand shortnames in calls like kr8s.get("po"). I think there are two separate things here we might want to fix:

  • Calling APIObject.get() shouldn't look up short names at all
  • Listing resources should be cached for some period of time (kubectl get does this to reduce the number of calls)

@jacobtomlinson
Copy link
Member

I've just merged #252 which fixes this specific problem.

>>> import logging
>>> from kr8s.objects import Pod
>>> logging.basicConfig(level=logging.INFO)
>>> Pod.get("test-pod")
INFO:httpx:HTTP Request: GET https://127.0.0.1:43613/api/v1/namespaces/foo/pods "HTTP/1.1 200 OK"
<Pod test-pod>

I've also raised #253 to track caching these requests better in situations where we do actually want to call them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants