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

reconcile, Filter daemon-sets and deployments to controlled namespace #978

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func add(mgr manager.Manager, r *ReconcileNetworkAddonsConfig) error {
// Create custom predicate for NetworkAddonsConfig watcher. This makes sure that Status field
// updates will not trigger reconciling of the object. Reconciliation is trigger only if
// Spec fields differ.
pred := predicate.Funcs{
crPred := predicate.Funcs{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Predicates are filtering on the client level, we are still getting all the Pods streamed from the API server.

We should either register the cache to only watch a specific namespace using https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/manager/manager.go#L188. But with this I'm not sure whether we can limit only part of the operator.

If the option above is not possible, we may want to use new Quique's option to filter on cache: kubernetes-sigs/controller-runtime#1435

Copy link
Collaborator Author

@oshoval oshoval Aug 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried the first option #981
the only tests that are failing are the ones that deploy nmstate on different namespace (nmstate ns) because it can't find them,
its a no go then ?
or its safe to require that no other component is installed ?
https://prow.ci.kubevirt.io/view/gs/kubevirt-prow/pr-logs/pull/kubevirt_cluster-network-addons-operator/981/pull-e2e-cluster-network-addons-operator-workflow-k8s/1429820891172179968

there is also this failure but i don't think its related
https://prow.ci.kubevirt.io/view/gs/kubevirt-prow/pr-logs/pull/kubevirt_cluster-network-addons-operator/981/pull-e2e-cluster-network-addons-operator-nmstate-functests/1429820891654524928

maybe we can change the namespace of the external nmstate to be in the real namespace ? or its not good

if we don't want this approach we need to bump controller-runtime and check the 2nd approach,
there as well we would need to filter according all the app labels of the components that we want to watch, because we can't predict the namespaces where it will be deployed

UpdateFunc: func(e event.UpdateEvent) bool {
oldConfig, err := runtimeObjectToNetworkAddonsConfig(e.ObjectOld)
if err != nil {
Expand All @@ -148,10 +148,10 @@ func add(mgr manager.Manager, r *ReconcileNetworkAddonsConfig) error {
}

// Watch for changes to primary resource NetworkAddonsConfig
if err := c.Watch(&source.Kind{Type: &cnaov1alpha1.NetworkAddonsConfig{}}, &handler.EnqueueRequestForObject{}, pred); err != nil {
if err := c.Watch(&source.Kind{Type: &cnaov1alpha1.NetworkAddonsConfig{}}, &handler.EnqueueRequestForObject{}, crPred); err != nil {
return err
}
if err := c.Watch(&source.Kind{Type: &cnaov1.NetworkAddonsConfig{}}, &handler.EnqueueRequestForObject{}, pred); err != nil {
if err := c.Watch(&source.Kind{Type: &cnaov1.NetworkAddonsConfig{}}, &handler.EnqueueRequestForObject{}, crPred); err != nil {
return err
}

Expand All @@ -161,12 +161,27 @@ func add(mgr manager.Manager, r *ReconcileNetworkAddonsConfig) error {
return err
}

pred := predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool {
return r.namespace == e.Meta.GetNamespace()
},
DeleteFunc: func(e event.DeleteEvent) bool {
return r.namespace == e.Meta.GetNamespace()
},
GenericFunc: func(e event.GenericEvent) bool {
return r.namespace == e.Meta.GetNamespace()
},
UpdateFunc: func(e event.UpdateEvent) bool {
return r.namespace == e.MetaNew.GetNamespace()
},
}

// Watch for changes on DaemonSet and Deployment resources
err = c.Watch(&source.Kind{Type: &appsv1.DaemonSet{}}, &handler.EnqueueRequestForObject{})
err = c.Watch(&source.Kind{Type: &appsv1.DaemonSet{}}, &handler.EnqueueRequestForObject{}, pred)
if err != nil {
return err
}
err = c.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForObject{})
err = c.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForObject{}, pred)
if err != nil {
return err
}
Expand Down