Skip to content

Commit 08be3ed

Browse files
gabivljemily-shen
andauthored
containers: Default scheduling policy should be the default (#9621)
* containers: Default scheduling policy should be the default * appease validate changesets check --------- Co-authored-by: emily-shen <[email protected]>
1 parent d1d34fe commit 08be3ed

File tree

7 files changed

+133
-15
lines changed

7 files changed

+133
-15
lines changed

.changeset/nasty-cameras-poke.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@cloudflare/containers-shared": patch
3+
"wrangler": patch
4+
---
5+
6+
wrangler containers: 'default' scheduling policy should be the default

packages/containers-shared/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"scripts": {
1818
"check:lint": "eslint src --ext ts",
1919
"check:type": "tsc -p ./tsconfig.json && pnpm run type:tests",
20+
"deploy": "echo 'no deploy'",
2021
"test": "vitest",
2122
"test:ci": "pnpm run test run",
2223
"test:watch": "pnpm run test --testTimeout=50000 --watch",

packages/containers-shared/src/client/models/SchedulingPolicy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ export enum SchedulingPolicy {
99
MOON = "moon",
1010
GPU = "gpu",
1111
REGIONAL = "regional",
12+
FILL_METALS = "fill_metals",
13+
DEFAULT = "default",
1214
}

packages/wrangler/src/__tests__/cloudchamber/apply.test.ts

Lines changed: 111 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ describe("cloudchamber apply", () => {
127127
│ [[containers]]
128128
│ name = \\"my-container-app\\"
129129
│ instances = 3
130-
│ scheduling_policy = \\"regional\\"
130+
│ scheduling_policy = \\"default\\"
131131
132132
│ [containers.configuration]
133133
│ image = \\"./Dockerfile\\"
@@ -169,7 +169,7 @@ describe("cloudchamber apply", () => {
169169
created_at: new Date().toString(),
170170
version: 1,
171171
account_id: "1",
172-
scheduling_policy: SchedulingPolicy.REGIONAL,
172+
scheduling_policy: SchedulingPolicy.DEFAULT,
173173
configuration: {
174174
image: "./Dockerfile",
175175
},
@@ -245,7 +245,7 @@ describe("cloudchamber apply", () => {
245245
created_at: new Date().toString(),
246246
account_id: "1",
247247
version: 1,
248-
scheduling_policy: SchedulingPolicy.REGIONAL,
248+
scheduling_policy: SchedulingPolicy.DEFAULT,
249249
configuration: {
250250
image: "./Dockerfile2",
251251
},
@@ -279,7 +279,7 @@ describe("cloudchamber apply", () => {
279279
│ [[containers]]
280280
│ name = \\"my-container-app-2\\"
281281
│ max_instances = 3
282-
│ scheduling_policy = \\"regional\\"
282+
│ scheduling_policy = \\"default\\"
283283
284284
│ [containers.configuration]
285285
│ image = \\"other-app/Dockerfile\\"
@@ -335,7 +335,7 @@ describe("cloudchamber apply", () => {
335335
created_at: new Date().toString(),
336336
account_id: "1",
337337
version: 1,
338-
scheduling_policy: SchedulingPolicy.REGIONAL,
338+
scheduling_policy: SchedulingPolicy.DEFAULT,
339339
configuration: {
340340
image: "./Dockerfile",
341341
},
@@ -366,7 +366,7 @@ describe("cloudchamber apply", () => {
366366
│ [[containers]]
367367
│ name = \\"my-container-app-2\\"
368368
│ instances = 1
369-
│ scheduling_policy = \\"regional\\"
369+
│ scheduling_policy = \\"default\\"
370370
371371
│ [containers.configuration]
372372
│ image = \\"other-app/Dockerfile\\"
@@ -416,7 +416,7 @@ describe("cloudchamber apply", () => {
416416
created_at: new Date().toString(),
417417
account_id: "1",
418418
version: 1,
419-
scheduling_policy: SchedulingPolicy.REGIONAL,
419+
scheduling_policy: SchedulingPolicy.DEFAULT,
420420
configuration: {
421421
image: "./Dockerfile",
422422
},
@@ -447,7 +447,7 @@ describe("cloudchamber apply", () => {
447447
│ [[containers]]
448448
│ name = \\"my-container-app-2\\"
449449
│ instances = 1
450-
│ scheduling_policy = \\"regional\\"
450+
│ scheduling_policy = \\"default\\"
451451
452452
│ [containers.configuration]
453453
│ image = \\"other-app/Dockerfile\\"
@@ -518,7 +518,7 @@ describe("cloudchamber apply", () => {
518518
version: 1,
519519
created_at: new Date().toString(),
520520
account_id: "1",
521-
scheduling_policy: SchedulingPolicy.REGIONAL,
521+
scheduling_policy: SchedulingPolicy.DEFAULT,
522522
configuration: {
523523
image: "./Dockerfile",
524524
labels: [
@@ -601,7 +601,7 @@ describe("cloudchamber apply", () => {
601601
/* eslint-enable */
602602
});
603603

604-
test("can apply an application, and there is no changes", async () => {
604+
test("can apply an application, and there is no changes (retrocompatibility with regional scheduling policy)", async () => {
605605
setIsTTY(false);
606606
writeAppConfiguration({
607607
class_name: "DurableObjectClass",
@@ -646,7 +646,7 @@ describe("cloudchamber apply", () => {
646646
version: 1,
647647
created_at: new Date().toString(),
648648
account_id: "1",
649-
scheduling_policy: SchedulingPolicy.REGIONAL,
649+
scheduling_policy: SchedulingPolicy.DEFAULT,
650650
configuration: {
651651
image: "./Dockerfile",
652652
labels: [
@@ -746,7 +746,7 @@ describe("cloudchamber apply", () => {
746746
created_at: new Date().toString(),
747747
class_name: "DurableObjectClass",
748748
account_id: "1",
749-
scheduling_policy: SchedulingPolicy.REGIONAL,
749+
scheduling_policy: SchedulingPolicy.DEFAULT,
750750
configuration: {
751751
image: "./Dockerfile",
752752
labels: [
@@ -805,4 +805,103 @@ describe("cloudchamber apply", () => {
805805
expect(std.stderr).toMatchInlineSnapshot(`""`);
806806
/* eslint-enable */
807807
});
808+
809+
test("can apply an application, and there is no changes", async () => {
810+
setIsTTY(false);
811+
writeAppConfiguration({
812+
class_name: "DurableObjectClass",
813+
name: "my-container-app",
814+
instances: 3,
815+
configuration: {
816+
image: "./Dockerfile",
817+
labels: [
818+
{
819+
name: "name",
820+
value: "value",
821+
},
822+
{
823+
name: "name-2",
824+
value: "value-2",
825+
},
826+
],
827+
secrets: [
828+
{
829+
name: "MY_SECRET",
830+
type: SecretAccessType.ENV,
831+
secret: "SECRET_NAME",
832+
},
833+
{
834+
name: "MY_SECRET_1",
835+
type: SecretAccessType.ENV,
836+
secret: "SECRET_NAME_1",
837+
},
838+
{
839+
name: "MY_SECRET_2",
840+
type: SecretAccessType.ENV,
841+
secret: "SECRET_NAME_2",
842+
},
843+
],
844+
},
845+
});
846+
mockGetApplications([
847+
{
848+
id: "abc",
849+
name: "my-container-app",
850+
instances: 3,
851+
version: 1,
852+
created_at: new Date().toString(),
853+
account_id: "1",
854+
scheduling_policy: SchedulingPolicy.REGIONAL,
855+
configuration: {
856+
image: "./Dockerfile",
857+
labels: [
858+
{
859+
name: "name",
860+
value: "value",
861+
},
862+
{
863+
name: "name-2",
864+
value: "value-2",
865+
},
866+
],
867+
secrets: [
868+
{
869+
name: "MY_SECRET",
870+
type: SecretAccessType.ENV,
871+
secret: "SECRET_NAME",
872+
},
873+
{
874+
name: "MY_SECRET_1",
875+
type: SecretAccessType.ENV,
876+
secret: "SECRET_NAME_1",
877+
},
878+
{
879+
name: "MY_SECRET_2",
880+
type: SecretAccessType.ENV,
881+
secret: "SECRET_NAME_2",
882+
},
883+
],
884+
},
885+
886+
constraints: {
887+
tier: 1,
888+
},
889+
},
890+
]);
891+
await runWrangler("cloudchamber apply --json");
892+
/* eslint-disable */
893+
expect(std.stdout).toMatchInlineSnapshot(`
894+
"╭ Deploy a container application deploy changes to your application
895+
896+
│ Container application changes
897+
898+
├ no changes my-container-app
899+
900+
╰ No changes to be made
901+
902+
"
903+
`);
904+
expect(std.stderr).toMatchInlineSnapshot(`""`);
905+
/* eslint-enable */
906+
});
808907
});

packages/wrangler/src/__tests__/deploy.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { randomFillSync } from "node:crypto";
44
import * as fs from "node:fs";
55
import * as path from "node:path";
66
import { PassThrough, Writable } from "node:stream";
7-
import { getCloudflareContainerRegistry } from "@cloudflare/containers-shared";
7+
import {
8+
getCloudflareContainerRegistry,
9+
SchedulingPolicy,
10+
} from "@cloudflare/containers-shared";
811
import * as TOML from "@iarna/toml";
912
import { sync } from "command-exists";
1013
import * as esbuild from "esbuild";
@@ -9129,6 +9132,7 @@ addEventListener('fetch', event => {});`
91299132
name: "my-container",
91309133
instances: 10,
91319134
durable_objects: { namespace_id: "1" },
9135+
scheduling_policy: SchedulingPolicy.DEFAULT,
91329136
});
91339137

91349138
fs.writeFileSync(

packages/wrangler/src/cloudchamber/apply.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function containerAppToCreateApplication(
120120
instances: containerApp.instances ?? 0,
121121
scheduling_policy:
122122
(containerApp.scheduling_policy as SchedulingPolicy) ??
123-
SchedulingPolicy.REGIONAL,
123+
SchedulingPolicy.DEFAULT,
124124
constraints: {
125125
...(containerApp.constraints ??
126126
(!skipDefaults ? { tier: 1 } : undefined)),
@@ -393,6 +393,12 @@ export async function apply(
393393
stripUndefined(applicationToCreateApplication(application))
394394
);
395395

396+
// fill up fields that their defaults were changed over-time,
397+
// maintaining retrocompatibility with the existing app
398+
if (appConfigNoDefaults.scheduling_policy === undefined) {
399+
appConfig.scheduling_policy = prevApp.scheduling_policy;
400+
}
401+
396402
if (
397403
prevApp.durable_objects !== undefined &&
398404
appConfigNoDefaults.durable_objects !== undefined &&

packages/wrangler/src/config/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export type ContainerApp = {
7373
class_name: string;
7474

7575
/** The scheduling policy of the application, default is regional */
76-
scheduling_policy?: "regional" | "moon";
76+
scheduling_policy?: "regional" | "moon" | "default";
7777

7878
/* Configuration of the container */
7979
configuration: {

0 commit comments

Comments
 (0)