Skip to content

Commit

Permalink
Merge pull request openstack-k8s-operators#461 from abays/sim_pod_rea…
Browse files Browse the repository at this point in the history
…dy_state

Test helper func for simulating pod ready state
  • Loading branch information
dprince authored Feb 20, 2024
2 parents 641ba4d + 6ccb98c commit 06e269f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions modules/common/test/helpers/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,40 @@ func (tc *TestHelper) SimulatePodPhaseRunning(name types.NamespacedName) {
}, tc.Timeout, tc.Interval).Should(gomega.Succeed())
tc.Logger.Info("Simulated pod running phase", "on", name)
}

// SimulatePodReady retrieves the Pod and simulates
// a Ready condition for the Pod in a Kubernetes cluster.
//
// example usage:
//
// th.SimulatePodReady(types.NamespacedName{Name: "test-pod", Namespace: "test-namespace"})
func (tc *TestHelper) SimulatePodReady(name types.NamespacedName) {
gomega.Eventually(func(g gomega.Gomega) {
pod := tc.GetPod(name)

found := false

for index, condition := range pod.Status.Conditions {
if condition.Type == corev1.PodReady {
condition.Status = corev1.ConditionTrue
pod.Status.Conditions[index] = condition
found = true
break
}
}

if !found {
pod.Status.Conditions = append(
pod.Status.Conditions,
corev1.PodCondition{
Type: corev1.PodReady,
Status: corev1.ConditionTrue,
},
)
}

g.Expect(tc.K8sClient.Status().Update(tc.Ctx, pod)).To(gomega.Succeed())

}, tc.Timeout, tc.Interval).Should(gomega.Succeed())
tc.Logger.Info("Simulated pod ready state", "on", name)
}

0 comments on commit 06e269f

Please sign in to comment.