github.com/helmwave/helmwave@v0.36.4-0.20240509190856-b35563eba4c6/pkg/hooks/config.go (about) 1 package hooks 2 3 import ( 4 "github.com/invopop/jsonschema" 5 log "github.com/sirupsen/logrus" 6 ) 7 8 var _ Hook = (*hook)(nil) 9 10 type Lifecycle struct { 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"` 13 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"` 16 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"` 19 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"` 22 } 23 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) 34 } 35 36 type hook struct { 37 Cmd string `yaml:"cmd" json:"cmd" jsonschema:"required,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"` 41 } 42 43 func (hook) JSONSchemaExtend(schema *jsonschema.Schema) { 44 schema.OneOf = []*jsonschema.Schema{ 45 { 46 Type: "string", 47 }, 48 { 49 Type: "object", 50 }, 51 } 52 schema.Type = "" 53 } 54 55 func (h *hook) Log() *log.Entry { 56 return log.WithFields(log.Fields{ 57 "cmd": h.Cmd, 58 "args": h.Args, 59 }) 60 }