@@ -109,14 +109,14 @@ func (r *WorkspaceReconciler) updateWorkspaceStatus(ctx context.Context, workspa
109
109
workspace .Status .Phase = * phase
110
110
}
111
111
112
- if failure != "" && ! wsk8s . ConditionPresentAndTrue ( workspace .Status . Conditions , string (workspacev1 .WorkspaceConditionFailed ) ) {
112
+ if failure != "" && ! workspace .IsConditionTrue (workspacev1 .WorkspaceConditionFailed ) {
113
113
// workspaces can fail only once - once there is a failed condition set, stick with it
114
114
log .Info ("workspace failed" , "workspace" , workspace .Name , "reason" , failure )
115
115
workspace .Status .SetCondition (workspacev1 .NewWorkspaceConditionFailed (failure ))
116
116
r .Recorder .Event (workspace , corev1 .EventTypeWarning , "Failed" , failure )
117
117
}
118
118
119
- if workspace .IsHeadless () && ! wsk8s . ConditionPresentAndTrue ( workspace .Status . Conditions , string (workspacev1 .WorkspaceConditionsHeadlessTaskFailed ) ) {
119
+ if workspace .IsHeadless () && ! workspace .IsConditionTrue (workspacev1 .WorkspaceConditionsHeadlessTaskFailed ) {
120
120
for _ , cs := range pod .Status .ContainerStatuses {
121
121
if cs .State .Terminated != nil && cs .State .Terminated .Message != "" {
122
122
workspace .Status .SetCondition (workspacev1 .NewWorkspaceConditionHeadlessTaskFailed (cs .State .Terminated .Message ))
@@ -156,14 +156,14 @@ func (r *WorkspaceReconciler) updateWorkspaceStatus(ctx context.Context, workspa
156
156
}
157
157
158
158
case pod .Status .Phase == corev1 .PodRunning :
159
- everReady := wsk8s . ConditionPresentAndTrue ( workspace .Status . Conditions , string (workspacev1 .WorkspaceConditionEverReady ) )
159
+ everReady := workspace .IsConditionTrue (workspacev1 .WorkspaceConditionEverReady )
160
160
if everReady {
161
161
// If the workspace has been ready before, stay in a Running state, even
162
162
// if the workspace container is not ready anymore. This is to avoid the workspace
163
163
// moving back to Initializing and becoming unusable.
164
164
workspace .Status .Phase = workspacev1 .WorkspacePhaseRunning
165
165
} else {
166
- contentReady := wsk8s . ConditionPresentAndTrue ( workspace .Status . Conditions , string (workspacev1 .WorkspaceConditionContentReady ) )
166
+ contentReady := workspace .IsConditionTrue (workspacev1 .WorkspaceConditionContentReady )
167
167
var ideReady bool
168
168
for _ , cs := range pod .Status .ContainerStatuses {
169
169
if cs .Ready {
@@ -176,7 +176,7 @@ func (r *WorkspaceReconciler) updateWorkspaceStatus(ctx context.Context, workspa
176
176
if ready {
177
177
// workspace is ready - hence content init is done
178
178
workspace .Status .Phase = workspacev1 .WorkspacePhaseRunning
179
- if ! wsk8s . ConditionPresentAndTrue ( workspace .Status . Conditions , string (workspacev1 .WorkspaceConditionEverReady ) ) {
179
+ if ! workspace .IsConditionTrue (workspacev1 .WorkspaceConditionEverReady ) {
180
180
workspace .Status .SetCondition (workspacev1 .NewWorkspaceConditionEverReady ())
181
181
}
182
182
} else {
@@ -186,7 +186,7 @@ func (r *WorkspaceReconciler) updateWorkspaceStatus(ctx context.Context, workspa
186
186
}
187
187
188
188
case workspace .IsHeadless () && (pod .Status .Phase == corev1 .PodSucceeded || pod .Status .Phase == corev1 .PodFailed ):
189
- if pod .Status .Phase == corev1 .PodSucceeded && ! wsk8s . ConditionPresentAndTrue ( workspace .Status . Conditions , string (workspacev1 .WorkspaceConditionEverReady ) ) {
189
+ if pod .Status .Phase == corev1 .PodSucceeded && ! workspace .IsConditionTrue (workspacev1 .WorkspaceConditionEverReady ) {
190
190
// Fix for Prebuilds that instantly succeed (e.g. empty task), sometimes we don't observe the
191
191
// workspace `Running` phase for these, and never had the opportunity to add the EverReady condition.
192
192
// This would then cause a "start failure" in the metrics. So we retroactively add the EverReady
@@ -229,7 +229,7 @@ func (r *WorkspaceReconciler) checkNodeDisappeared(ctx context.Context, workspac
229
229
}
230
230
231
231
// If NodeDisappeared is already set, return early, we've already made the below checks previously.
232
- if wsk8s . ConditionPresentAndTrue ( workspace .Status . Conditions , string (workspacev1 .WorkspaceConditionNodeDisappeared ) ) {
232
+ if workspace .IsConditionTrue (workspacev1 .WorkspaceConditionNodeDisappeared ) {
233
233
return nil
234
234
}
235
235
@@ -245,17 +245,17 @@ func (r *WorkspaceReconciler) checkNodeDisappeared(ctx context.Context, workspac
245
245
}
246
246
247
247
func isDisposalFinished (ws * workspacev1.Workspace ) bool {
248
- return wsk8s . ConditionPresentAndTrue ( ws .Status . Conditions , string (workspacev1 .WorkspaceConditionBackupComplete ) ) ||
249
- wsk8s . ConditionPresentAndTrue ( ws .Status . Conditions , string (workspacev1 .WorkspaceConditionBackupFailure ) ) ||
250
- wsk8s . ConditionPresentAndTrue ( ws .Status . Conditions , string (workspacev1 .WorkspaceConditionAborted ) ) ||
248
+ return ws .IsConditionTrue (workspacev1 .WorkspaceConditionBackupComplete ) ||
249
+ ws .IsConditionTrue (workspacev1 .WorkspaceConditionBackupFailure ) ||
250
+ ws .IsConditionTrue (workspacev1 .WorkspaceConditionAborted ) ||
251
251
// Nothing to dispose if content wasn't ready.
252
- ! wsk8s . ConditionPresentAndTrue ( ws .Status . Conditions , string (workspacev1 .WorkspaceConditionContentReady ) ) ||
252
+ ! ws .IsConditionTrue (workspacev1 .WorkspaceConditionContentReady ) ||
253
253
// Can't dispose if node disappeared.
254
- wsk8s . ConditionPresentAndTrue ( ws .Status . Conditions , string (workspacev1 .WorkspaceConditionNodeDisappeared ) ) ||
254
+ ws .IsConditionTrue (workspacev1 .WorkspaceConditionNodeDisappeared ) ||
255
255
// Image builds have nothing to dispose.
256
256
ws .Spec .Type == workspacev1 .WorkspaceTypeImageBuild ||
257
257
// headless workspaces that failed do not need to be backed up
258
- wsk8s . ConditionPresentAndTrue ( ws .Status . Conditions , string (workspacev1 .WorkspaceConditionsHeadlessTaskFailed ) )
258
+ ws .IsConditionTrue (workspacev1 .WorkspaceConditionsHeadlessTaskFailed )
259
259
}
260
260
261
261
// extractFailure returns a pod failure reason and possibly a phase. If phase is nil then
0 commit comments