This repository has been archived by the owner on Mar 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix template panic, refactor builder construction
What I Did --------- There were some code paths that would nil-pointer panic because of a `StaticCtx` or a `ConfigCtx` that was constructed without a `Logger` field. Specifically [this path](https://github.com/replicatedcom/ship/blob/master/pkg/lifecycle/render/config/config_context.go#L147) and [this one](https://github.com/replicatedcom/ship/blob/master/pkg/templates/static_context.go#L87). Things worked fine when all was well, but if you had an issue with your usage of `{{repl }}`, referencing an unsupported template function, ship would `panic` when trying to print a warning. I also added a small sleep before exiting so the ui can bring up the "all done" page before we bail. How I did it --------- Did a big refactor of how `Builder` and `ConfigCtx` and `StaticCtx` instances are created. Instead of ```go builder := templates.NewBuilder(...) ``` or ```go builder := &templates.Builder{} ``` we now instead use a new `BuilderBuilder` struct to manage creation. A BuilderBuilder has all the dependencies needed by the underlying `Builder`s and `Ctx`s, and can pass them in during construction. So now every object that needs to create or manage a `Builder` gets a BuilderBuilder injected. And should use something like the following to get a Builder ```go staticCtx := r.BuilderBuilder.NewStaticContext() configCtx, _ := r.BuilderBuilder.NewConfigContext( configGroups, updatedValues, ) builder := r.BuilderBuilder.NewBuilder( r.BuilderBuilder.NewStaticContext(), configCtx, ) ``` This should help with `Ctx`s not getting the deps they need in some places. How to verify it --------- Write a yaml that uses `{{repl NonExistentFunctionABCDEF }}` to reference a template function that does not exist. Ensure that ship prints an informative error about the template function, instead of just panic-ing as in [this error](https://replicated.slack.com/archives/C9QQD9LHK/p1527283748000194). Description for the changelog --------- Fixes a bug in template processing that could cause panics when an unknown or unsupported template function was used.
- Loading branch information
Showing
22 changed files
with
509 additions
and
332 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
What I Did | ||
------------ | ||
|
||
|
||
How I Did it | ||
------------ | ||
|
||
|
||
How to verify it | ||
------------ | ||
|
||
|
||
Description for the Changelog | ||
------------ | ||
|
||
|
||
|
||
<!-- (thanks https://github.com/linuxkit/linuxkit for this template) --> | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.