Skip to content
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

Merged
merged 26 commits into from
Dec 6, 2019
Merged

Conversation

kensipe
Copy link
Member

@kensipe kensipe commented Nov 26, 2019

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:

  1. errors for template params which are not defined
  2. warnings for defined params which are not used
  3. errors for templates which are not parsable

This PR also provides verification on templates and their use in the operator file:

  1. errors for resource names which do not have associated templates
  2. warnings for templates which are not used as a resource

Using: Replace go run cmd/kubectl-kudo/main.go package with kubectl kudo for binary use.

go run cmd/kubectl-kudo/main.go package verify ../operators/repository/kafka/operator/
Warnings                                                             
parameter "SSL_ENDPOINT_IDENTIFICATION_ENABLED" defined but not used.
parameter "CUSTOM_SERVER_PROPERTIES" defined but not used.           
package is valid
go run cmd/kubectl-kudo/main.go package verify ../operators/repository/flink/docs/demo/financial-fraud/demo-operator/
Errors                                                           
parameter "download_url" in template uploader.yaml is not defined
Error: package verification errors: 1
exit status 255

Fixes #1077 #1080

pkg/kudoctl/cmd/verify/verify.go Outdated Show resolved Hide resolved
pkg/kudoctl/cmd/verify/verify.go Outdated Show resolved Hide resolved
pkg/kudoctl/packages/types.go Outdated Show resolved Hide resolved
pkg/kudoctl/packages/types.go Outdated Show resolved Hide resolved
pkg/kudoctl/packages/types.go Outdated Show resolved Hide resolved
@kensipe
Copy link
Member Author

kensipe commented Nov 26, 2019

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.

@kensipe kensipe added this to the 0.9.0 milestone Nov 26, 2019
Copy link
Contributor

@alenkacz alenkacz left a 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.

pkg/kudoctl/packages/types.go Outdated Show resolved Hide resolved
pkg/kudoctl/cmd/verify/verify.go Outdated Show resolved Hide resolved
pkg/kudoctl/cmd/verify/verify.go Outdated Show resolved Hide resolved
Copy link
Contributor

@zen-dog zen-dog left a 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.

@kensipe
Copy link
Member Author

kensipe commented Nov 27, 2019

Great feedback! Restructuring the packaging totally makes sense. I'll hit it on Monday after the US holiday weekend!

@kensipe kensipe requested a review from nfnt as a code owner December 5, 2019 17:05
additionally renamed `verify::Operator()` to `verify.PackageFiles` - term `Operator` is heavily overloaded both externally and in the code base.
Copy link
Contributor

@alenkacz alenkacz left a 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/packages/template/template_verify.go Outdated Show resolved Hide resolved
pkg/kudoctl/packages/template/template_verify.go Outdated Show resolved Hide resolved
pkg/kudoctl/packages/template/template_verify.go Outdated Show resolved Hide resolved
pkg/kudoctl/packages/types.go Outdated Show resolved Hide resolved
// 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) {
Copy link
Contributor

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?

Copy link
Member Author

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) {
Copy link
Contributor

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 {
Copy link
Contributor

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 ¯_(ツ)_/¯

pkg/kudoctl/packages/template/template_verify.go Outdated Show resolved Hide resolved
Copy link
Contributor

@zen-dog zen-dog left a 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 ✅

pkg/kudoctl/packages/verifier/template/parser.go Outdated Show resolved Hide resolved
pkg/kudoctl/cmd/package_verify.go Outdated Show resolved Hide resolved
pkg/kudoctl/packages/verifier/types.go Outdated Show resolved Hide resolved
@kensipe kensipe merged commit ef23d5a into master Dec 6, 2019
@kensipe kensipe added this to Done in KUDO Global via automation Dec 6, 2019
@kensipe kensipe deleted the ken/param-valid branch December 6, 2019 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
KUDO Global
  
Done
Development

Successfully merging this pull request may close these issues.

package verify to validate params
4 participants