diff --git a/pkg/controller/instance/instance_controller.go b/pkg/controller/instance/instance_controller.go index 71a0906fb..be4dda246 100644 --- a/pkg/controller/instance/instance_controller.go +++ b/pkg/controller/instance/instance_controller.go @@ -67,34 +67,33 @@ type Reconciler struct { // SetupWithManager registers this reconciler with the controller manager func (r *Reconciler) SetupWithManager( mgr ctrl.Manager) error { - addOvRelatedInstancesToReconcile := handler.ToRequestsFunc( - func(obj handler.MapObject) []reconcile.Request { - requests := make([]reconcile.Request, 0) - instances := &kudoapi.InstanceList{} - // we are listing all instances here, which could come with some performance penalty - // obj possible optimization is to introduce filtering based on operatorversion (or operator) - err := mgr.GetClient().List( - context.TODO(), - instances, - ) - if err != nil { - log.Printf("InstanceController: Error fetching instances list for operator %v: %v", obj.Meta.GetName(), err) - return nil - } - for _, instance := range instances.Items { - // we need to pick only those instances, that belong to the OperatorVersion we're reconciling - if instance.Spec.OperatorVersion.Name == obj.Meta.GetName() && - instance.OperatorVersionNamespace() == obj.Meta.GetNamespace() { - requests = append(requests, reconcile.Request{ - NamespacedName: types.NamespacedName{ - Name: instance.Name, - Namespace: instance.Namespace, - }, - }) - } + addOvRelatedInstancesToReconcile := func(obj client.Object) []reconcile.Request { + requests := make([]reconcile.Request, 0) + instances := &kudoapi.InstanceList{} + // we are listing all instances here, which could come with some performance penalty + // obj possible optimization is to introduce filtering based on operatorversion (or operator) + err := mgr.GetClient().List( + context.TODO(), + instances, + ) + if err != nil { + log.Printf("InstanceController: Error fetching instances list for operator %v: %v", obj.GetName(), err) + return nil + } + for _, instance := range instances.Items { + // we need to pick only those instances, that belong to the OperatorVersion we're reconciling + if instance.Spec.OperatorVersion.Name == obj.GetName() && + instance.OperatorVersionNamespace() == obj.GetNamespace() { + requests = append(requests, reconcile.Request{ + NamespacedName: types.NamespacedName{ + Name: instance.Name, + Namespace: instance.Namespace, + }, + }) } - return requests - }) + } + return requests + } return ctrl.NewControllerManagedBy(mgr). // Owns(&kudoapi.Instance{}) is equivalent to Watches(&source.Kind{Type: }, @@ -112,7 +111,7 @@ func (r *Reconciler) SetupWithManager( Owns(&appsv1.StatefulSet{}). Owns(&corev1.Pod{}). WithEventFilter(eventFilter()). - Watches(&source.Kind{Type: &kudoapi.OperatorVersion{}}, &handler.EnqueueRequestsFromMapFunc{ToRequests: addOvRelatedInstancesToReconcile}). + Watches(&source.Kind{Type: &kudoapi.OperatorVersion{}}, handler.EnqueueRequestsFromMapFunc(addOvRelatedInstancesToReconcile)). Complete(r) } @@ -137,7 +136,7 @@ func eventFilter() predicate.Funcs { } func isForPipePod(e event.DeleteEvent) bool { - return e.Meta.GetAnnotations() != nil && funk.Contains(e.Meta.GetAnnotations(), task.PipePodAnnotation) + return e.Object.GetAnnotations() != nil && funk.Contains(e.Object.GetAnnotations(), task.PipePodAnnotation) } // Reconcile is the main controller method that gets called every time something about the instance changes @@ -166,7 +165,7 @@ func isForPipePod(e event.DeleteEvent) bool { // +-------------------------------+ // // Automatically generate RBAC rules to allow the Controller to read and write Deployments -func (r *Reconciler) Reconcile(request ctrl.Request) (ctrl.Result, error) { +func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) { // ---------- 1. Query the current state ---------- log.Printf("InstanceController: Received Reconcile request for instance %s", request.NamespacedName) diff --git a/pkg/controller/operator/operator_controller.go b/pkg/controller/operator/operator_controller.go index 1954117ab..ea186fc1a 100644 --- a/pkg/controller/operator/operator_controller.go +++ b/pkg/controller/operator/operator_controller.go @@ -43,10 +43,10 @@ func (r *Reconciler) SetupWithManager( // Reconcile reads that state of the cluster for an Operator object and makes changes based on the state read // and what is in the Operator.Spec // Automatically generate RBAC rules to allow the Controller to read and write Deployments -func (r *Reconciler) Reconcile(request ctrl.Request) (ctrl.Result, error) { +func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) { // Fetch the operator operator := &kudoapi.Operator{} - err := r.Get(context.TODO(), request.NamespacedName, operator) + err := r.Get(ctx, request.NamespacedName, operator) if err != nil { if errors.IsNotFound(err) { // Object not found, return. Created objects are automatically garbage collected. diff --git a/pkg/controller/operatorversion/operatorversion_controller.go b/pkg/controller/operatorversion/operatorversion_controller.go index c734818f9..853be734e 100644 --- a/pkg/controller/operatorversion/operatorversion_controller.go +++ b/pkg/controller/operatorversion/operatorversion_controller.go @@ -44,10 +44,10 @@ func (r *Reconciler) SetupWithManager( // and what is in the OperatorVersion.Spec. // // Automatically generate RBAC rules to allow the Controller to read and write Deployments -func (r *Reconciler) Reconcile(request ctrl.Request) (ctrl.Result, error) { +func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) { // Fetch the operator version operatorVersion := &kudoapi.OperatorVersion{} - err := r.Get(context.TODO(), request.NamespacedName, operatorVersion) + err := r.Get(ctx, request.NamespacedName, operatorVersion) if err != nil { if errors.IsNotFound(err) { // Object not found, return. Created objects are automatically garbage collected. diff --git a/pkg/engine/task/podexec/pod_exec.go b/pkg/engine/task/podexec/pod_exec.go index b6e9daed5..e15960308 100644 --- a/pkg/engine/task/podexec/pod_exec.go +++ b/pkg/engine/task/podexec/pod_exec.go @@ -64,6 +64,7 @@ func (pe *PodExec) Run() error { Version: "v1", Kind: "pods", }, + false, pe.RestCfg, codec) if err != nil {