forked from ray-project/kuberay
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor] Move
validateRayClusterStatus
function to `validation.go…
…` and move unit test to `validation_test.go` (ray-project#2780)
- Loading branch information
Showing
4 changed files
with
107 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package utils | ||
|
||
import ( | ||
errstd "errors" | ||
|
||
"k8s.io/apimachinery/pkg/api/meta" | ||
|
||
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1" | ||
) | ||
|
||
func ValidateRayClusterStatus(instance *rayv1.RayCluster) error { | ||
suspending := meta.IsStatusConditionTrue(instance.Status.Conditions, string(rayv1.RayClusterSuspending)) | ||
suspended := meta.IsStatusConditionTrue(instance.Status.Conditions, string(rayv1.RayClusterSuspended)) | ||
if suspending && suspended { | ||
return errstd.New("invalid RayCluster State: rayv1.RayClusterSuspending and rayv1.RayClusterSuspended conditions should not be both true") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1" | ||
) | ||
|
||
func TestValidateRayClusterStatus(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
conditions []metav1.Condition | ||
expectError bool | ||
}{ | ||
{ | ||
name: "Both suspending and suspended are true", | ||
conditions: []metav1.Condition{ | ||
{ | ||
Type: string(rayv1.RayClusterSuspending), | ||
Status: metav1.ConditionTrue, | ||
}, | ||
{ | ||
Type: string(rayv1.RayClusterSuspended), | ||
Status: metav1.ConditionTrue, | ||
}, | ||
}, | ||
expectError: true, | ||
}, | ||
{ | ||
name: "Only suspending is true", | ||
conditions: []metav1.Condition{ | ||
{ | ||
Type: string(rayv1.RayClusterSuspending), | ||
Status: metav1.ConditionTrue, | ||
}, | ||
{ | ||
Type: string(rayv1.RayClusterSuspended), | ||
Status: metav1.ConditionFalse, | ||
}, | ||
}, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "Only suspended is true", | ||
conditions: []metav1.Condition{ | ||
{ | ||
Type: string(rayv1.RayClusterSuspending), | ||
Status: metav1.ConditionFalse, | ||
}, | ||
{ | ||
Type: string(rayv1.RayClusterSuspended), | ||
Status: metav1.ConditionTrue, | ||
}, | ||
}, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "Both suspending and suspended are false", | ||
conditions: []metav1.Condition{ | ||
{ | ||
Type: string(rayv1.RayClusterSuspending), | ||
Status: metav1.ConditionFalse, | ||
}, | ||
{ | ||
Type: string(rayv1.RayClusterSuspended), | ||
Status: metav1.ConditionFalse, | ||
}, | ||
}, | ||
expectError: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
instance := &rayv1.RayCluster{ | ||
Status: rayv1.RayClusterStatus{ | ||
Conditions: tt.conditions, | ||
}, | ||
} | ||
err := ValidateRayClusterStatus(instance) | ||
if (err != nil) != tt.expectError { | ||
t.Errorf("ValidateRayClusterStatus() error = %v, wantErr %v", err, tt.expectError) | ||
} | ||
}) | ||
} | ||
} |