Repository navigation
support import/export - #8
Merged
Merged
Conversation
state.Load did not validate the files, so an invalid target state, such as a reserved stage name, was accepted by plan.
…plan - Add the export definition (node / cluster, capability, path) to stages. - Validate the fields on load, and resolve the capability to the recipe ID on normalization (the version is ignored with a warning). - Validate the references at plan: the union of the initial and the target state for the default plan, and the definitions kept by prune.
- Add import (param name -> {from, optional}) to capabilities. The short
form `param: export` is the same as {from: export, optional: false}.
- Keep import through decoding, normalization, clone and merge; the later
definition replaces the earlier one for each param.
- At plan, check that a non-optional import refers to an export of a
preceding stage and that its param is not also set by params.
- Replace an export definition as a whole when merging target files.
The definition of a node, cluster or generator now overrides its templates, and a later template overrides an earlier one. Before, a template overrode node labels and cluster/generator fields, and an earlier template won for node capabilities.
- Add import to generators and generator templates, and keep it through clone, merge and template application. - Validate the imports of generators at plan, as for capabilities. - Add import and imported to the State JSON Schema.
- Put the import of capabilities and generators into the vertex data of the plan, as written in the State. - At the start of each stage, resolve the values of the exports of the preceding stages (in the construct order) from the current state, and stop if an export path is missing in the store. - When building the tasks of a vertex, add the imported values to a copy of the params of the job; an optional import without the export is skipped. The job data is not changed. - Resolve the export path in the same notation as the relative path of stateChanges (patch.TrimForPath / patch.ParsePath).
- After each pre-stage succeeds, record its exports in the current state: the default plan replaces and adds the definitions of the target and keeps the others, prune keeps the current definitions whose names are in the target, and destroy removes all. A failed stage leaves the record unchanged. _init and main have no exports. - Add Exports.RestrictTo and Stage.ExportMerge / ExportRestrictTo, and use ExportMerge for the plan-time checks in place of effectiveExports. - Exports.Merge no longer returns an error; it never failed. - Add SetExports to the state manager to write the exports of the stage.
- Record in `imported` of a node or cluster capability the hash of each value injected by import, keyed by param name: on construct together with the capability, and on update after the tasks succeed, replacing the previous map. A param not injected (an optional import without the export) is not recorded. Generators do not record it. - Add types.MakeHash (SHA-256 of the JSON form, in hex) and use it for Dict.Hash, so that the params and the imported values are hashed in the same way. - Simplify taskGenerator.OnComplete with early returns.
- Record the import of a node or cluster capability in the State on construct and update, in the form with from / optional, so that a later plan can detect a change of the import. - Accept import in Capability.Add, and replace the fields set as a whole (version, params, import, imported) through one helper.
Check that a value a pre-stage writes to the store reaches the params of a recipe in the main stage, and that state.json records the export definition, the normalized import and the hash of the injected value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
exportandimportto pass values between stages. A pre-stage exports a value in thestoreof a capability on one of its nodes or clusters. A capability or generator in a later stage imports it, and the recipe receives it as a param.Changes
exportto pre-stages andimportto capabilities and generators. They are kept through templates,-tmerging and normalization. The capability of an export is resolved to its recipe ID.params.importin the normalized form andimported, the hash of each injected value.planvalidates the target State after merging the-tfiles.Not included (follow-up PR)
plan, and the user guide.Testing
make unit-test: all 34 packages pass.golangci-lint run ./internal/... ./cmd/...: 0 issues.make e2e-test: pass. The newTestStage_ExportAndImportchecks that a value written in a pre-stage reaches a main-stage recipe, and thatstate.jsonrecords the export, the import and the hash of the imported value.