@@ -7,18 +7,22 @@ package controllers
7
7
import (
8
8
"context"
9
9
"os"
10
+ "reflect"
10
11
11
12
"k8s.io/apimachinery/pkg/api/errors"
12
13
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13
14
ctrl "sigs.k8s.io/controller-runtime"
14
15
"sigs.k8s.io/controller-runtime/pkg/client"
15
16
"sigs.k8s.io/controller-runtime/pkg/controller"
17
+ "sigs.k8s.io/controller-runtime/pkg/event"
16
18
"sigs.k8s.io/controller-runtime/pkg/handler"
17
19
"sigs.k8s.io/controller-runtime/pkg/log"
20
+ "sigs.k8s.io/controller-runtime/pkg/predicate"
18
21
"sigs.k8s.io/controller-runtime/pkg/source"
19
22
20
23
config "github.com/gitpod-io/gitpod/ws-manager/api/config"
21
24
workspacev1 "github.com/gitpod-io/gitpod/ws-manager/api/crd/v1"
25
+ "github.com/google/go-cmp/cmp"
22
26
)
23
27
24
28
func NewSubscriberReconciler (c client.Client , cfg * config.Configuration ) (* SubscriberReconciler , error ) {
@@ -76,5 +80,28 @@ func (r *SubscriberReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
76
80
}
77
81
}()
78
82
79
- return c .Watch (source .Kind (mgr .GetCache (), & workspacev1.Workspace {}), & handler.EnqueueRequestForObject {})
83
+ // we need several reconciliation loops during a workspace creation until it reaches a stable state.
84
+ // this introduces the side effect of multiple notifications to the subscribers with partial information.
85
+ // the filterByUpdate predicate acts as a filter to avoid this
86
+ filterByUpdate := predicate.Funcs {
87
+ CreateFunc : func (ce event.CreateEvent ) bool {
88
+ return true
89
+ },
90
+ UpdateFunc : func (e event.UpdateEvent ) bool {
91
+ old := e .ObjectOld .(* workspacev1.Workspace )
92
+ new := e .ObjectNew .(* workspacev1.Workspace )
93
+
94
+ if ! cmp .Equal (old .Spec .Ports , new .Spec .Ports ) {
95
+ return true
96
+ }
97
+
98
+ // do not notify LastActivity changes
99
+ old .Status .LastActivity = nil
100
+ new .Status .LastActivity = nil
101
+
102
+ return ! reflect .DeepEqual (old .Status , new .Status )
103
+ },
104
+ }
105
+
106
+ return c .Watch (source .Kind (mgr .GetCache (), & workspacev1.Workspace {}), & handler.EnqueueRequestForObject {}, filterByUpdate )
80
107
}
0 commit comments