Skip to content

Commit

Permalink
cloudchamber: Render list of events with capitalised event messages, …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
gabivlj authored Nov 4, 2024
1 parent 2278616 commit 89f6274
Show file tree
Hide file tree
Showing 99 changed files with 1,732 additions and 187 deletions.
7 changes: 7 additions & 0 deletions .changeset/tricky-schools-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": minor
---

Event messages are capitalized, images of wrong architectures properly show the error in `cloudchamber create`
When a new "health" enum is introduced, `wrangler cloudchamber list` won't crash anymore.
Update Cloudchamber schemas.
18 changes: 11 additions & 7 deletions packages/wrangler/src/__tests__/helpers/mock-cloudchamber.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { DeploymentType, NodeGroup } from "../../cloudchamber/client";
import {
DeploymentType,
NodeGroup,
PlacementStatusHealth,
} from "../../cloudchamber/client";
import type {
DeploymentV2,
PlacementWithEvents,
Expand Down Expand Up @@ -42,7 +46,7 @@ export const MOCK_DEPLOYMENTS: DeploymentV2[] = [
},
current_placement: {
deployment_version: 2,
status: { health: "running" },
status: { health: PlacementStatusHealth.RUNNING },
deployment_id: "2",
terminate: false,
created_at: "123",
Expand Down Expand Up @@ -91,7 +95,7 @@ export const MOCK_DEPLOYMENTS_COMPLEX: DeploymentV2[] = [
},
current_placement: {
deployment_version: 2,
status: { health: "running" },
status: { health: PlacementStatusHealth.RUNNING },
deployment_id: "2",
terminate: false,
created_at: "123",
Expand Down Expand Up @@ -137,7 +141,7 @@ export const MOCK_DEPLOYMENTS_COMPLEX: DeploymentV2[] = [
},
current_placement: {
deployment_version: 2,
status: { health: "running" },
status: { health: PlacementStatusHealth.RUNNING },
deployment_id: "2",
terminate: false,
created_at: "123",
Expand All @@ -156,7 +160,7 @@ export const MOCK_PLACEMENTS: PlacementWithEvents[] = [
deployment_version: 2,
terminate: false,
events: [],
status: { health: "stopped" },
status: { health: PlacementStatusHealth.STOPPED },
},
{
id: "3",
Expand All @@ -165,7 +169,7 @@ export const MOCK_PLACEMENTS: PlacementWithEvents[] = [
deployment_version: 3,
terminate: false,
events: [],
status: { health: "failed" },
status: { health: PlacementStatusHealth.FAILED },
},
{
id: "1",
Expand All @@ -174,6 +178,6 @@ export const MOCK_PLACEMENTS: PlacementWithEvents[] = [
deployment_version: 4,
terminate: false,
events: [],
status: { health: "running" },
status: { health: PlacementStatusHealth.RUNNING },
},
];
17 changes: 11 additions & 6 deletions packages/wrangler/src/cloudchamber/cli/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import { DeploymentsService } from "../client";
import { wrap } from "../helpers/wrap";
import { idToLocationName } from "../locations";
import { statusToColored } from "./util";
import type { Placement, State } from "../client";
import type {
DeploymentPlacementState,
Placement,
PlacementStatusHealth,
} from "../client";
import type { DeploymentV2 } from "../client/models/DeploymentV2";
import type { Status } from "../enums";

function ipv6(placement: Placement | undefined) {
if (!placement) {
Expand Down Expand Up @@ -52,12 +55,14 @@ function version(deployment: DeploymentV2) {

function health(placement?: Placement) {
if (!placement) {
return statusToColored("placing");
return statusToColored();
}

if (!placement.status["health"]) {
return statusToColored("placing");
return statusToColored();
}
return statusToColored(placement.status["health"] as Status);

return statusToColored(placement.status["health"] as PlacementStatusHealth);
}

/**
Expand All @@ -81,7 +86,7 @@ export async function loadDeployments(
undefined,
deploymentsParams?.location,
deploymentsParams?.image,
deploymentsParams?.state as State,
deploymentsParams?.state as DeploymentPlacementState | undefined,
deploymentsParams?.state
)
);
Expand Down
31 changes: 18 additions & 13 deletions packages/wrangler/src/cloudchamber/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ import {
} from "../client";
import { wrap } from "../helpers/wrap";
import { idToLocationName } from "../locations";
import { capitalize } from "./util";
import type {
CustomerImageRegistry,
DeploymentV2,
ListSSHPublicKeys,
PlacementEvent,
PlacementStatusHealth,
PlacementWithEvents,
} from "../client";
import type { EventName, Status } from "../enums";
import type { EventName } from "../enums";

export function pollRegistriesUntilCondition(
onRegistries: (registries: Array<CustomerImageRegistry>) => boolean
Expand Down Expand Up @@ -184,11 +186,11 @@ async function waitForEvent(
eventName.includes(e.name as EventName)
);
if (!event) {
if ((p.status["health"] as Status) === "failed") {
if ((p.status["health"] as PlacementStatusHealth) === "failed") {
return true;
}

if ((p.status["health"] as Status) == "stopped") {
if ((p.status["health"] as PlacementStatusHealth) == "stopped") {
return true;
}

Expand All @@ -212,7 +214,6 @@ async function waitForImagePull(deployment: DeploymentV2) {
s.stop();
if (err) {
crash(err.message);
return;
}

if (
Expand All @@ -225,13 +226,19 @@ async function waitForImagePull(deployment: DeploymentV2) {
}

if (eventPlacement.event.name == "ImagePullError") {
crash(
"Your container image couldn't be pulled, (404 not found). Did you specify the correct URL?",
`Run ${brandColor(
process.argv0 + " cloudchamber modify " + deployment.id
)} to change the deployment image`
);
return;
// TODO: We should really report here something more specific when it's not found.
// For now, the cloudchamber API always returns a 404 in the message when the
// image is not found.
if (eventPlacement.event.message.includes("404")) {
crash(
"Your container image couldn't be pulled, (404 not found). Did you specify the correct URL?",
`Run ${brandColor(
process.argv0 + " cloudchamber modify " + deployment.id
)} to change the deployment image`
);
}

crash(capitalize(eventPlacement.event.message));
}

updateStatus("Pulled your image");
Expand Down Expand Up @@ -264,7 +271,6 @@ async function waitForVMToStart(deployment: DeploymentV2) {
s.stop();
if (err) {
crash(err.message);
return;
}

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

if (err) {
crash(err.message);
return;
}

updateStatus(
Expand Down
20 changes: 16 additions & 4 deletions packages/wrangler/src/cloudchamber/cli/util.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
import { bgGreen, bgRed, bgYellow } from "@cloudflare/cli/colors";
import type { Status } from "../enums";
import { type PlacementStatusHealth } from "../client";

export function statusToColored(status?: Status): string {
export function capitalize<S extends string>(str: S): Capitalize<S> {
return (
str.length > 0 ? str[0].toUpperCase() + str.substring(1) : str
) as Capitalize<S>;
}

export function statusToColored(status?: PlacementStatusHealth): string {
if (!status) {
return bgYellow("PLACING");
}

const mappings: Record<Status, (_: string) => string> = {
placing: bgYellow,
const mappings: Record<PlacementStatusHealth, (_: string) => string> = {
pending: bgYellow,
placed: bgYellow,
running: bgGreen,
stopped: bgYellow,
stopping: bgYellow,
failed: bgRed,
unhealthy: bgRed,
complete: bgGreen,
};

if (!(status in mappings)) {
return bgYellow(status);
}

return mappings[status](status.toUpperCase());
}

Expand Down
Loading

0 comments on commit 89f6274

Please sign in to comment.