Skip to content

Commit

Permalink
Add Ray cluster support in test support package
Browse files Browse the repository at this point in the history
  • Loading branch information
sutaakar committed Jul 24, 2023
1 parent 0a84b1d commit fbefb5a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
15 changes: 14 additions & 1 deletion test/support/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package support

import (
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
)
Expand All @@ -34,7 +35,10 @@ func ConditionStatus[T conditionType](conditionType T) func(any) corev1.Conditio
if c := getJobCondition(o.Status.Conditions, batchv1.JobConditionType(conditionType)); c != nil {
return c.Status
}

case *appsv1.Deployment:
if c := getDeploymentCondition(o.Status.Conditions, appsv1.DeploymentConditionType(conditionType)); c != nil {
return c.Status
}
}

return corev1.ConditionUnknown
Expand All @@ -51,3 +55,12 @@ func getJobCondition(conditions []batchv1.JobCondition, conditionType batchv1.Jo
}
return nil
}

func getDeploymentCondition(conditions []appsv1.DeploymentCondition, conditionType appsv1.DeploymentConditionType) *appsv1.DeploymentCondition {
for _, c := range conditions {
if c.Type == conditionType {
return &c
}
}
return nil
}
17 changes: 17 additions & 0 deletions test/support/ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,20 @@ func WriteRayJobLogs(t Test, namespace, name string) {
t.T().Logf("Retrieving RayJob %s/%s logs", namespace, name)
WriteToOutputDir(t, name, Log, GetRayJobLogs(t, namespace, name))
}

func RayCluster(t Test, namespace, name string) func(g gomega.Gomega) *rayv1alpha1.RayCluster {
return func(g gomega.Gomega) *rayv1alpha1.RayCluster {
cluster, err := t.Client().Ray().RayV1alpha1().RayClusters(namespace).Get(t.Ctx(), name, metav1.GetOptions{})
g.Expect(err).NotTo(gomega.HaveOccurred())
return cluster
}
}

func GetRayCluster(t Test, namespace, name string) *rayv1alpha1.RayCluster {
t.T().Helper()
return RayCluster(t, namespace, name)(t)
}

func RayClusterState(cluster *rayv1alpha1.RayCluster) rayv1alpha1.ClusterState {
return cluster.Status.State
}

0 comments on commit fbefb5a

Please sign in to comment.