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

When kooper operates K8S object resources, can it be retrieved from the cache instead? #76

Closed
AllenZMC opened this issue Aug 1, 2019 · 10 comments

Comments

@AllenZMC
Copy link

AllenZMC commented Aug 1, 2019

When kooper operates K8S object resources, it can be retrieved from the cache instead of directly accessing k8s. This allows quick access to k8s objects.

@slok
Copy link
Collaborator

slok commented Aug 2, 2019

Hi @AllenZMC!

When you say retrieve what do you mean? when do you retrieve objects with kooper?, the object that you receive from kooper on each reconciliation loop iteration, is retrieved from the cache, and these objects are only updated when changes happen (that's the watcher purpose), the lister is used on start to get the initial full list of objects.

@AllenZMC
Copy link
Author

AllenZMC commented Aug 2, 2019

Hi @slok . See the following code. Is the operation to get the configmap obtained from the cache or directly access k8s etcd? (I use kooper in my operator)
Because getting resources such as pods or configmap from the cache is faster, which can reduce the pressure of etcd.

configMap, err := p.kubeClient.CoreV1().ConfigMaps(namespace).Get(name, metav1.GetOptions{})

@slok
Copy link
Collaborator

slok commented Aug 2, 2019

Where is that line?

@AllenZMC
Copy link
Author

AllenZMC commented Aug 2, 2019

This code is in spotahome/redis-operator

@AllenZMC
Copy link
Author

AllenZMC commented Aug 2, 2019

I hope to quickly access the k8s resources such as pod, configmap, etc. in the operator.

@AllenZMC
Copy link
Author

AllenZMC commented Aug 2, 2019

Obtaining k8s resources such as pods and configmaps from the cache is faster than directly accessing etcd

@slok
Copy link
Collaborator

slok commented Aug 2, 2019

oh, I understand now what do you mean.

That's business logic of the operator, not the operator framework itself, Kooper has nothing to do with that, Kooper maintains a reconciliation loop on specific resources, these resources are the ones that trigger the iteration handling of that resource changes, and this handling code is logic of the application (in this case the redis operator logic), so... the app should maintain it's own cache on the resources it wants.

Imagine those other resources as regular resources of any kind, a database query, a query to AWS API, a query to K8s API... whatever, Kooper is out of that scope of these resources.

Kooper caches the resources on what the reconciliation loop is based on, in this case, the RedisFailover CRDs, if the iteration logic needs to access to different resources (Redis commands, other Kubernetes resources, database access...) is part of the app, and is out of the scope of Kooper and the responsibility is on the app implementation.

@AllenZMC
Copy link
Author

AllenZMC commented Aug 2, 2019

OK, thanks.

@slok
Copy link
Collaborator

slok commented Aug 2, 2019

Apart from that, Kooper only retrieves the resources it is subscribed to, so it will only cache those ones, so if my operator is based on pods, and when handling each pod log it access an ingress, Kooper cache will not have ingresses. So in case you could access the cache, the resources would not be stored there.

@slok
Copy link
Collaborator

slok commented Aug 2, 2019

Can I close the issue? or do you have more questions regarding this (or maybe I didn't explain correctly 😞)

@AllenZMC AllenZMC closed this as completed Aug 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants