Skip to content

Commit cd14a5b

Browse files
committed
Cleanup
1 parent 3cc1c3b commit cd14a5b

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed

components/ws-manager-mk2/controllers/subscriber_controller.go

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,35 @@ import (
99
"os"
1010

1111
"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"
1413
ctrl "sigs.k8s.io/controller-runtime"
1514
"sigs.k8s.io/controller-runtime/pkg/client"
1615
"sigs.k8s.io/controller-runtime/pkg/controller"
1716
"sigs.k8s.io/controller-runtime/pkg/handler"
1817
"sigs.k8s.io/controller-runtime/pkg/log"
19-
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2018
"sigs.k8s.io/controller-runtime/pkg/source"
2119

2220
config "github.com/gitpod-io/gitpod/ws-manager/api/config"
2321
workspacev1 "github.com/gitpod-io/gitpod/ws-manager/api/crd/v1"
2422
)
2523

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) {
2725
reconciler := &SubscriberReconciler{
28-
Client: c,
29-
Scheme: scheme,
30-
Config: cfg,
31-
Recorder: recorder,
26+
Client: c,
27+
Config: cfg,
3228
}
3329

3430
return reconciler, nil
3531
}
3632

3733
type SubscriberReconciler struct {
3834
client.Client
39-
Scheme *runtime.Scheme
4035

41-
Config *config.Configuration
42-
Recorder record.EventRecorder
36+
Config *config.Configuration
37+
4338
OnReconcile func(ctx context.Context, ws *workspacev1.Workspace)
4439
}
4540

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
5541
func (r *SubscriberReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
5642
log := log.FromContext(ctx)
5743

@@ -64,28 +50,31 @@ func (r *SubscriberReconciler) Reconcile(ctx context.Context, req ctrl.Request)
6450
return ctrl.Result{}, client.IgnoreNotFound(err)
6551
}
6652

53+
if workspace.Status.Conditions == nil {
54+
workspace.Status.Conditions = []metav1.Condition{}
55+
}
56+
6757
if r.OnReconcile != nil {
68-
// Publish to subscribers in a goroutine, to prevent blocking the main reconcile loop.
6958
ws := workspace.DeepCopy()
7059
go func() {
7160
r.OnReconcile(ctx, ws)
7261
}()
7362
}
7463

75-
return reconcile.Result{}, nil
64+
return ctrl.Result{}, nil
7665
}
7766

7867
// SetupWithManager sets up the controller with the Manager.
7968
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})
8170
if err != nil {
8271
return err
8372
}
8473

8574
go func() {
8675
err = c.Start(ctx)
8776
if err != nil {
88-
log.FromContext(ctx).Error(err, "cannot start maintenance reconciler")
77+
log.FromContext(ctx).Error(err, "cannot start Subscriber reconciler")
8978
os.Exit(1)
9079
}
9180
}()

components/ws-manager-mk2/controllers/timeout_controller_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ var _ = Describe("TimeoutController", func() {
4747
customMaxLifetime *time.Duration
4848
update func(ws *workspacev1.Workspace)
4949
updateStatus func(ws *workspacev1.Workspace)
50-
//controllerRestart time.Time
51-
expectTimeout bool
50+
expectTimeout bool
5251
}
5352
DescribeTable("workspace timeouts",
5453
func(tc testCase) {

components/ws-manager-mk2/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func main() {
162162
os.Exit(1)
163163
}
164164

165-
subscriberReconciler, err := controllers.NewSubscriberReconciler(mgr.GetClient(), mgr.GetScheme(), mgr.GetEventRecorderFor("subscribers"), &cfg.Manager)
165+
subscriberReconciler, err := controllers.NewSubscriberReconciler(mgr.GetClient(), &cfg.Manager)
166166
if err != nil {
167167
setupLog.Error(err, "unable to create timeout controller", "controller", "Timeout")
168168
os.Exit(1)

0 commit comments

Comments
 (0)