8
8
"time"
9
9
10
10
wsk8s "github.com/gitpod-io/gitpod/common-go/kubernetes"
11
- "github.com/gitpod-io/gitpod/ws-manager-mk2/pkg/activity"
12
11
workspacev1 "github.com/gitpod-io/gitpod/ws-manager/api/crd/v1"
13
12
"github.com/google/uuid"
14
13
. "github.com/onsi/ginkgo/v2"
@@ -36,7 +35,7 @@ var _ = Describe("TimeoutController", func() {
36
35
// Use a fake client instead of the envtest's k8s client, such that we can add objects
37
36
// with custom CreationTimestamps and check timeout logic.
38
37
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 })
40
39
Expect (err ).ToNot (HaveOccurred ())
41
40
})
42
41
@@ -48,20 +47,22 @@ var _ = Describe("TimeoutController", func() {
48
47
customMaxLifetime * time.Duration
49
48
update func (ws * workspacev1.Workspace )
50
49
updateStatus func (ws * workspacev1.Workspace )
51
- controllerRestart time.Time
52
- expectTimeout bool
50
+ // controllerRestart time.Time
51
+ expectTimeout bool
53
52
}
54
53
DescribeTable ("workspace timeouts" ,
55
54
func (tc testCase ) {
56
55
By ("creating a workspace" )
57
56
ws := newWorkspace (uuid .NewString (), "default" )
58
57
ws .CreationTimestamp = metav1 .NewTime (now .Add (- tc .age ))
59
- Expect (fakeClient .Create (ctx , ws )).To (Succeed ())
60
58
61
59
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
63
62
}
64
63
64
+ Expect (fakeClient .Create (ctx , ws )).To (Succeed ())
65
+
65
66
updateObjWithRetries (fakeClient , ws , false , func (ws * workspacev1.Workspace ) {
66
67
if tc .customTimeout != nil {
67
68
ws .Spec .Timeout .Time = & metav1.Duration {Duration : * tc .customTimeout }
@@ -80,14 +81,6 @@ var _ = Describe("TimeoutController", func() {
80
81
}
81
82
})
82
83
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
-
91
84
// Run the timeout controller for this workspace.
92
85
By ("running the TimeoutController reconcile()" )
93
86
_ , err := r .Reconcile (ctx , reconcile.Request {NamespacedName : types.NamespacedName {Name : ws .Name , Namespace : ws .Namespace }})
@@ -159,32 +152,11 @@ var _ = Describe("TimeoutController", func() {
159
152
lastActivityAgo : pointer .Duration (1 * time .Minute ),
160
153
expectTimeout : true ,
161
154
}),
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
- }),
182
155
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 ,
188
160
}),
189
161
Entry ("should timeout eventually with no user activity after controller restart" , testCase {
190
162
phase : workspacev1 .WorkspacePhaseRunning ,
@@ -195,10 +167,9 @@ var _ = Describe("TimeoutController", func() {
195
167
LastTransitionTime : metav1 .NewTime (now .Add (- 5 * time .Hour )),
196
168
})
197
169
},
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 ,
202
173
}),
203
174
)
204
175
})
@@ -207,7 +178,7 @@ var _ = Describe("TimeoutController", func() {
207
178
var r * TimeoutReconciler
208
179
BeforeEach (func () {
209
180
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 })
211
182
Expect (err ).ToNot (HaveOccurred ())
212
183
})
213
184
0 commit comments