Skip to content

Commit 0c04da9

Browse files
authored
add rollout_active_grace_period to container config (#10315)
* update api client * pass rollout_active_grace_period from config to api * add to create application too * add tests * changeset * lint * fixup validation * feedback
1 parent 76a6701 commit 0c04da9

File tree

14 files changed

+105
-6
lines changed

14 files changed

+105
-6
lines changed

.changeset/poor-hoops-cover.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Add `rollout_active_grace_period` option to containers configuration.
6+
7+
This allows users to configure how long an active container should keep running for during a rollout, before the upgrade is applied.

packages/containers-shared/src/client/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export type { ApplicationNotFoundError } from "./models/ApplicationNotFoundError
3030
export type { ApplicationPriorities } from "./models/ApplicationPriorities";
3131
export type { ApplicationPriority } from "./models/ApplicationPriority";
3232
export { ApplicationRollout } from "./models/ApplicationRollout";
33+
export type { ApplicationRolloutActiveGracePeriod } from "./models/ApplicationRolloutActiveGracePeriod";
3334
export type { ApplicationRolloutProgress } from "./models/ApplicationRolloutProgress";
3435
export type { ApplicationSchedulingHint } from "./models/ApplicationSchedulingHint";
3536
export type { ApplicationStatus } from "./models/ApplicationStatus";

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { ApplicationID } from "./ApplicationID";
1010
import type { ApplicationJobsConfig } from "./ApplicationJobsConfig";
1111
import type { ApplicationName } from "./ApplicationName";
1212
import type { ApplicationPriorities } from "./ApplicationPriorities";
13+
import type { ApplicationRolloutActiveGracePeriod } from "./ApplicationRolloutActiveGracePeriod";
1314
import type { ApplicationSchedulingHint } from "./ApplicationSchedulingHint";
1415
import type { DurableObjectsConfiguration } from "./DurableObjectsConfiguration";
1516
import type { ISO8601Timestamp } from "./ISO8601Timestamp";
@@ -43,5 +44,6 @@ export type Application = {
4344
durable_objects?: DurableObjectsConfiguration;
4445
scheduling_hint?: ApplicationSchedulingHint;
4546
active_rollout_id?: RolloutID;
47+
rollout_active_grace_period?: ApplicationRolloutActiveGracePeriod;
4648
health?: ApplicationHealth;
4749
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* istanbul ignore file */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
5+
/**
6+
* Grace period for active instances to stay alive before becoming elibile for shutdown signal due to a rollout, in seconds.
7+
* Defaults to 0.
8+
*
9+
*/
10+
export type ApplicationRolloutActiveGracePeriod = number;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { ApplicationAffinities } from "./ApplicationAffinities";
66
import type { ApplicationConstraints } from "./ApplicationConstraints";
77
import type { ApplicationJobsConfig } from "./ApplicationJobsConfig";
88
import type { ApplicationPriorities } from "./ApplicationPriorities";
9+
import type { ApplicationRolloutActiveGracePeriod } from "./ApplicationRolloutActiveGracePeriod";
910
import type { DurableObjectsConfiguration } from "./DurableObjectsConfiguration";
1011
import type { SchedulingPolicy } from "./SchedulingPolicy";
1112
import type { UserDeploymentConfiguration } from "./UserDeploymentConfiguration";
@@ -40,4 +41,5 @@ export type CreateApplicationRequest = {
4041
durable_objects?: DurableObjectsConfiguration;
4142
affinities?: ApplicationAffinities;
4243
priorities?: ApplicationPriorities;
44+
rollout_active_grace_period?: ApplicationRolloutActiveGracePeriod;
4345
};

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import type { ApplicationAffinities } from "./ApplicationAffinities";
66
import type { ApplicationConstraints } from "./ApplicationConstraints";
77
import type { ApplicationPriorities } from "./ApplicationPriorities";
8+
import type { ApplicationRolloutActiveGracePeriod } from "./ApplicationRolloutActiveGracePeriod";
89
import type { ModifyUserDeploymentConfiguration } from "./ModifyUserDeploymentConfiguration";
910
import type { SchedulingPolicy } from "./SchedulingPolicy";
1011

@@ -30,6 +31,7 @@ export type ModifyApplicationRequestBody = {
3031
priorities?: ApplicationPriorities;
3132
scheduling_policy?: SchedulingPolicy;
3233
constraints?: ApplicationConstraints;
34+
rollout_active_grace_period?: ApplicationRolloutActiveGracePeriod;
3335
/**
3436
* The deployment configuration of all deployments created by this application.
3537
* Right now, if you modify the application configuration, only new deployments

packages/containers-shared/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export type SharedContainerConfig = {
6565
rollout_step_percentage: number;
6666
/** if undefined in config, defaults to "full_auto" */
6767
rollout_kind: "full_auto" | "full_manual" | "none";
68+
rollout_active_grace_period?: number;
6869
constraints: {
6970
regions?: string[];
7071
cities?: string[];

packages/wrangler/src/__tests__/config/configuration.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,6 +2436,8 @@ describe("normalizeAndValidateConfig()", () => {
24362436
image_vars: "invalid",
24372437
scheduling_policy: "invalid",
24382438
unknown_field: "value",
2439+
rollout_active_grace_period: "60s",
2440+
rollout_step_percentage: "full",
24392441
},
24402442
],
24412443
} as unknown as RawConfig,
@@ -2453,14 +2455,43 @@ describe("normalizeAndValidateConfig()", () => {
24532455
- Expected \\"containers.image_build_context\\" to be of type string but got 123.
24542456
- The image \\"something\\" does not appear to be a valid path to a Dockerfile, or a valid image registry path:
24552457
If this is an image registry path, it needs to include at least a tag ':' (e.g: docker.io/httpd:1)
2458+
- \\"containers.rollout_step_percentage\\" field should be a number between 25 and 100, but got \\"full\\"
24562459
- Expected \\"containers.rollout_kind\\" field to be one of [\\"full_auto\\",\\"full_manual\\",\\"none\\"] but got \\"invalid\\".
2460+
- \\"containers.rollout_active_grace_period\\" field should be a positive number but got \\"60s\\"
24572461
- Expected \\"containers.max_instances\\" to be of type number but got \\"invalid\\".
24582462
- Expected \\"containers.image_vars\\" to be of type object but got \\"invalid\\".
24592463
- Expected \\"containers.scheduling_policy\\" field to be one of [\\"regional\\",\\"moon\\",\\"default\\"] but got \\"invalid\\".
24602464
- Expected \\"containers.instance_type\\" field to be one of [\\"dev\\",\\"basic\\",\\"standard\\"] but got \\"invalid\\"."
24612465
`);
24622466
});
24632467

2468+
it("should error if rollout_active_grace_period and rollout_step_percentage are out of range", () => {
2469+
const { diagnostics } = normalizeAndValidateConfig(
2470+
{
2471+
name: "test-worker",
2472+
containers: [
2473+
{
2474+
image: "blah",
2475+
class_name: "test-class",
2476+
rollout_active_grace_period: -1,
2477+
rollout_step_percentage: 10,
2478+
},
2479+
],
2480+
} as unknown as RawConfig,
2481+
undefined,
2482+
undefined,
2483+
{ env: undefined }
2484+
);
2485+
2486+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2487+
"Processing wrangler configuration:
2488+
- The image \\"blah\\" does not appear to be a valid path to a Dockerfile, or a valid image registry path:
2489+
If this is an image registry path, it needs to include at least a tag ':' (e.g: docker.io/httpd:1)
2490+
- \\"containers.rollout_step_percentage\\" field should be a number between 25 and 100, but got \\"10\\"
2491+
- \\"containers.rollout_active_grace_period\\" field should be a positive number but got \\"-1\\""
2492+
`);
2493+
});
2494+
24642495
it("should warn for deprecated container fields", () => {
24652496
const { diagnostics } = normalizeAndValidateConfig(
24662497
{

packages/wrangler/src/__tests__/containers/config.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ describe("getNormalizedContainerOptions", () => {
387387
scheduling_policy: "regional",
388388
rollout_step_percentage: 50,
389389
rollout_kind: "full_manual",
390+
rollout_active_grace_period: 600,
390391
instance_type: "basic",
391392
constraints: {
392393
tier: 2,
@@ -414,6 +415,7 @@ describe("getNormalizedContainerOptions", () => {
414415
scheduling_policy: "regional",
415416
rollout_step_percentage: 50,
416417
rollout_kind: "full_manual",
418+
rollout_active_grace_period: 600,
417419
instance_type: "basic",
418420
image_uri: "registry.example.com/test:latest",
419421
constraints: {

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ describe("wrangler deploy with containers", () => {
143143
mockGetVersion("Galaxy-Class");
144144
writeWranglerConfig({
145145
...DEFAULT_DURABLE_OBJECTS,
146-
containers: [DEFAULT_CONTAINER_FROM_REGISTRY],
146+
containers: [
147+
{
148+
...DEFAULT_CONTAINER_FROM_REGISTRY,
149+
rollout_active_grace_period: 600,
150+
},
151+
],
147152
});
148153

149154
mockGetApplications([]);
@@ -152,6 +157,7 @@ describe("wrangler deploy with containers", () => {
152157
name: "my-container",
153158
max_instances: 10,
154159
scheduling_policy: SchedulingPolicy.DEFAULT,
160+
rollout_active_grace_period: 600,
155161
});
156162

157163
await runWrangler("deploy index.js");
@@ -182,6 +188,7 @@ describe("wrangler deploy with containers", () => {
182188
│ scheduling_policy = \\"default\\"
183189
│ instances = 0
184190
│ max_instances = 10
191+
│ rollout_active_grace_period = 600
185192
186193
│ [containers.configuration]
187194
│ image = \\"docker.io/hello:world\\"
@@ -512,7 +519,12 @@ describe("wrangler deploy with containers", () => {
512519
setupDockerMocks("my-container", "Galaxy");
513520
writeWranglerConfig({
514521
...DEFAULT_DURABLE_OBJECTS,
515-
containers: [DEFAULT_CONTAINER_FROM_DOCKERFILE],
522+
containers: [
523+
{
524+
...DEFAULT_CONTAINER_FROM_DOCKERFILE,
525+
rollout_active_grace_period: 600,
526+
},
527+
],
516528
});
517529
mockGetApplications([
518530
{
@@ -540,6 +552,7 @@ describe("wrangler deploy with containers", () => {
540552
durable_objects: {
541553
namespace_id: "1",
542554
},
555+
rollout_active_grace_period: 500,
543556
},
544557
]);
545558
fs.writeFileSync("./Dockerfile", "FROM scratch");
@@ -549,6 +562,7 @@ describe("wrangler deploy with containers", () => {
549562
image: "registry.cloudflare.com/some-account-id/my-container:Galaxy",
550563
},
551564
max_instances: 10,
565+
rollout_active_grace_period: 600,
552566
});
553567
mockCreateApplicationRollout({
554568
description: "Progressive update",
@@ -570,6 +584,8 @@ describe("wrangler deploy with containers", () => {
570584
│ - max_instances = 2
571585
│ + max_instances = 10
572586
│ name = \\"my-container\\"
587+
│ - rollout_active_grace_period = 500
588+
│ + rollout_active_grace_period = 600
573589
│ scheduling_policy = \\"default\\"
574590
575591
│ [containers.configuration]

0 commit comments

Comments
 (0)