Repository navigation
[rayapp] add --cloud and --compute-config to test and probe - #507
elliot-barn wants to merge 1 commit into
Conversation
`rayapp test` always tests a template's AWS compute config on the org's default cloud: the "AWS" key is hardcoded and no template config sets a cloud, so the GCP and K8S entries are never exercised. `probe` always launches on the default cloud too. - `--cloud NAME` (test, probe): run on this cloud instead of the default. For test, the cloud is written into a temp copy of the compute config (either format; the new format otherwise lands in the default cloud) and passed to `workspace_v2 create`. For probe, it is resolved with `cloud get --name` and sent as the launch's cloud_id. - `--compute-config KEY` (test): the compute_config entry to test with, default AWS. A key the template lacks is an error rather than a silent fallback to the workspace default. Probe has no equivalent: the backend picks the entry matching the cloud. With --cloud set, the compute config name gets a slugified cloud suffix, since names are shared across clouds and a config created from the same file in another cloud would otherwise be reused. `cloud get` logs "Cloud not found." and exits 0 with empty stdout, so GetCloud treats an empty ID as not found. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
There was a problem hiding this comment.
Code Review
This pull request introduces the ability to specify a target cloud and compute configuration when running template tests and probes. It adds a new GetCloud method to retrieve cloud information, updates CreateComputeConfig to support cloud overrides via temporary configuration files, and introduces a TestTarget struct to propagate these options. Additionally, command-line flags for --cloud and --compute-config have been added to the CLI. One review comment was provided regarding a potential temporary file leak in CreateComputeConfig if tmpFile.Close() fails before defer os.Remove(tmpPath) is registered, suggesting that the defer should be registered immediately after the temporary file is successfully created.
| tmpFile, err := os.CreateTemp("", "compute-config-*.yaml") | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create temp file: %w", err) | ||
| } | ||
| tmpPath := tmpFile.Name() | ||
| if err := tmpFile.Close(); err != nil { | ||
| return fmt.Errorf("failed to close temp file: %w", err) | ||
| } | ||
| defer os.Remove(tmpPath) |
There was a problem hiding this comment.
The defer os.Remove(tmpPath) is registered after tmpFile.Close(). If tmpFile.Close() fails and returns an error, the function will exit early without registering the defer, resulting in a temporary file leak. To ensure the temporary file is always cleaned up, register the defer os.Remove(tmpPath) immediately after os.CreateTemp succeeds.
| tmpFile, err := os.CreateTemp("", "compute-config-*.yaml") | |
| if err != nil { | |
| return fmt.Errorf("failed to create temp file: %w", err) | |
| } | |
| tmpPath := tmpFile.Name() | |
| if err := tmpFile.Close(); err != nil { | |
| return fmt.Errorf("failed to close temp file: %w", err) | |
| } | |
| defer os.Remove(tmpPath) | |
| tmpFile, err := os.CreateTemp("", "compute-config-*.yaml") | |
| if err != nil { | |
| return fmt.Errorf("failed to create temp file: %w", err) | |
| } | |
| tmpPath := tmpFile.Name() | |
| defer os.Remove(tmpPath) | |
| if err := tmpFile.Close(); err != nil { | |
| return fmt.Errorf("failed to close temp file: %w", err) | |
| } |
Problem
rayapp testcan only ever test a template's AWS compute config, on the org's default cloud:setupEmptyWorkspacehardcodesc.template.ComputeConfig["AWS"], so theGCPandK8Sentries inBUILD.yamlare never exercised.cloud:key, so the compute config is created inanyscale cloud get-default(rayapp injects it for the legacy format; the SDK falls back to it for the new format), andworkspace_v2 create --compute-configinherits that cloud.rayapp probehas the same limit: it sends the default cloud's ID tofrom_template, and the backend picks the entry matching that cloud. So testing a template on GCP or a Kubernetes cloud means changing the org default, which isn't an option on shared staging.Change
--cloud NAMEtest,probe--compute-config KEYtestAWScompute_configentry to test with (GCP,K8S, …)With neither flag set, behaviour is unchanged (covered by a test).
testwith--cloud:cloud:into a temp copy of the compute config, in both formats. A legacy file's existingcloud:is replaced, and a new-format file would otherwise land in the default cloud. The source file is not modified.workspace_v2 create --cloud.basic-single-node-k8s-<cloud>). Compute config names are shared across clouds, so without the suffix, a config already created from the same file in another cloud would be found byCreateComputeConfig's existence check, reused, and fail to launch.testwith--compute-config: a key the template doesn't have is an error, not a silent fallback to the workspace's default compute config, which would report success while testing the wrong thing.probewith--cloud: the cloud is resolved withanyscale cloud get --nameand its ID is sent ascloud_id.probehas no--compute-configbecause the backend picks the entry that matches the cloud.GetCloud:anyscale cloud getlogsCloud not found.and exits 0 with empty stdout for an unknown name, so an empty ID is treated as not found. Otherwise a typo would surface later as an opaque launch error.The options travel as a
TestTarget{Cloud, ComputeConfig}struct throughRunTemplateTest/RunAllTemplateTests/RunProbe, rather than as more positional strings.Note: flags must come before the template name (Go
flagstops at the first positional argument):On Kubernetes clouds, a passing
testis only trustworthy once #496 (detect remote command failure) lands.Testing
go test ./rayapp/...andgo vetpass. Pre-commit/pre-push hooks pass (gofmt, golines, raycilint).TestGetCloud: success, not found (empty stdout, exit 0), CLI failure.TestCreateComputeConfig_CloudOverride: a new-format file gainscloud:; a legacy file'scloud:is replaced; the source file is untouched.TestRunTemplateTestsWithTarget:GCPkey and named cloud give the right file, the suffixed name,cloud:in the temp copy, and--cloud/--compute-configon workspace create.TestRunTemplateTestsWithTarget_DefaultsToAWS: zero value matches today's behaviour (AWS config, no--cloud).TestRunTemplateTestsWithTarget_MissingComputeConfig: an explicit missing key errors before any workspace is created.TestProbe_WithCloud: default cloud, named cloud, and unknown cloud each produce the expectedcloud_idor error.🤖 Generated with Claude Code