Skip to content

Commit

Permalink
mathew commit 1
Browse files Browse the repository at this point in the history
Signed-off-by: Mathew Wicks <[email protected]>
  • Loading branch information
thesuperzapper committed Aug 6, 2024
1 parent 4707443 commit def97ba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,6 @@ func (r *WorkspaceReconciler) generateWorkspaceStatus(ctx context.Context, log l
}
}


// cases where the Pod does not exist
if pod == nil {
// STATUS: Paused
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ package controller

import (
"fmt"
"k8s.io/utils/ptr"
"time"

"k8s.io/utils/ptr"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"

Expand Down Expand Up @@ -131,23 +132,37 @@ var _ = Describe("Workspace Controller", func() {
workspace := NewExampleWorkspace1(workspaceName, namespaceName, workspaceKindName)
Expect(k8sClient.Create(ctx, workspace)).To(Succeed())

By("pausing the Workspace")
patch := client.MergeFrom(workspace.DeepCopy())
By("setting the Workspace to paused")
Expect(workspace.Status.PauseTime).To(Equal(int64(0)))
newWorkspace := workspace.DeepCopy()
newWorkspace.Spec.Paused = ptr.To(true)
Expect(k8sClient.Patch(ctx, newWorkspace, patch)).To(Succeed())
// Define a small range for acceptable time difference
timeRangeSeconds := int64(2) // 2-second range
currentTime := metav1.Now().Unix()

By("setting the Workspace `status.pauseTime` to the current time")
tolerance := int64(5)
currentTime := time.Now().Unix()
Eventually(func() (int64, error) {
err := k8sClient.Get(ctx, types.NamespacedName{Name: workspaceName, Namespace: namespaceName}, workspace)
if err != nil {
return 0, err
}
return workspace.Status.PauseTime, nil
}, timeout, interval).Should(BeNumerically("~", currentTime, tolerance))

By("un-pausing the Workspace")
patch = client.MergeFrom(workspace.DeepCopy())
newWorkspace = workspace.DeepCopy()
newWorkspace.Spec.Paused = ptr.To(false)
Expect(k8sClient.Patch(ctx, newWorkspace, patch)).To(Succeed())

By("setting the Workspace `status.pauseTime` to 0")
Eventually(func() (int64, error) {
err := k8sClient.Get(ctx, types.NamespacedName{Name: workspaceName, Namespace: namespaceName}, workspace)
if err != nil {
return 0, err
}
return workspace.Status.PauseTime, nil
}).Should(BeNumerically("<=", currentTime+timeRangeSeconds))
Expect(workspace.Spec.Paused).To(Equal(ptr.To(true)))
}, timeout, interval).Should(BeZero())

By("creating a StatefulSet")
statefulSetList := &appsv1.StatefulSetList{}
Expand All @@ -157,7 +172,7 @@ var _ = Describe("Workspace Controller", func() {
return nil, err
}
return statefulSetList.Items, nil
}).Should(HaveLen(1))
}, timeout, interval).Should(HaveLen(1))

// TODO: use this to get the StatefulSet
//statefulSet := statefulSetList.Items[0]
Expand All @@ -170,7 +185,7 @@ var _ = Describe("Workspace Controller", func() {
return nil, err
}
return serviceList.Items, nil
}).Should(HaveLen(1))
}, timeout, interval).Should(HaveLen(1))

// TODO: use this to get the Service
//service := serviceList.Items[0]
Expand Down

0 comments on commit def97ba

Please sign in to comment.