-
Notifications
You must be signed in to change notification settings - Fork 1k
add more validation to containers config #9934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3c7b9ae
8195d2d
24e4c95
2e505f8
af4dbde
65c2c19
ddbc4dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "wrangler": patch | ||
| --- | ||
|
|
||
| Add more thorough validation to containers configuration |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2421,7 +2421,6 @@ function validateContainerApp( | |||||||||||||
| name += config === undefined ? "" : `-${envName}`; | ||||||||||||||
| containerAppOptional.name = name.toLowerCase().replace(/ /g, "-"); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if ( | ||||||||||||||
| !containerAppOptional.configuration?.image && | ||||||||||||||
| !containerAppOptional.image | ||||||||||||||
|
|
@@ -2430,6 +2429,11 @@ function validateContainerApp( | |||||||||||||
| `"containers.image" field must be defined for each container app. This should be the path to your Dockerfile or a image URI pointing to the Cloudflare registry.` | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
| if ("configuration" in containerAppOptional) { | ||||||||||||||
| diagnostics.warnings.push( | ||||||||||||||
| `"containers.configuration" is deprecated. Use top level "containers" fields instead. "configuration.image" should be "image", "configuration.disk" should be set via "instance_type".` | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Validate that we have an image configuration for this container app. | ||||||||||||||
| // For legacy reasons we have to check both at containerAppOptional.image and | ||||||||||||||
|
|
@@ -2469,19 +2473,6 @@ function validateContainerApp( | |||||||||||||
| `"containers.rollout_step_percentage" field should be a number between 25 and 100, but got ${containerAppOptional.rollout_step_percentage}` | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if ( | ||||||||||||||
| !isOptionalProperty(containerAppOptional, "rollout_kind", "string") && | ||||||||||||||
| "rollout_kind" in containerAppOptional && | ||||||||||||||
| !["full_auto", "full_manual", "none"].includes( | ||||||||||||||
| containerAppOptional.rollout_kind | ||||||||||||||
| ) | ||||||||||||||
| ) { | ||||||||||||||
| diagnostics.errors.push( | ||||||||||||||
| `"containers.rollout_kind" field should be either 'full_auto', 'full_manual' or 'none', but got ${containerAppOptional.rollout_kind}` | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Leaving for legacy reasons | ||||||||||||||
| // TODO: When cleaning up container.configuration usage in other places clean this up | ||||||||||||||
| // as well. | ||||||||||||||
|
|
@@ -2490,14 +2481,99 @@ function validateContainerApp( | |||||||||||||
| `"containers.configuration" is defined as an array, it should be an object` | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
| if ("instance_type" in containerAppOptional) { | ||||||||||||||
| validateOptionalProperty( | ||||||||||||||
| diagnostics, | ||||||||||||||
| field, | ||||||||||||||
| validateOptionalProperty( | ||||||||||||||
| diagnostics, | ||||||||||||||
| field, | ||||||||||||||
| "rollout_kind", | ||||||||||||||
| containerAppOptional.rollout_kind, | ||||||||||||||
| "string", | ||||||||||||||
| ["full_auto", "full_manual", "none"] | ||||||||||||||
| ); | ||||||||||||||
| validateOptionalProperty( | ||||||||||||||
| diagnostics, | ||||||||||||||
| field, | ||||||||||||||
| "instance_type", | ||||||||||||||
| containerAppOptional.instance_type, | ||||||||||||||
| "string", | ||||||||||||||
| ["dev", "basic", "standard"] | ||||||||||||||
| ); | ||||||||||||||
| validateOptionalProperty( | ||||||||||||||
| diagnostics, | ||||||||||||||
| field, | ||||||||||||||
| "max_instances", | ||||||||||||||
| containerAppOptional.max_instances, | ||||||||||||||
| "number" | ||||||||||||||
| ); | ||||||||||||||
| if ( | ||||||||||||||
| containerAppOptional.max_instances !== undefined && | ||||||||||||||
| containerAppOptional.max_instances < 0 | ||||||||||||||
| ) { | ||||||||||||||
| diagnostics.errors.push( | ||||||||||||||
| `"containers.max_instances" field should be a positive number, but got ${containerAppOptional.max_instances}` | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
| validateOptionalProperty( | ||||||||||||||
| diagnostics, | ||||||||||||||
| field, | ||||||||||||||
| "image_build_context", | ||||||||||||||
| containerAppOptional.image_build_context, | ||||||||||||||
| "string" | ||||||||||||||
| ); | ||||||||||||||
| validateOptionalProperty( | ||||||||||||||
| diagnostics, | ||||||||||||||
| field, | ||||||||||||||
| "image_vars", | ||||||||||||||
| containerAppOptional.image_vars, | ||||||||||||||
| "object" | ||||||||||||||
| ); | ||||||||||||||
| validateOptionalProperty( | ||||||||||||||
| diagnostics, | ||||||||||||||
| field, | ||||||||||||||
| "scheduling_policy", | ||||||||||||||
| containerAppOptional.scheduling_policy, | ||||||||||||||
| "string", | ||||||||||||||
| ["regional", "moon", "default"] | ||||||||||||||
| ); | ||||||||||||||
|
|
||||||||||||||
| // Add deprecation warnings for legacy fields | ||||||||||||||
| if ("instances" in containerAppOptional) { | ||||||||||||||
| diagnostics.warnings.push( | ||||||||||||||
| `"containers.instances" is deprecated. Use "containers.max_instances" instead.` | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
| if ("durable_objects" in containerAppOptional) { | ||||||||||||||
| diagnostics.warnings.push( | ||||||||||||||
| `"containers.durable_objects" is deprecated. Use the "class_name" field instead.` | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| validateAdditionalProperties( | ||||||||||||||
| diagnostics, | ||||||||||||||
| field, | ||||||||||||||
| Object.keys(containerAppOptional), | ||||||||||||||
| [ | ||||||||||||||
| "name", | ||||||||||||||
| "instances", | ||||||||||||||
| "max_instances", | ||||||||||||||
| "image", | ||||||||||||||
| "image_build_context", | ||||||||||||||
| "image_vars", | ||||||||||||||
| "class_name", | ||||||||||||||
| "scheduling_policy", | ||||||||||||||
| "instance_type", | ||||||||||||||
| containerAppOptional.instance_type, | ||||||||||||||
| "string", | ||||||||||||||
| ["dev", "basic", "standard"] | ||||||||||||||
| "configuration", | ||||||||||||||
| "constraints", | ||||||||||||||
| "rollout_step_percentage", | ||||||||||||||
| "rollout_kind", | ||||||||||||||
| "durable_objects", | ||||||||||||||
| ] | ||||||||||||||
| ); | ||||||||||||||
| if ("configuration" in containerAppOptional) { | ||||||||||||||
| validateAdditionalProperties( | ||||||||||||||
| diagnostics, | ||||||||||||||
| `${field}.configuration`, | ||||||||||||||
| Object.keys(containerAppOptional.configuration), | ||||||||||||||
| ["image", "secrets", "labels", "disk", "vcpu", "memory_mib"] | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think workers-sdk/packages/wrangler/src/config/environment.ts Lines 109 to 114 in 64af5da
Users shouldn't be able to set these directly in the Wrangler config anyway, they are set by the instance type.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these fields are being used right now for customers that need custom instance types, see #9962 for better handling for custom instance types
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do they need to be added to the type definition then?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'd strongly prefer to have them in the type definition so that we're not trying to read values that typescript doesn't expect to be there. they're hidden from the wrangler config schema, so we don't need to worry about showing this to the general user.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, they should be in the type definition |
||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.