New 🌊 wave for @helm

Commit 9ef74a50

9ef74a50cbcaMerged

Sviatoslav Dumchenko <[email protected]> · 3 years ago · 4 files · +1 added · ~3 modified

Description

feat: use Hook interface for easier testing

Details

Commit
9ef74a50cbca
Parent
951cd92a2f12

pkg/hooks/config.gomodifiedView file

@@ -1,35 +1,43 @@
11 package hooks
22
33 import (
4- "context"
5-
4+ "github.com/invopop/jsonschema"
65 log "github.com/sirupsen/logrus"
76 )
87
8+var _ Hook = (*hook)(nil)
9+
910 type Lifecycle struct {
10- PreBuild []hook `yaml:"pre_build" json:"pre_build" jsonschema:"title=pre_build,description=pre_build hooks"`
11- PostBuild []hook `yaml:"post_build" json:"post_build" jsonschema:"title=post_build,description=post_build hooks"`
11+ PreBuild Hooks `yaml:"pre_build" json:"pre_build" jsonschema:"title=pre_build,description=pre_build hooks"`
12+ PostBuild Hooks `yaml:"post_build" json:"post_build" jsonschema:"title=post_build,description=post_build hooks"`
1213
13- PreUp []hook `yaml:"pre_up" json:"pre_up" jsonschema:"title=pre_up,description=pre_up hooks"`
14- PostUp []hook `yaml:"post_up" json:"post_up" jsonschema:"title=post_up,description=post_up hooks"`
14+ PreUp Hooks `yaml:"pre_up" json:"pre_up" jsonschema:"title=pre_up,description=pre_up hooks"`
15+ PostUp Hooks `yaml:"post_up" json:"post_up" jsonschema:"title=post_up,description=post_up hooks"`
1516
16- PreRollback []hook `yaml:"pre_rollback" json:"pre_rollback" jsonschema:"title=pre_rollback,description=pre_rollback hooks"`
17- PostRollback []hook `yaml:"post_rollback" json:"post_rollback" jsonschema:"title=post_rollback,description=post_rollback hooks"`
17+ PreRollback Hooks `yaml:"pre_rollback" json:"pre_rollback" jsonschema:"title=pre_rollback,description=pre_rollback hooks"`
18+ PostRollback Hooks `yaml:"post_rollback" json:"post_rollback" jsonschema:"title=post_rollback,description=post_rollback hooks"`
1819
19- PreDown []hook `yaml:"pre_down" json:"pre_down" jsonschema:"title=pre_down,description=pre_down hooks"`
20- PostDown []hook `yaml:"post_down" json:"post_down" jsonschema:"title=post_down,description=post_down hooks"`
20+ PreDown Hooks `yaml:"pre_down" json:"pre_down" jsonschema:"title=pre_down,description=pre_down hooks"`
21+ PostDown Hooks `yaml:"post_down" json:"post_down" jsonschema:"title=post_down,description=post_down hooks"`
2122 }
2223
23-type Hook interface {
24- Run(context.Context) error
25- Log() *log.Entry
24+type Hooks []Hook
25+
26+func (*Hooks) JSONSchema() *jsonschema.Schema {
27+ r := &jsonschema.Reflector{
28+ DoNotReference: true,
29+ RequiredFromJSONSchemaTags: true,
30+ }
31+ var l []*hook
32+
33+ return r.Reflect(&l)
2634 }
2735
2836 type hook struct {
29- Cmd string
30- Args []string
31- Show bool
32- AllowFailure bool
37+ Cmd string `yaml:"cmd" json:"cmd" jsonschema:"title=cmd,description=executable to run"`
38+ Args []string `yaml:"args" json:"args" jsonschema:"title=args,description=arguments to pass to executable"`
39+ Show bool `yaml:"show" json:"show" jsonschema:"title=show,description=whether to log command stdout,default=true"`
40+ AllowFailure bool `yaml:"allow_failure" json:"allow_failure" jsonschema:"title=allow_failure,description=whether to fail the whole helmwave if command fail,default=false"`
3341 }
3442
3543 func (h *hook) Log() *log.Entry {