-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Add ValidateRayClusterSpec to Webhook #2739
Open
CheyuWu
wants to merge
5
commits into
ray-project:master
Choose a base branch
from
CheyuWu:feat/gcsFT/webhook_val
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+310
−12
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
954cb7f
feat: add ValidateRayClusterSpec in raycluster webhook and add unit test
CheyuWu bf35c7f
fix: linter issue
CheyuWu ecd513e
feat: add ValidateRayClusterSpec in raycluster webhook, copy necessar…
CheyuWu 4d71412
fix: reference duplicate func and constant variables
CheyuWu ce2c194
fix: rm Containers[RayContainerIndex].Env check which is not necessar…
CheyuWu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package v1 | ||
|
||
const ( | ||
// In KubeRay, the Ray container must be the first application container in a head or worker Pod. | ||
RayContainerIndex = 0 | ||
|
||
// Use as container env variable | ||
RAY_REDIS_ADDRESS = "RAY_REDIS_ADDRESS" | ||
|
||
// Ray GCS FT related annotations | ||
RayFTEnabledAnnotationKey = "ray.io/ft-enabled" | ||
) |
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,252 @@ | ||
package v1 | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
) | ||
|
||
func TestValidateRayClusterSpec(t *testing.T) { | ||
tests := []struct { | ||
gcsFaultToleranceOptions *GcsFaultToleranceOptions | ||
annotations map[string]string | ||
name string | ||
errorMessage string | ||
envVars []corev1.EnvVar | ||
expectError bool | ||
}{ | ||
{ | ||
name: "FT disabled with GcsFaultToleranceOptions set", | ||
annotations: map[string]string{ | ||
RayFTEnabledAnnotationKey: "false", | ||
}, | ||
gcsFaultToleranceOptions: &GcsFaultToleranceOptions{}, | ||
expectError: true, | ||
errorMessage: fmt.Sprintf("GcsFaultToleranceOptions should be nil when %s annotation is set to false", RayFTEnabledAnnotationKey), | ||
}, | ||
{ | ||
name: "FT disabled with RAY_REDIS_ADDRESS set", | ||
annotations: map[string]string{ | ||
RayFTEnabledAnnotationKey: "false", | ||
}, | ||
envVars: []corev1.EnvVar{ | ||
{ | ||
Name: RAY_REDIS_ADDRESS, | ||
Value: "redis://127.0.0.1:6379", | ||
}, | ||
}, | ||
expectError: true, | ||
errorMessage: fmt.Sprintf("%s should not be set when %s is disabled", RAY_REDIS_ADDRESS, RayFTEnabledAnnotationKey), | ||
}, | ||
{ | ||
name: "FT not set with RAY_REDIS_ADDRESS set", | ||
annotations: map[string]string{}, | ||
envVars: []corev1.EnvVar{ | ||
{ | ||
Name: RAY_REDIS_ADDRESS, | ||
Value: "redis://127.0.0.1:6379", | ||
}, | ||
}, | ||
expectError: true, | ||
errorMessage: fmt.Sprintf("%s should not be set when %s is disabled", RAY_REDIS_ADDRESS, RayFTEnabledAnnotationKey), | ||
}, | ||
{ | ||
name: "FT disabled with other environment variables set", | ||
annotations: map[string]string{ | ||
RayFTEnabledAnnotationKey: "false", | ||
}, | ||
envVars: []corev1.EnvVar{ | ||
{ | ||
Name: "SOME_OTHER_ENV", | ||
Value: "some-value", | ||
}, | ||
}, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "FT enabled, GcsFaultToleranceOptions not nil", | ||
annotations: map[string]string{ | ||
RayFTEnabledAnnotationKey: "true", | ||
}, | ||
gcsFaultToleranceOptions: &GcsFaultToleranceOptions{ | ||
RedisAddress: "redis://127.0.0.1:6379", | ||
}, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "FT enabled, GcsFaultToleranceOptions is nil", | ||
annotations: map[string]string{ | ||
RayFTEnabledAnnotationKey: "true", | ||
}, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "FT enabled with with other environment variables set", | ||
annotations: map[string]string{ | ||
RayFTEnabledAnnotationKey: "true", | ||
}, | ||
envVars: []corev1.EnvVar{ | ||
{ | ||
Name: "SOME_OTHER_ENV", | ||
Value: "some-value", | ||
}, | ||
}, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "FT enabled with RAY_REDIS_ADDRESS set", | ||
annotations: map[string]string{ | ||
RayFTEnabledAnnotationKey: "true", | ||
}, | ||
envVars: []corev1.EnvVar{ | ||
{ | ||
Name: RAY_REDIS_ADDRESS, | ||
Value: "redis://127.0.0.1:6379", | ||
}, | ||
}, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "FT disabled with no GcsFaultToleranceOptions and no RAY_REDIS_ADDRESS", | ||
annotations: map[string]string{ | ||
RayFTEnabledAnnotationKey: "false", | ||
}, | ||
expectError: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
r := &RayCluster{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Annotations: tt.annotations, | ||
}, | ||
Spec: RayClusterSpec{ | ||
GcsFaultToleranceOptions: tt.gcsFaultToleranceOptions, | ||
HeadGroupSpec: HeadGroupSpec{ | ||
Template: corev1.PodTemplateSpec{ | ||
Spec: corev1.PodSpec{ | ||
Containers: []corev1.Container{ | ||
{ | ||
Name: "ray-head", | ||
Env: tt.envVars, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
err := r.ValidateRayClusterSpec() | ||
if tt.expectError { | ||
assert.NotNil(t, err) | ||
assert.IsType(t, &field.Error{}, err) | ||
assert.Equal(t, err.Detail, tt.errorMessage) | ||
} else { | ||
assert.Nil(t, err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestValidateRayCluster(t *testing.T) { | ||
tests := []struct { | ||
GcsFaultToleranceOptions *GcsFaultToleranceOptions | ||
name string | ||
errorMessage string | ||
ObjectMeta metav1.ObjectMeta | ||
WorkerGroupSpecs []WorkerGroupSpec | ||
expectError bool | ||
}{ | ||
{ | ||
name: "Invalid name", | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "Invalid_Name", | ||
}, | ||
expectError: true, | ||
errorMessage: "name must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character", | ||
}, | ||
{ | ||
name: "Duplicate worker group names", | ||
|
||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "valid-name", | ||
}, | ||
|
||
WorkerGroupSpecs: []WorkerGroupSpec{ | ||
{GroupName: "group1"}, | ||
{GroupName: "group1"}, | ||
}, | ||
|
||
expectError: true, | ||
errorMessage: "worker group names must be unique", | ||
}, | ||
{ | ||
name: "FT disabled with GcsFaultToleranceOptions set", | ||
|
||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "valid-name", | ||
Annotations: map[string]string{ | ||
RayFTEnabledAnnotationKey: "false", | ||
}, | ||
}, | ||
GcsFaultToleranceOptions: &GcsFaultToleranceOptions{}, | ||
expectError: true, | ||
errorMessage: fmt.Sprintf("GcsFaultToleranceOptions should be nil when %s annotation is set to false", RayFTEnabledAnnotationKey), | ||
}, | ||
{ | ||
name: "Valid RayCluster", | ||
|
||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "valid-name", | ||
Annotations: map[string]string{ | ||
RayFTEnabledAnnotationKey: "true", | ||
}, | ||
}, | ||
GcsFaultToleranceOptions: &GcsFaultToleranceOptions{ | ||
RedisAddress: "redis://127.0.0.1:6379", | ||
}, | ||
WorkerGroupSpecs: []WorkerGroupSpec{ | ||
{GroupName: "group1"}, | ||
{GroupName: "group2"}, | ||
}, | ||
expectError: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
rayCluster := &RayCluster{ | ||
ObjectMeta: tt.ObjectMeta, | ||
Spec: RayClusterSpec{ | ||
GcsFaultToleranceOptions: tt.GcsFaultToleranceOptions, | ||
HeadGroupSpec: HeadGroupSpec{ | ||
Template: corev1.PodTemplateSpec{ | ||
Spec: corev1.PodSpec{ | ||
Containers: []corev1.Container{ | ||
{ | ||
Name: "ray-head", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
WorkerGroupSpecs: tt.WorkerGroupSpecs, | ||
}, | ||
} | ||
err := rayCluster.validateRayCluster() | ||
if tt.expectError { | ||
assert.NotNil(t, err) | ||
assert.IsType(t, &apierrors.StatusError{}, err) | ||
assert.Contains(t, err.Error(), tt.errorMessage) | ||
} else { | ||
assert.Nil(t, err) | ||
} | ||
}) | ||
} | ||
} |
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,12 @@ | ||
package v1 | ||
|
||
import corev1 "k8s.io/api/core/v1" | ||
|
||
func EnvVarExists(envName string, envVars []corev1.EnvVar) bool { | ||
for _, env := range envVars { | ||
if env.Name == envName { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.