Skip to content

Commit

Permalink
Revert "Filter subscriber reconciler events (#18660)" (#18694)
Browse files Browse the repository at this point in the history
This reverts commit 9470fb8.
  • Loading branch information
WVerlaek authored Sep 11, 2023
1 parent 2ae927a commit 2ac4919
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 44 deletions.
16 changes: 0 additions & 16 deletions components/ws-manager-api/go/crd/v1/workspace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,6 @@ type PortSpec struct {
Protocol PortProtocol `json:"protocol"`
}

func (ps PortSpec) Equal(other PortSpec) bool {
if ps.Port != other.Port {
return false
}

if ps.Visibility != other.Visibility {
return false
}

if ps.Protocol != other.Protocol {
return false
}

return true
}

// WorkspaceStatus defines the observed state of Workspace
type WorkspaceStatus struct {
PodStarts int `json:"podStarts"`
Expand Down
29 changes: 1 addition & 28 deletions components/ws-manager-mk2/controllers/subscriber_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@ package controllers
import (
"context"
"os"
"reflect"

"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/source"

config "github.com/gitpod-io/gitpod/ws-manager/api/config"
workspacev1 "github.com/gitpod-io/gitpod/ws-manager/api/crd/v1"
"github.com/google/go-cmp/cmp"
)

func NewSubscriberReconciler(c client.Client, cfg *config.Configuration) (*SubscriberReconciler, error) {
Expand Down Expand Up @@ -80,28 +76,5 @@ func (r *SubscriberReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
}
}()

// we need several reconciliation loops during a workspace creation until it reaches a stable state.
// this introduces the side effect of multiple notifications to the subscribers with partial information.
// the filterByUpdate predicate acts as a filter to avoid this
filterByUpdate := predicate.Funcs{
CreateFunc: func(ce event.CreateEvent) bool {
return true
},
UpdateFunc: func(e event.UpdateEvent) bool {
old := e.ObjectOld.(*workspacev1.Workspace)
new := e.ObjectNew.(*workspacev1.Workspace)

if !cmp.Equal(old.Spec.Ports, new.Spec.Ports) {
return true
}

// do not notify LastActivity changes
old.Status.LastActivity = nil
new.Status.LastActivity = nil

return !reflect.DeepEqual(old.Status, new.Status)
},
}

return c.Watch(source.Kind(mgr.GetCache(), &workspacev1.Workspace{}), &handler.EnqueueRequestForObject{}, filterByUpdate)
return c.Watch(source.Kind(mgr.GetCache(), &workspacev1.Workspace{}), &handler.EnqueueRequestForObject{})
}

0 comments on commit 2ac4919

Please sign in to comment.