@@ -9,49 +9,35 @@ import (
9
9
"os"
10
10
11
11
"k8s.io/apimachinery/pkg/api/errors"
12
- "k8s.io/apimachinery/pkg/runtime"
13
- "k8s.io/client-go/tools/record"
12
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14
13
ctrl "sigs.k8s.io/controller-runtime"
15
14
"sigs.k8s.io/controller-runtime/pkg/client"
16
15
"sigs.k8s.io/controller-runtime/pkg/controller"
17
16
"sigs.k8s.io/controller-runtime/pkg/handler"
18
17
"sigs.k8s.io/controller-runtime/pkg/log"
19
- "sigs.k8s.io/controller-runtime/pkg/reconcile"
20
18
"sigs.k8s.io/controller-runtime/pkg/source"
21
19
22
20
config "github.com/gitpod-io/gitpod/ws-manager/api/config"
23
21
workspacev1 "github.com/gitpod-io/gitpod/ws-manager/api/crd/v1"
24
22
)
25
23
26
- func NewSubscriberReconciler (c client.Client , scheme * runtime. Scheme , recorder record. EventRecorder , cfg * config.Configuration ) (* SubscriberReconciler , error ) {
24
+ func NewSubscriberReconciler (c client.Client , cfg * config.Configuration ) (* SubscriberReconciler , error ) {
27
25
reconciler := & SubscriberReconciler {
28
- Client : c ,
29
- Scheme : scheme ,
30
- Config : cfg ,
31
- Recorder : recorder ,
26
+ Client : c ,
27
+ Config : cfg ,
32
28
}
33
29
34
30
return reconciler , nil
35
31
}
36
32
37
33
type SubscriberReconciler struct {
38
34
client.Client
39
- Scheme * runtime.Scheme
40
35
41
- Config * config.Configuration
42
- Recorder record. EventRecorder
36
+ Config * config.Configuration
37
+
43
38
OnReconcile func (ctx context.Context , ws * workspacev1.Workspace )
44
39
}
45
40
46
- // Reconcile is part of the main kubernetes reconciliation loop which aims to
47
- // move the current state of the cluster closer to the desired state.
48
- // Modify the Reconcile function to compare the state specified by
49
- // the Workspace object against the actual cluster state, and then
50
- // perform operations to make the cluster state reflect the state specified by
51
- // the user.
52
- //
53
- // For more details, check Reconcile and its Result here:
54
- // - https://pkg.go.dev/sigs.k8s.io/[email protected] /pkg/reconcile
55
41
func (r * SubscriberReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
56
42
log := log .FromContext (ctx )
57
43
@@ -64,28 +50,31 @@ func (r *SubscriberReconciler) Reconcile(ctx context.Context, req ctrl.Request)
64
50
return ctrl.Result {}, client .IgnoreNotFound (err )
65
51
}
66
52
53
+ if workspace .Status .Conditions == nil {
54
+ workspace .Status .Conditions = []metav1.Condition {}
55
+ }
56
+
67
57
if r .OnReconcile != nil {
68
- // Publish to subscribers in a goroutine, to prevent blocking the main reconcile loop.
69
58
ws := workspace .DeepCopy ()
70
59
go func () {
71
60
r .OnReconcile (ctx , ws )
72
61
}()
73
62
}
74
63
75
- return reconcile .Result {}, nil
64
+ return ctrl .Result {}, nil
76
65
}
77
66
78
67
// SetupWithManager sets up the controller with the Manager.
79
68
func (r * SubscriberReconciler ) SetupWithManager (ctx context.Context , mgr ctrl.Manager ) error {
80
- c , err := controller .NewUnmanaged ("maintenance -controller" , mgr , controller.Options {Reconciler : r })
69
+ c , err := controller .NewUnmanaged ("subscribers -controller" , mgr , controller.Options {Reconciler : r })
81
70
if err != nil {
82
71
return err
83
72
}
84
73
85
74
go func () {
86
75
err = c .Start (ctx )
87
76
if err != nil {
88
- log .FromContext (ctx ).Error (err , "cannot start maintenance reconciler" )
77
+ log .FromContext (ctx ).Error (err , "cannot start Subscriber reconciler" )
89
78
os .Exit (1 )
90
79
}
91
80
}()
0 commit comments