Skip to content

Commit 89f6274

Browse files
authored
cloudchamber: Render list of events with capitalised event messages, and render updated health enums. (#7132)
* cloudchamber: Deployments with checks should have their status properly rendered Also update the http client * cloudchamber: capitalize every event message
1 parent 2278616 commit 89f6274

File tree

99 files changed

+1732
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1732
-187
lines changed

.changeset/tricky-schools-heal.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Event messages are capitalized, images of wrong architectures properly show the error in `cloudchamber create`
6+
When a new "health" enum is introduced, `wrangler cloudchamber list` won't crash anymore.
7+
Update Cloudchamber schemas.

packages/wrangler/src/__tests__/helpers/mock-cloudchamber.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { DeploymentType, NodeGroup } from "../../cloudchamber/client";
1+
import {
2+
DeploymentType,
3+
NodeGroup,
4+
PlacementStatusHealth,
5+
} from "../../cloudchamber/client";
26
import type {
37
DeploymentV2,
48
PlacementWithEvents,
@@ -42,7 +46,7 @@ export const MOCK_DEPLOYMENTS: DeploymentV2[] = [
4246
},
4347
current_placement: {
4448
deployment_version: 2,
45-
status: { health: "running" },
49+
status: { health: PlacementStatusHealth.RUNNING },
4650
deployment_id: "2",
4751
terminate: false,
4852
created_at: "123",
@@ -91,7 +95,7 @@ export const MOCK_DEPLOYMENTS_COMPLEX: DeploymentV2[] = [
9195
},
9296
current_placement: {
9397
deployment_version: 2,
94-
status: { health: "running" },
98+
status: { health: PlacementStatusHealth.RUNNING },
9599
deployment_id: "2",
96100
terminate: false,
97101
created_at: "123",
@@ -137,7 +141,7 @@ export const MOCK_DEPLOYMENTS_COMPLEX: DeploymentV2[] = [
137141
},
138142
current_placement: {
139143
deployment_version: 2,
140-
status: { health: "running" },
144+
status: { health: PlacementStatusHealth.RUNNING },
141145
deployment_id: "2",
142146
terminate: false,
143147
created_at: "123",
@@ -156,7 +160,7 @@ export const MOCK_PLACEMENTS: PlacementWithEvents[] = [
156160
deployment_version: 2,
157161
terminate: false,
158162
events: [],
159-
status: { health: "stopped" },
163+
status: { health: PlacementStatusHealth.STOPPED },
160164
},
161165
{
162166
id: "3",
@@ -165,7 +169,7 @@ export const MOCK_PLACEMENTS: PlacementWithEvents[] = [
165169
deployment_version: 3,
166170
terminate: false,
167171
events: [],
168-
status: { health: "failed" },
172+
status: { health: PlacementStatusHealth.FAILED },
169173
},
170174
{
171175
id: "1",
@@ -174,6 +178,6 @@ export const MOCK_PLACEMENTS: PlacementWithEvents[] = [
174178
deployment_version: 4,
175179
terminate: false,
176180
events: [],
177-
status: { health: "running" },
181+
status: { health: PlacementStatusHealth.RUNNING },
178182
},
179183
];

packages/wrangler/src/cloudchamber/cli/deployments.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import { DeploymentsService } from "../client";
77
import { wrap } from "../helpers/wrap";
88
import { idToLocationName } from "../locations";
99
import { statusToColored } from "./util";
10-
import type { Placement, State } from "../client";
10+
import type {
11+
DeploymentPlacementState,
12+
Placement,
13+
PlacementStatusHealth,
14+
} from "../client";
1115
import type { DeploymentV2 } from "../client/models/DeploymentV2";
12-
import type { Status } from "../enums";
1316

1417
function ipv6(placement: Placement | undefined) {
1518
if (!placement) {
@@ -52,12 +55,14 @@ function version(deployment: DeploymentV2) {
5255

5356
function health(placement?: Placement) {
5457
if (!placement) {
55-
return statusToColored("placing");
58+
return statusToColored();
5659
}
60+
5761
if (!placement.status["health"]) {
58-
return statusToColored("placing");
62+
return statusToColored();
5963
}
60-
return statusToColored(placement.status["health"] as Status);
64+
65+
return statusToColored(placement.status["health"] as PlacementStatusHealth);
6166
}
6267

6368
/**
@@ -81,7 +86,7 @@ export async function loadDeployments(
8186
undefined,
8287
deploymentsParams?.location,
8388
deploymentsParams?.image,
84-
deploymentsParams?.state as State,
89+
deploymentsParams?.state as DeploymentPlacementState | undefined,
8590
deploymentsParams?.state
8691
)
8792
);

packages/wrangler/src/cloudchamber/cli/index.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ import {
1616
} from "../client";
1717
import { wrap } from "../helpers/wrap";
1818
import { idToLocationName } from "../locations";
19+
import { capitalize } from "./util";
1920
import type {
2021
CustomerImageRegistry,
2122
DeploymentV2,
2223
ListSSHPublicKeys,
2324
PlacementEvent,
25+
PlacementStatusHealth,
2426
PlacementWithEvents,
2527
} from "../client";
26-
import type { EventName, Status } from "../enums";
28+
import type { EventName } from "../enums";
2729

2830
export function pollRegistriesUntilCondition(
2931
onRegistries: (registries: Array<CustomerImageRegistry>) => boolean
@@ -184,11 +186,11 @@ async function waitForEvent(
184186
eventName.includes(e.name as EventName)
185187
);
186188
if (!event) {
187-
if ((p.status["health"] as Status) === "failed") {
189+
if ((p.status["health"] as PlacementStatusHealth) === "failed") {
188190
return true;
189191
}
190192

191-
if ((p.status["health"] as Status) == "stopped") {
193+
if ((p.status["health"] as PlacementStatusHealth) == "stopped") {
192194
return true;
193195
}
194196

@@ -212,7 +214,6 @@ async function waitForImagePull(deployment: DeploymentV2) {
212214
s.stop();
213215
if (err) {
214216
crash(err.message);
215-
return;
216217
}
217218

218219
if (
@@ -225,13 +226,19 @@ async function waitForImagePull(deployment: DeploymentV2) {
225226
}
226227

227228
if (eventPlacement.event.name == "ImagePullError") {
228-
crash(
229-
"Your container image couldn't be pulled, (404 not found). Did you specify the correct URL?",
230-
`Run ${brandColor(
231-
process.argv0 + " cloudchamber modify " + deployment.id
232-
)} to change the deployment image`
233-
);
234-
return;
229+
// TODO: We should really report here something more specific when it's not found.
230+
// For now, the cloudchamber API always returns a 404 in the message when the
231+
// image is not found.
232+
if (eventPlacement.event.message.includes("404")) {
233+
crash(
234+
"Your container image couldn't be pulled, (404 not found). Did you specify the correct URL?",
235+
`Run ${brandColor(
236+
process.argv0 + " cloudchamber modify " + deployment.id
237+
)} to change the deployment image`
238+
);
239+
}
240+
241+
crash(capitalize(eventPlacement.event.message));
235242
}
236243

237244
updateStatus("Pulled your image");
@@ -264,7 +271,6 @@ async function waitForVMToStart(deployment: DeploymentV2) {
264271
s.stop();
265272
if (err) {
266273
crash(err.message);
267-
return;
268274
}
269275

270276
if (!eventPlacement.event) {
@@ -325,7 +331,6 @@ async function waitForPlacementInstance(deployment: DeploymentV2) {
325331

326332
if (err) {
327333
crash(err.message);
328-
return;
329334
}
330335

331336
updateStatus(

packages/wrangler/src/cloudchamber/cli/util.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
import { bgGreen, bgRed, bgYellow } from "@cloudflare/cli/colors";
2-
import type { Status } from "../enums";
2+
import { type PlacementStatusHealth } from "../client";
33

4-
export function statusToColored(status?: Status): string {
4+
export function capitalize<S extends string>(str: S): Capitalize<S> {
5+
return (
6+
str.length > 0 ? str[0].toUpperCase() + str.substring(1) : str
7+
) as Capitalize<S>;
8+
}
9+
10+
export function statusToColored(status?: PlacementStatusHealth): string {
511
if (!status) {
612
return bgYellow("PLACING");
713
}
814

9-
const mappings: Record<Status, (_: string) => string> = {
10-
placing: bgYellow,
15+
const mappings: Record<PlacementStatusHealth, (_: string) => string> = {
16+
pending: bgYellow,
1117
placed: bgYellow,
1218
running: bgGreen,
1319
stopped: bgYellow,
1420
stopping: bgYellow,
1521
failed: bgRed,
22+
unhealthy: bgRed,
23+
complete: bgGreen,
1624
};
1725

26+
if (!(status in mappings)) {
27+
return bgYellow(status);
28+
}
29+
1830
return mappings[status](status.toUpperCase());
1931
}
2032

0 commit comments

Comments
 (0)