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
k8s: Split SharedResources into binary specific cells #25757
k8s: Split SharedResources into binary specific cells #25757
Conversation
56663a9
to
9484f01
Compare
pkg/k8s/resource_ctors.go
Outdated
return resource.New[*cilium_api_v2.CiliumIdentity](lc, lw), nil | ||
} | ||
|
||
func CiliumNetworkPolicy(lc hive.Lifecycle, cs client.Clientset, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumNetworkPolicy], error) { |
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 wonder if it'd make sense to namespace these by package, e.g. pkg/k8s/resources
and then we'd have resources.CiliumNetworkPolicy
, or by the suffix (NamespaceResource
). I think either is probably fine and I do like having k8s
in the package name. If you go the suffix route, then let's add it to these Cilium*
functions here.
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.
Added the Resource
suffix where missing.
81ce31d
to
d5fa5d5
Compare
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.
My codeowners look good to me.
It might be a naive question, but why do we even need the per-binary packages? Can't there be something like cell.LazyProvide
that only executes the constructor if it's actually requested by a dependency?
I think it'd be a reasonable alternative for the current usage of the resources, even if keeping a single cell would not allow to customize each resource events stream when consumed by multiple binaries. |
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.
Looks good to me from ClusterMesh's perspective.
"Clustermesh-apiserver Kubernetes resources", | ||
|
||
cell.Provide( | ||
k8s.ServiceResource, |
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 think we need CiliumNode, Endpoints, and CiliumEndpoint resources, but they are currently using the legacy clientset
. Approving with the understanding that they will be followed up at some point.
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.
Yep, there is already work in progress to port other resources to the new resource.Resource[T]
framework.
/test Job 'Cilium-PR-K8s-1.26-kernel-net-next' failed: Click to show.Test Name
Failure Output
Jenkins URL: https://jenkins.cilium.io/job/Cilium-PR-K8s-1.26-kernel-net-next/356/ If it is a flake and a GitHub issue doesn't already exist to track it, comment Then please upload the Jenkins artifacts to that issue. |
Add the "Resource" suffix to the CNP, CCNP and CCG resources constructors to uniform the methods naming. Signed-off-by: Fabio Falzoi <fabio.falzoi@isovalent.com>
Use functional options pattern to customize k8s resources constructors with option modifiers. This pattern allows to expose a base constructor that is easily customizable with modifiers like labels-based objects filtering. This is helpful to customize the events stream for a given resource that is used by multiple binaries, like the agent and the operator. Signed-off-by: Fabio Falzoi <fabio.falzoi@isovalent.com>
Split SharedResources cell into multiple cells, one for each binary relying on k8s resources (agent, operator and clustermesh-apiserver). Each binary depends only on the specific resources that it actually uses, and it customizes each resource events stream based on its own specific needs. Signed-off-by: Fabio Falzoi <fabio.falzoi@isovalent.com>
The SharedResources cell has been split into multiple binary-specific cells, so change the name of the daemon params and k8s watchers fields accordingly. Signed-off-by: Fabio Falzoi <fabio.falzoi@isovalent.com>
d5fa5d5
to
303787d
Compare
Force-pushed to solve a conflict in |
/test |
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
Split the SharedResources cell into multiple cells, one for each binary (agent, operator and clustermesh-apiserver).
This improves the dependencies management, since each binary will depend only on the k8s resources that it actually uses.
Also, the functional options pattern is introduced to give more flexibility when customizing a resource events stream.
Notes for the reviewers: review commit by commit might be simpler. The last commit is the one responsible for the high number of files modified, but it is just a rename (
sharedResources
->resources
) after the removal of the single SharedResources cell.Fixes #24070