mirror of
https://github.com/hanzo-ml/kuberay.git
synced 2026-10-30 19:48:47 +00:00
* feat: Add node endpoint /nodes POC Signed-off-by: JiangJiaWei1103 <[email protected]> * docs: Clarify router nodes Signed-off-by: JiangJiaWei1103 <[email protected]> * feat: Support dashboard API-compatible response Signed-off-by: JiangJiaWei1103 <[email protected]> * refactor: Clean event processing logic Signed-off-by: JiangJiaWei1103 <[email protected]> * refactor: Extract lifecycle dedup and sorting helper Signed-off-by: JiangJiaWei1103 <[email protected]> * feat: Support more node fields Signed-off-by: JiangJiaWei1103 <[email protected]> * Support local dev outside cluster (should be reverted) Signed-off-by: JiangJiaWei1103 <[email protected]> * test: Add e2e tests for /nodes endpoint for both live and dead Signed-off-by: JiangJiaWei1103 <[email protected]> * feat: Support base64 to hex conversion Signed-off-by: JiangJiaWei1103 <[email protected]> * feat: Support /nodes/node_id endpoint with shared formatters Signed-off-by: JiangJiaWei1103 <[email protected]> * docs: Remove redundant comments Signed-off-by: JiangJiaWei1103 <[email protected]> * test: Add e2e tests for /nodes/node_id endpoint for both live and dead Signed-off-by: JiangJiaWei1103 <[email protected]> * Revert "Support local dev outside cluster (should be reverted)" This reverts commit 8d7ff9a1cf9ee8eedfe948229f2b12dfdba1b094. * fix: Use test namespace instead of default Signed-off-by: JiangJiaWei1103 <[email protected]> * fix: Check empty node ID before conversion Signed-off-by: JiangJiaWei1103 <[email protected]> * fix: Fix deepcopy to prevent race conditions Signed-off-by: JiangJiaWei1103 <[email protected]> * Support local dev outside cluster (should be reverted) Signed-off-by: JiangJiaWei1103 <[email protected]> * feat: Add more fields Signed-off-by: JiangJiaWei1103 <[email protected]> * test: Add new test fields Signed-off-by: JiangJiaWei1103 <[email protected]> * feat: Add storeStats Signed-off-by: JiangJiaWei1103 <[email protected]> * feat: Add resource string Signed-off-by: JiangJiaWei1103 <[email protected]> * Revert "Support local dev outside cluster (should be reverted)" This reverts commit 25898182f85732a79781c8a1074b63512d0d3bc4. * fix: Follow iter order by using slice not map Signed-off-by: JiangJiaWei1103 <[email protected]> * docs: Add docs Signed-off-by: JiangJiaWei1103 <[email protected]> * test: Add back log file e2e tests Signed-off-by: JiangJiaWei1103 <[email protected]> * fix: Handle NODE_LIFECYCLE_EVENT without any state transitions Signed-off-by: JiangJiaWei1103 <[email protected]> * fix: Fix merging def conflicts Signed-off-by: JiangJiaWei1103 <[email protected]> * refactor: Add a helper to get node by node id Signed-off-by: JiangJiaWei1103 <[email protected]> * Remove .env Signed-off-by: JiangJiaWei1103 <[email protected]> * fix: Construct resource string only for alive Signed-off-by: JiangJiaWei1103 <[email protected]> * [history server] use sessionName in task, actor, and job endpoints (#4464) Signed-off-by: Future-Outlier <[email protected]> * fix merge bug Signed-off-by: Future-Outlier <[email protected]> * fix node endpoints Signed-off-by: Future-Outlier <[email protected]> * fix: Fix get one node summary API schema Signed-off-by: JiangJiaWei1103 <[email protected]> * update Signed-off-by: Future-Outlier <[email protected]> * fix TODO Signed-off-by: Future-Outlier <[email protected]> * fix: Check rsc str for non-empty string Signed-off-by: JiangJiaWei1103 <[email protected]> * fix: Avoid missing key Signed-off-by: JiangJiaWei1103 <[email protected]> * fix: Sort resource keys first Signed-off-by: JiangJiaWei1103 <[email protected]> * test: Verify hostnamelist view and clean code Signed-off-by: JiangJiaWei1103 <[email protected]> * refactor: Use existing helper to get cluster session key Signed-off-by: JiangJiaWei1103 <[email protected]> * refactor: Use existing helper to get cluster session key Signed-off-by: JiangJiaWei1103 <[email protected]> * better comments Signed-off-by: Future-Outlier <[email protected]> * remove unused variable and funciton Signed-off-by: Future-Outlier <[email protected]> * fix: Handle different types of resources Signed-off-by: JiangJiaWei1103 <[email protected]> * refactor: Align err msg Signed-off-by: JiangJiaWei1103 <[email protected]> * fix comments Signed-off-by: Future-Outlier <[email protected]> * Remove TODO Signed-off-by: Future-Outlier <[email protected]> --------- Signed-off-by: JiangJiaWei1103 <[email protected]> Signed-off-by: Future-Outlier <[email protected]> Co-authored-by: Han-Ju Chen (Future-Outlier) <[email protected]>
161 lines
4.9 KiB
Go
161 lines
4.9 KiB
Go
package support
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
|
"github.com/aws/aws-sdk-go/aws/session"
|
|
"github.com/aws/aws-sdk-go/service/s3"
|
|
. "github.com/onsi/gomega"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
. "github.com/ray-project/kuberay/ray-operator/test/support"
|
|
)
|
|
|
|
const (
|
|
// MinIO configuration
|
|
MinioNamespace = "minio-dev"
|
|
MinioManifestPath = "../../config/minio.yaml"
|
|
MinioUsername = "minioadmin"
|
|
MinioSecret = "minioadmin"
|
|
MinioAPIEndpoint = "http://localhost:9000"
|
|
MinioAPIPort = 9000
|
|
S3BucketName = "ray-historyserver"
|
|
)
|
|
|
|
// ApplyMinIO deploys minio once per test namespace, making sure it's idempotent.
|
|
func ApplyMinIO(test Test, g *WithT) {
|
|
KubectlApplyYAML(test, MinioManifestPath, MinioNamespace)
|
|
|
|
// Wait for MinIO pods ready.
|
|
g.Eventually(func(gg Gomega) {
|
|
pods, err := test.Client().Core().CoreV1().Pods(MinioNamespace).List(
|
|
test.Ctx(), metav1.ListOptions{
|
|
LabelSelector: "app=minio",
|
|
},
|
|
)
|
|
gg.Expect(err).NotTo(HaveOccurred())
|
|
gg.Expect(pods.Items).NotTo(BeEmpty())
|
|
gg.Expect(AllPodsRunningAndReady(pods.Items)).To(BeTrue())
|
|
}, TestTimeoutMedium).Should(Succeed())
|
|
}
|
|
|
|
// EnsureS3Client creates an S3 client and ensures API endpoint accessibility.
|
|
func EnsureS3Client(t *testing.T) *s3.S3 {
|
|
test := With(t)
|
|
g := NewWithT(t)
|
|
ApplyMinIO(test, g)
|
|
|
|
PortForwardService(test, g, MinioNamespace, "minio-service", MinioAPIPort)
|
|
|
|
// Check readiness of the MinIO API endpoint.
|
|
g.Eventually(func() error {
|
|
s3Client, err := NewS3Client(MinioAPIEndpoint)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = s3Client.ListBuckets(&s3.ListBucketsInput{}) // Dummy operation to ensure accessibility
|
|
return err
|
|
}, TestTimeoutMedium).Should(Succeed(), "MinIO API endpoint should be ready")
|
|
LogWithTimestamp(test.T(), "Port-forwarded MinIO API port to localhost:%d successfully", MinioAPIPort)
|
|
|
|
s3Client, err := NewS3Client(MinioAPIEndpoint)
|
|
g.Expect(err).NotTo(HaveOccurred())
|
|
|
|
return s3Client
|
|
}
|
|
|
|
// NewS3Client creates a new S3 client.
|
|
func NewS3Client(endpoint string) (*s3.S3, error) {
|
|
sess, err := session.NewSession(&aws.Config{
|
|
Endpoint: aws.String(endpoint),
|
|
Region: aws.String("e2e-test"),
|
|
Credentials: credentials.NewStaticCredentials(MinioUsername, MinioSecret, ""),
|
|
DisableSSL: aws.Bool(true),
|
|
S3ForcePathStyle: aws.Bool(true),
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return s3.New(sess), nil
|
|
}
|
|
|
|
// DeleteS3Bucket deletes the S3 bucket. Note that objects under the bucket should be deleted first.
|
|
func DeleteS3Bucket(test Test, g *WithT, s3Client *s3.S3) {
|
|
LogWithTimestamp(test.T(), "Deleting S3 bucket %s", S3BucketName)
|
|
|
|
err := s3Client.ListObjectsV2Pages(&s3.ListObjectsV2Input{
|
|
Bucket: aws.String(S3BucketName),
|
|
}, func(page *s3.ListObjectsV2Output, lastPage bool) bool {
|
|
if len(page.Contents) == 0 {
|
|
return false
|
|
}
|
|
|
|
var objectsToDelete []*s3.ObjectIdentifier
|
|
for _, obj := range page.Contents {
|
|
objectsToDelete = append(objectsToDelete, &s3.ObjectIdentifier{
|
|
Key: obj.Key,
|
|
})
|
|
}
|
|
|
|
_, err := s3Client.DeleteObjects(&s3.DeleteObjectsInput{
|
|
Bucket: aws.String(S3BucketName),
|
|
Delete: &s3.Delete{
|
|
Objects: objectsToDelete,
|
|
Quiet: aws.Bool(true),
|
|
},
|
|
})
|
|
if err != nil {
|
|
test.T().Logf("Failed to delete objects: %v", err)
|
|
return false
|
|
}
|
|
|
|
return true
|
|
})
|
|
if err != nil {
|
|
test.T().Logf("Failed to list/delete objects in bucket: %v", err)
|
|
}
|
|
|
|
_, err = s3Client.DeleteBucket(&s3.DeleteBucketInput{
|
|
Bucket: aws.String(S3BucketName),
|
|
})
|
|
if err != nil {
|
|
test.T().Logf("Failed to delete bucket %s: %v (this is OK if bucket doesn't exist)", S3BucketName, err)
|
|
} else {
|
|
LogWithTimestamp(test.T(), "Deleted S3 bucket %s successfully", S3BucketName)
|
|
}
|
|
}
|
|
|
|
// ListS3Directories lists all directories (prefixes) under the given S3 prefix.
|
|
// In S3, directories are simulated using prefixes and delimiters.
|
|
// For example, given prefix "log/cluster/session/job_events/", this function returns ["AgAAAA==", "AQAAAA=="]
|
|
// which are the jobID directories under job_events/.
|
|
func ListS3Directories(s3Client *s3.S3, bucket string, prefix string) ([]string, error) {
|
|
result, err := s3Client.ListObjectsV2(&s3.ListObjectsV2Input{
|
|
Bucket: aws.String(bucket),
|
|
Prefix: aws.String(prefix),
|
|
Delimiter: aws.String("/"),
|
|
})
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to list S3 directories under %s: %w", prefix, err)
|
|
}
|
|
|
|
// Extract directory names from CommonPrefixes.
|
|
var directories []string
|
|
for _, commonPrefix := range result.CommonPrefixes {
|
|
fullPrefix := aws.StringValue(commonPrefix.Prefix)
|
|
// Extract the directory name by removing the parent prefix and trailing slash.
|
|
// Example: "log/cluster/session/job_events/AgAAAA==/" -> "AgAAAA=="
|
|
dirName := strings.TrimPrefix(fullPrefix, prefix)
|
|
dirName = strings.TrimSuffix(dirName, "/")
|
|
if dirName != "" {
|
|
directories = append(directories, dirName)
|
|
}
|
|
}
|
|
|
|
return directories, nil
|
|
}
|