Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ The wizard covers the whole devfile 2.3.0 schema:
- **Commands**: exec, apply and composite, each with a group, a label and attributes
- **Events**: preStart, postStart, preStop, postStop
- **Variables**: string substitution with `{{variable}}` syntax
- **Attributes**: free-form YAML on the devfile, metadata, components, commands, projects and
endpoints
- **Attributes**: free-form YAML on the devfile, components, commands, projects and endpoints

[`SCHEMA_COVERAGE.md`](SCHEMA_COVERAGE.md) lists every field and the validation rules applied on
top of the schema.
Expand Down
13 changes: 9 additions & 4 deletions SCHEMA_COVERAGE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Devfile 2.3.0 Schema Coverage

The wizard covers the **whole** [devfile 2.3.0 schema](https://devfile.io/docs/2.3.0/devfile-schema):
every field below can be produced through the UI, and nothing outside the schema is ever written
to the generated `devfile.yaml`.
The wizard covers the **whole** [devfile 2.3.0 schema](https://devfile.io/docs/2.3.0/devfile-schema)
apart from the fields the schema itself deprecates: every field below can be produced through the
UI, and nothing outside the schema is ever written to the generated `devfile.yaml`.

Both claims are enforced by tests. `tests/unit/schema-coverage.spec.js` walks the published schema
(vendored in `tests/schema/devfile-2.3.0.json`) and fails if the wizard cannot generate one of its
Expand All @@ -25,7 +25,12 @@ fields, or if it generates a field the schema does not define.
## metadata

`name`, `version`, `displayName`, `description`, `icon`, `language`, `projectType`, `provider`,
`tags`, `architectures`, `website`, `supportUrl`, `globalMemoryLimit`, `attributes`.
`tags`, `architectures`, `website`, `supportUrl`, `globalMemoryLimit`.

`metadata.attributes` is the one schema field the wizard does not offer: the schema deprecates it
in favour of the top-level `attributes`, which is also the only one DevWorkspace honours for
settings such as `controller.devfile.io/storage-type` or `pod-overrides`. The coverage test keeps a
list of such deprecated fields and checks the schema still marks them as deprecated.

`generateName` is also offered. It is not part of the schema, but `metadata` accepts additional
properties and Eclipse Che stacks use it to get a unique workspace name per start. It is mutually
Expand Down
10 changes: 1 addition & 9 deletions src/components/steps/MetadataStep.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,14 @@ export default function MetadataStep() {
/>
</FormSection>

<CollapsibleSection title="Metadata attributes" description="Free-form attributes attached to the metadata">
<AttributesEditor
name="metadata-attributes"
value={metadata.attributes || ''}
onChange={(text) => updateMetadata({ attributes: text })}
/>
</CollapsibleSection>

<CollapsibleSection title="Devfile attributes" description="Free-form attributes attached to the devfile itself">
<AttributesEditor
name="devfile-attributes"
value={state.devfileData.attributes || ''}
onChange={(text) =>
dispatch({ type: actions.SET_SECTION, payload: { section: 'attributes', value: text } })
}
helpText="For example controller.devfile.io/storage-type or che-theia plugin settings."
helpText="For example controller.devfile.io/storage-type or pod-overrides."
/>
</CollapsibleSection>

Expand Down
6 changes: 3 additions & 3 deletions src/utils/devfileGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,9 @@ function buildMetadata(metadata) {
architectures: strList(metadata.architectures),
website: str(metadata.website),
supportUrl: str(metadata.supportUrl),
globalMemoryLimit: str(metadata.globalMemoryLimit),
attributes: attributes(metadata.attributes)
globalMemoryLimit: str(metadata.globalMemoryLimit)
// `metadata.attributes` is deprecated by the 2.3.0 schema in favour of the
// top-level `attributes`, so the wizard never writes it.
})
}

Expand Down Expand Up @@ -1216,7 +1217,6 @@ function validateRawCommand(command, where, errors) {
*/
function validateRawState(data, errors, warnings) {
validateAttributeText(data.attributes, 'Devfile attributes', errors)
validateAttributeText(data.metadata?.attributes, 'Metadata attributes', errors)

checkMapEntries(data.variables, 'Variables', 'variable', errors)
for (const variable of data.variables || []) {
Expand Down
3 changes: 1 addition & 2 deletions src/utils/factories.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ export function createInitialDevfileData() {
architectures: [],
website: '',
supportUrl: '',
globalMemoryLimit: '',
attributes: ''
globalMemoryLimit: ''
},
attributes: '',
parent: null,
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/fixtures/devfile-states.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@ function baseState() {
architectures: ['amd64', 'arm64'],
website: 'https://devfile.io',
supportUrl: 'https://devfile.io/docs',
globalMemoryLimit: '2674Mi',
attributes: 'alpha.build-context: .'
globalMemoryLimit: '2674Mi'
},
attributes: 'controller.devfile.io/devworkspace-config:\n name: config\n namespace: devfile',
parent: null,
Expand Down
22 changes: 21 additions & 1 deletion tests/unit/schema-coverage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ function schemaPaths(node, prefix = '') {
return paths
}

/**
* Schema fields the wizard deliberately never generates because the schema
* itself deprecates them. `metadata.attributes` is superseded by the top-level
* `attributes`, and only the latter is honoured by DevWorkspace.
*/
const DEPRECATED_PATHS = new Set(['metadata.attributes'])

/** Every field a generated devfile actually contains, in the same notation. */
function instancePaths(value, prefix = '', found = new Set()) {
if (Array.isArray(value)) {
Expand All @@ -67,6 +74,17 @@ test.describe('devfile 2.3.0 schema', () => {
expect(schema.title).toBe('Devfile schema - Version 2.3.0')
})

test('the skipped fields are the ones the schema deprecates', () => {
for (const path of DEPRECATED_PATHS) {
const field = path
.split('.')
.reduce((node, key) => node?.properties?.[key], schema)

expect(field, `${path} is no longer part of the schema`).toBeTruthy()
expect(field.description, `${path} is no longer deprecated`).toContain('Deprecated')
}
})

test('generated devfiles validate against the schema', () => {
for (const state of fullCoverageStates()) {
const devfile = buildDevfile(state)
Expand Down Expand Up @@ -94,7 +112,9 @@ test.describe('devfile 2.3.0 schema', () => {
instancePaths(buildDevfile(state), '', generated)
}

const missing = schemaPaths(schema).filter((path) => !generated.has(path))
const missing = schemaPaths(schema).filter(
(path) => !generated.has(path) && !DEPRECATED_PATHS.has(path)
)

expect(missing, `fields the wizard never generates: ${missing.join(', ')}`).toEqual([])
})
Expand Down
Loading