feat(project): inject custom playbooks at arbitrary positions via playbooks order - #3191
Merged
kubesphere-prow[bot] merged 1 commit intoAug 11, 2026
Conversation
…aybooks` order Hard-coding an import slot in every builtin playbook was brittle and could not place custom playbooks at arbitrary positions. Generalize injection so users can insert custom playbooks anywhere in the top-level source playbook by weight. - Add a `playbooks` config list; each entry has `order` (float, can be fractional or negative) and `path` (template-rendered). Original plays get weights 0,1,2,... by document order; injected items are merged and sorted by a deterministic comparator: order ascending -> config items precede file plays -> definition order (duplicate order does not error). - Empty or unset `path` is skipped silently; a set path that does not exist still errors. Injection applies only to the top-level (first) source playbook. - Remove the hard-coded `inject_playbooks_path` import slot from builtin playbooks; injection now goes exclusively through the `playbooks` order list. - Add unit tests for order-based injection (incl. empty-path skip and pure import-directive anchors) and zh/en docs (framework + reference page). Signed-off-by: redscholar <blacktiledhouse@gmail.com>
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: redscholar The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
redscholar
added a commit
that referenced
this pull request
Aug 12, 2026
…aybooks` order (#3191) Hard-coding an import slot in every builtin playbook was brittle and could not place custom playbooks at arbitrary positions. Generalize injection so users can insert custom playbooks anywhere in the top-level source playbook by weight. - Add a `playbooks` config list; each entry has `order` (float, can be fractional or negative) and `path` (template-rendered). Original plays get weights 0,1,2,... by document order; injected items are merged and sorted by a deterministic comparator: order ascending -> config items precede file plays -> definition order (duplicate order does not error). - Empty or unset `path` is skipped silently; a set path that does not exist still errors. Injection applies only to the top-level (first) source playbook. - Remove the hard-coded `inject_playbooks_path` import slot from builtin playbooks; injection now goes exclusively through the `playbooks` order list. - Add unit tests for order-based injection (incl. empty-path skip and pure import-directive anchors) and zh/en docs (framework + reference page). Signed-off-by: redscholar <blacktiledhouse@gmail.com>
redscholar
added a commit
to redscholar/kubekey
that referenced
this pull request
Aug 19, 2026
…aybooks` order (kubesphere#3191) Hard-coding an import slot in every builtin playbook was brittle and could not place custom playbooks at arbitrary positions. Generalize injection so users can insert custom playbooks anywhere in the top-level source playbook by weight. - Add a `playbooks` config list; each entry has `order` (float, can be fractional or negative) and `path` (template-rendered). Original plays get weights 0,1,2,... by document order; injected items are merged and sorted by a deterministic comparator: order ascending -> config items precede file plays -> definition order (duplicate order does not error). - Empty or unset `path` is skipped silently; a set path that does not exist still errors. Injection applies only to the top-level (first) source playbook. - Remove the hard-coded `inject_playbooks_path` import slot from builtin playbooks; injection now goes exclusively through the `playbooks` order list. - Add unit tests for order-based injection (incl. empty-path skip and pure import-directive anchors) and zh/en docs (framework + reference page). Signed-off-by: redscholar <blacktiledhouse@gmail.com>
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.



/kind feature
What does this PR do
Generalizes playbook injection so custom playbooks can be inserted at any position of the top-level source playbook via a
playbooksorder list, replacing the brittle per-playbook hard-coded import slot.Background / Motivation
Overriding/modifying KubeKey's computed default parameters used to require a hard-coded
import_playbookslot (driven by aninject_playbooks_pathvariable) inserted into every builtin playbook. That approach was brittle, had to be repeated across all 11 builtin playbooks, and could only inject at a fixed position. Users wanted to inject at an arbitrary position relative to the original plays.Implementation
The top-level playbook loader now merges a configured
playbookslist into the original plays and sorts them by weight:0, 1, 2, ...by document order.order(float, can be fractional or negative) and apath(template-rendered, relative to the playbook).orderdoes not error):orderascending → config items precede file plays → definition order.pathrendered to empty / unset variable → item skipped silently; a set path that does not exist still errors.inject_playbooks_pathslot was removed from builtin playbooks (it was never part ofmain); injection now goes exclusively through theplaybooksorder list. The bundledbuiltin/core/playbooks/hook/inject_playbooks.yamlremains as a copy-paste example, documented indocs/zh|en/reference/playbooks/inject_playbooks.md.Key Changes
pkg/project/project.goloadPlaybookinjects configured playbooks at the top level and merges/sorts by order; addsplaybookInjection+injectPlaybooks; pureimport_playbookdirectives no longer leave an empty play in the result.pkg/project/project_test.goTestInjectPlaybooksOrder,TestInjectPlaybooksOrderWithImportDirective,TestInjectPlaybooksOrderEmptyPath.pkg/project/testdata/playbooks/order_*.yamldocs/zh/framework/002-playbook.md,docs/en/framework/002-playbook.mdplaybooksinjection mechanism.docs/zh/reference/playbooks/inject_playbooks.md,docs/en/reference/playbooks/inject_playbooks.mdbuiltin/core/playbooks/hook/inject_playbooks.yamlImpact
pkg/project(playbook loader).playbooksis read fromconfiggenerically).playbooksconfig list (order+path) under the playbookspec; opt-in, defaults to empty (no injection).Breaking Changes
None. The
inject_playbooks_pathhard-coded slot being removed was never present onmain, so no released behavior is changed.Which issue(s) this PR fixes:
Fixes #
Testing
Verification performed
go test ./pkg/project/...)<command>)Steps to verify
cd builtin/core/playbooks && go test ./pkg/project/...(or from repo root:go test ./pkg/project/...).TestInjectPlaybooksOrderetc. — they assert the merged/sorted ordere,d,f,g,a,b,cand empty-path skip.hook/inject_playbooks.yamlfrom a playbook'sspec.playbookswith anorder, e.g.order: 0.5, and confirm it is injected between the 0th and 1st original plays.Test coverage
New unit tests cover: order-based merge/sort (
TestInjectPlaybooksOrder), positioning relative to a pureimport_playbookdirective anchor (TestInjectPlaybooksOrderWithImportDirective), and silent skip when apathrenders empty (TestInjectPlaybooksOrderEmptyPath).Rollback
Plain revert of
27690c52(no data/state change).Does this PR introduce a user-facing change?
Checklist
.envfiles committedSigned-off-by)make build)Additional documentation, usage docs, etc.:
Notes for Reviewer
Signed-off-byonly. Re-sign locally if the repo enforces the Verified badge.go.work.sumwas intentionally left out of this PR: it drifted only due to localgo work sync/ Go toolchain version differences (extra/go.modhashes) and is unrelated to this feature.