Skip to content

Commit c502718

Browse files
committed
Remove workspace activity
1 parent 513e768 commit c502718

File tree

6 files changed

+55
-188
lines changed

6 files changed

+55
-188
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"sigs.k8s.io/controller-runtime/pkg/metrics"
2424

2525
"github.com/gitpod-io/gitpod/common-go/util"
26-
"github.com/gitpod-io/gitpod/ws-manager-mk2/pkg/activity"
2726
"github.com/gitpod-io/gitpod/ws-manager/api/config"
2827
workspacev1 "github.com/gitpod-io/gitpod/ws-manager/api/crd/v1"
2928
//+kubebuilder:scaffold:imports
@@ -50,10 +49,10 @@ func TestAPIs(t *testing.T) {
5049
}
5150

5251
var (
53-
ctx context.Context
54-
cancel context.CancelFunc
55-
wsActivity *activity.WorkspaceActivity
56-
wsMetrics *controllerMetrics
52+
ctx context.Context
53+
cancel context.CancelFunc
54+
//wsActivity *activity.WorkspaceActivity
55+
wsMetrics *controllerMetrics
5756
)
5857

5958
var _ = BeforeSuite(func() {
@@ -111,8 +110,8 @@ var _ = BeforeSuite(func() {
111110
Expect(err).ToNot(HaveOccurred())
112111
Expect(wsReconciler.SetupWithManager(k8sManager)).To(Succeed())
113112

114-
wsActivity = activity.NewWorkspaceActivity(conf.Namespace, k8sManager.GetClient())
115-
timeoutReconciler, err := NewTimeoutReconciler(k8sManager.GetClient(), k8sManager.GetEventRecorderFor("workspace"), conf, wsActivity, maintenance)
113+
//wsActivity = activity.NewWorkspaceActivity(conf.Namespace, k8sManager.GetClient())
114+
timeoutReconciler, err := NewTimeoutReconciler(k8sManager.GetClient(), k8sManager.GetEventRecorderFor("workspace"), conf, maintenance)
116115
Expect(err).ToNot(HaveOccurred())
117116
Expect(timeoutReconciler.SetupWithManager(k8sManager)).To(Succeed())
118117

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
corev1 "k8s.io/api/core/v1"
1313
apierrors "k8s.io/apimachinery/pkg/api/errors"
14+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1415
"k8s.io/apimachinery/pkg/types"
1516
"k8s.io/client-go/tools/record"
1617
"k8s.io/client-go/util/retry"
@@ -20,13 +21,12 @@ import (
2021
"sigs.k8s.io/controller-runtime/pkg/log"
2122

2223
"github.com/gitpod-io/gitpod/common-go/util"
23-
wsactivity "github.com/gitpod-io/gitpod/ws-manager-mk2/pkg/activity"
2424
"github.com/gitpod-io/gitpod/ws-manager-mk2/pkg/maintenance"
2525
config "github.com/gitpod-io/gitpod/ws-manager/api/config"
2626
workspacev1 "github.com/gitpod-io/gitpod/ws-manager/api/crd/v1"
2727
)
2828

29-
func NewTimeoutReconciler(c client.Client, recorder record.EventRecorder, cfg config.Configuration, activity *wsactivity.WorkspaceActivity, maintenance maintenance.Maintenance) (*TimeoutReconciler, error) {
29+
func NewTimeoutReconciler(c client.Client, recorder record.EventRecorder, cfg config.Configuration, maintenance maintenance.Maintenance) (*TimeoutReconciler, error) {
3030
if cfg.HeartbeatInterval == 0 {
3131
return nil, fmt.Errorf("invalid heartbeat interval, must not be 0")
3232
}
@@ -38,7 +38,6 @@ func NewTimeoutReconciler(c client.Client, recorder record.EventRecorder, cfg co
3838
return &TimeoutReconciler{
3939
Client: c,
4040
Config: cfg,
41-
activity: activity,
4241
reconcileInterval: reconcileInterval,
4342
recorder: recorder,
4443
maintenance: maintenance,
@@ -53,7 +52,6 @@ type TimeoutReconciler struct {
5352
client.Client
5453

5554
Config config.Configuration
56-
activity *wsactivity.WorkspaceActivity
5755
reconcileInterval time.Duration
5856
recorder record.EventRecorder
5957
maintenance maintenance.Maintenance
@@ -157,7 +155,7 @@ func (r *TimeoutReconciler) isWorkspaceTimedOut(ws *workspacev1.Workspace) (reas
157155
}
158156

159157
start := ws.ObjectMeta.CreationTimestamp.Time
160-
lastActivity := r.activity.GetLastActivity(ws)
158+
lastActivity := ws.Status.LastActivity
161159
isClosed := ws.IsConditionTrue(workspacev1.WorkspaceConditionClosed)
162160

163161
switch phase {
@@ -189,7 +187,8 @@ func (r *TimeoutReconciler) isWorkspaceTimedOut(ws *workspacev1.Workspace) (reas
189187
activity := activityNone
190188
if ws.IsHeadless() {
191189
timeout = timeouts.HeadlessWorkspace
192-
lastActivity = &start
190+
nt := metav1.NewTime(start)
191+
lastActivity = &nt
193192
activity = activityRunningHeadless
194193
} else if lastActivity == nil {
195194
// The workspace is up and running, but the user has never produced any activity
@@ -203,13 +202,13 @@ func (r *TimeoutReconciler) isWorkspaceTimedOut(ws *workspacev1.Workspace) (reas
203202
return ""
204203
}
205204
}
206-
return decide(*lastActivity, afterClosed, activityClosed)
205+
return decide(lastActivity.Time, afterClosed, activityClosed)
207206
}()
208207
if reason != "" {
209208
return reason
210209
}
211210
}
212-
return decide(*lastActivity, timeout, activity)
211+
return decide(lastActivity.Time, timeout, activity)
213212

214213
case workspacev1.WorkspacePhaseStopping:
215214
if isWorkspaceBeingDeleted(ws) && !ws.IsConditionTrue(workspacev1.WorkspaceConditionBackupComplete) {

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

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"time"
99

1010
wsk8s "github.com/gitpod-io/gitpod/common-go/kubernetes"
11-
"github.com/gitpod-io/gitpod/ws-manager-mk2/pkg/activity"
1211
workspacev1 "github.com/gitpod-io/gitpod/ws-manager/api/crd/v1"
1312
"github.com/google/uuid"
1413
. "github.com/onsi/ginkgo/v2"
@@ -36,7 +35,7 @@ var _ = Describe("TimeoutController", func() {
3635
// Use a fake client instead of the envtest's k8s client, such that we can add objects
3736
// with custom CreationTimestamps and check timeout logic.
3837
fakeClient = fake.NewClientBuilder().WithStatusSubresource(&workspacev1.Workspace{}).WithScheme(k8sClient.Scheme()).Build()
39-
r, err = NewTimeoutReconciler(fakeClient, record.NewFakeRecorder(100), conf, activity.NewWorkspaceActivity("default", k8sClient), &fakeMaintenance{enabled: false})
38+
r, err = NewTimeoutReconciler(fakeClient, record.NewFakeRecorder(100), conf, &fakeMaintenance{enabled: false})
4039
Expect(err).ToNot(HaveOccurred())
4140
})
4241

@@ -48,20 +47,22 @@ var _ = Describe("TimeoutController", func() {
4847
customMaxLifetime *time.Duration
4948
update func(ws *workspacev1.Workspace)
5049
updateStatus func(ws *workspacev1.Workspace)
51-
controllerRestart time.Time
52-
expectTimeout bool
50+
//controllerRestart time.Time
51+
expectTimeout bool
5352
}
5453
DescribeTable("workspace timeouts",
5554
func(tc testCase) {
5655
By("creating a workspace")
5756
ws := newWorkspace(uuid.NewString(), "default")
5857
ws.CreationTimestamp = metav1.NewTime(now.Add(-tc.age))
59-
Expect(fakeClient.Create(ctx, ws)).To(Succeed())
6058

6159
if tc.lastActivityAgo != nil {
62-
r.activity.Store(ws.Name, now.Add(-*tc.lastActivityAgo))
60+
now := metav1.NewTime(now.Add(-*tc.lastActivityAgo))
61+
ws.Status.LastActivity = &now
6362
}
6463

64+
Expect(fakeClient.Create(ctx, ws)).To(Succeed())
65+
6566
updateObjWithRetries(fakeClient, ws, false, func(ws *workspacev1.Workspace) {
6667
if tc.customTimeout != nil {
6768
ws.Spec.Timeout.Time = &metav1.Duration{Duration: *tc.customTimeout}
@@ -80,14 +81,6 @@ var _ = Describe("TimeoutController", func() {
8081
}
8182
})
8283

83-
// Set controller (re)start time.
84-
if tc.controllerRestart.IsZero() {
85-
// Bit arbitrary, but default to the controller running for ~2 days.
86-
r.activity.ManagerStartedAt = now.Add(-48 * time.Hour)
87-
} else {
88-
r.activity.ManagerStartedAt = tc.controllerRestart
89-
}
90-
9184
// Run the timeout controller for this workspace.
9285
By("running the TimeoutController reconcile()")
9386
_, err := r.Reconcile(ctx, reconcile.Request{NamespacedName: types.NamespacedName{Name: ws.Name, Namespace: ws.Namespace}})
@@ -159,32 +152,11 @@ var _ = Describe("TimeoutController", func() {
159152
lastActivityAgo: pointer.Duration(1 * time.Minute),
160153
expectTimeout: true,
161154
}),
162-
Entry("shouldn't timeout after controller restart", testCase{
163-
phase: workspacev1.WorkspacePhaseRunning,
164-
updateStatus: func(ws *workspacev1.Workspace) {
165-
// Add FirstUserActivity condition from 5 hours ago.
166-
// From this condition the controller should deduce that the workspace
167-
// has had user activity, but since lastActivity is nil, it's been cleared on
168-
// a restart. The controller therefore should not timeout the workspace and
169-
// wait for new user activity. Or timeout once user activity doesn't come
170-
// eventually after the controller restart.
171-
ws.Status.Conditions = wsk8s.AddUniqueCondition(ws.Status.Conditions, metav1.Condition{
172-
Type: string(workspacev1.WorkspaceConditionFirstUserActivity),
173-
Status: metav1.ConditionTrue,
174-
LastTransitionTime: metav1.NewTime(now.Add(-5 * time.Hour)),
175-
})
176-
},
177-
age: 5 * time.Hour,
178-
lastActivityAgo: nil, // No last activity recorded yet after controller restart.
179-
controllerRestart: now,
180-
expectTimeout: false,
181-
}),
182155
Entry("should timeout after controller restart if no FirstUserActivity", testCase{
183-
phase: workspacev1.WorkspacePhaseRunning,
184-
age: 5 * time.Hour,
185-
lastActivityAgo: nil, // No last activity recorded yet after controller restart.
186-
controllerRestart: now,
187-
expectTimeout: true,
156+
phase: workspacev1.WorkspacePhaseRunning,
157+
age: 5 * time.Hour,
158+
lastActivityAgo: nil, // No last activity recorded yet after controller restart.
159+
expectTimeout: true,
188160
}),
189161
Entry("should timeout eventually with no user activity after controller restart", testCase{
190162
phase: workspacev1.WorkspacePhaseRunning,
@@ -195,10 +167,9 @@ var _ = Describe("TimeoutController", func() {
195167
LastTransitionTime: metav1.NewTime(now.Add(-5 * time.Hour)),
196168
})
197169
},
198-
age: 5 * time.Hour,
199-
lastActivityAgo: nil,
200-
controllerRestart: now.Add(-2 * time.Hour),
201-
expectTimeout: true,
170+
age: 5 * time.Hour,
171+
lastActivityAgo: nil,
172+
expectTimeout: true,
202173
}),
203174
)
204175
})
@@ -207,7 +178,7 @@ var _ = Describe("TimeoutController", func() {
207178
var r *TimeoutReconciler
208179
BeforeEach(func() {
209180
var err error
210-
r, err = NewTimeoutReconciler(k8sClient, record.NewFakeRecorder(100), newTestConfig(), activity.NewWorkspaceActivity("default", k8sClient), &fakeMaintenance{enabled: false})
181+
r, err = NewTimeoutReconciler(k8sClient, record.NewFakeRecorder(100), newTestConfig(), &fakeMaintenance{enabled: false})
211182
Expect(err).ToNot(HaveOccurred())
212183
})
213184

components/ws-manager-mk2/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ func main() {
168168
}
169169
}()
170170

171-
timeoutReconciler, err := controllers.NewTimeoutReconciler(mgr.GetClient(), mgr.GetEventRecorderFor("workspace"), cfg.Manager, activity, maintenanceReconciler)
171+
timeoutReconciler, err := controllers.NewTimeoutReconciler(mgr.GetClient(), mgr.GetEventRecorderFor("workspace"), cfg.Manager, maintenanceReconciler)
172172
if err != nil {
173173
setupLog.Error(err, "unable to create timeout controller", "controller", "Timeout")
174174
os.Exit(1)
175175
}
176176

177-
wsmanService, err := setupGRPCService(cfg, mgr.GetClient(), activity, maintenanceReconciler)
177+
wsmanService, err := setupGRPCService(cfg, mgr.GetClient(), maintenanceReconciler)
178178
if err != nil {
179179
setupLog.Error(err, "unable to start manager service")
180180
os.Exit(1)
@@ -219,7 +219,7 @@ func main() {
219219
}
220220
}
221221

222-
func setupGRPCService(cfg *config.ServiceConfiguration, k8s client.Client, activity *activity.WorkspaceActivity, maintenance maintenance.Maintenance) (*service.WorkspaceManagerServer, error) {
222+
func setupGRPCService(cfg *config.ServiceConfiguration, k8s client.Client, maintenance maintenance.Maintenance) (*service.WorkspaceManagerServer, error) {
223223
// TODO(cw): remove use of common-go/log
224224

225225
if len(cfg.RPCServer.RateLimits) > 0 {
@@ -275,7 +275,7 @@ func setupGRPCService(cfg *config.ServiceConfiguration, k8s client.Client, activ
275275
imgbldr.RegisterImageBuilderServer(grpcServer, imgproxy.ImageBuilder{D: imgbldr.NewImageBuilderClient(conn)})
276276
}
277277

278-
srv := service.NewWorkspaceManagerServer(k8s, &cfg.Manager, metrics.Registry, activity, maintenance)
278+
srv := service.NewWorkspaceManagerServer(k8s, &cfg.Manager, metrics.Registry, maintenance)
279279

280280
grpc_prometheus.Register(grpcServer)
281281
wsmanapi.RegisterWorkspaceManagerServer(grpcServer, srv)

components/ws-manager-mk2/pkg/activity/activity.go

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)