-
Notifications
You must be signed in to change notification settings - Fork 104
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
Operator Parameter and Template Verification #1106
Conversation
It is worth noting that the verifiers are by design built to follow a command pattern. It is somewhat expected that someone will request a flag to skip a specific verification and this will enable that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left couple of minor comments - I am not approving nor rejecting though. To get my approval, my main concern is what's in packages/types.go
. We've refactored the packages package recently to give it some sense of encapsulation and I feel like we're breaking it again.
First types.go
is a place for high-level exposed types for parsing packages (like the tarballs). Having a low-level code for parsing templates there feels like it's a bit abusing that place. Also the implicits are totally a renderer implementation detail in my head and now we expose them in the packages/types. I would like to see the whole template parsing being encapsulated somewhere nicely, we can pair on that when you're back if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep types.go
only about types. All the methods belong in separate packages. I strongly suggest creating a new /packages/sub-package
(can't come up with a good, single-word name yet) to avoid circular dependency hell.
Great feedback! Restructuring the packaging totally makes sense. I'll hit it on Monday after the US holiday weekend! |
Co-Authored-By: Andreas Neumann <aneumann@mesosphere.com>
…out breaking current verify or packaging
50e5181
to
fc583d6
Compare
additionally renamed `verify::Operator()` to `verify.PackageFiles` - term `Operator` is heavily overloaded both externally and in the code base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think no blockers for me, thanks 👍 I would like some parts still get more docs/a little bit of cleanup but it overall looks good already
pkg/kudoctl/cmd/verify/verify.go
Outdated
// DuplicateVerifier provides verification that there are no duplicates disallowing casing (Kudo and kudo are duplicates) | ||
type DuplicateVerifier struct { | ||
} | ||
|
||
func (DuplicateVerifier) Verify(params packages.Parameter) (warnings ParamWarnings, errors ParamErrors) { | ||
func (DuplicateVerifier) Verify(pf *packages.Files) (warnings verifier.ParamWarnings, errors verifier.ParamErrors) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we move these to verify package as well? would be nice to have all the verifiers in one package or do you see any advantage of keeping these separate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to get to the level of encapsulation @zen-dog requested which current makes sense to me as well... it is necessary for verifiers to be in different packages. The template verifiers for instance are under templates
package. To put all verifiers in a verifiers package would request exposing template details... same for other verifiers.
} | ||
|
||
//walkNodes walks the nodes of a template providing an array of parameters | ||
func walkNodes(node parse.Node, fname string, nodeMap map[string]map[string]bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is very go-template internals thing, I don't really understand all the implications of how are certain types parsed. Maybe this deserves more comments/docs or some references to go template docs?
which now looks like: ``` ./pkg/kudoctl/packages/verifier/ ├── template │ ├── parser.go │ ├── parser_test.go │ ├── verify_parameters.go │ ├── verify_parameters_test.go.go │ ├── verify_references.go │ └── verify_references_test.go └── types.go ``` - moved `templates` pkg into `verify/templates` - this is the subpkg that handles verifying templates, leaving it open to verify other things (like operator.yaml etc.) - split existing verifiers into separate files - renamed `template_parsing` to `parser` since _template_ is already in the package name
// returning errors when keys are missing. | ||
func (e *Engine) Render(tpl string, vals map[string]interface{}) (string, error) { | ||
// Template provides access to the engines template engine. | ||
func (e Engine) Template(name string) *template.Template { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little bit concerned about exposing template.Template
to the outer world. So far, go-templates as implementation details have been nicely encapsulated within the renderer
package. Exposing it here will make it harder to move to a different frontend e.g. Starlak. But that's a "future-us-problem" I guess ¯_(ツ)_/¯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This goes a long way from the initial POC 👏 Great work. A few things we still could improve:
- parsing go-templates - seems that you have a lot of context there that I'd love to see in comments.
- verify error types. would love to see
verifier.Error
encapsulating handling and printing of errors/warnings
None of that is a blocker so ✅
What this PR does / why we need it:
Provides additional package verification for operators.
This PR walks through the template nodes and provides validation associated with that which include:
This PR also provides verification on templates and their use in the operator file:
Using: Replace
go run cmd/kubectl-kudo/main.go package
withkubectl kudo
for binary use.Fixes #1077 #1080