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

feature: preconf #125

Merged
merged 2 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions command_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ func CmdConf(c *cli.Context) error {
nodeinfo[node.Name] = node.Type
}

if len(tnconfig.PreConf) != 0 {
for _, preConf := range tnconfig.PreConf {
preConfCmds := shell.ExecCmd(preConf.Cmds)
utils.PrintCmds(os.Stdout, preConfCmds, verbose)
}
}

for _, nodeConfig := range tnconfig.NodeConfigs {
execConfCmds := nodeConfig.ExecConf(nodeinfo[nodeConfig.Name])
for _, execConfCmd := range execConfCmds {
Expand Down
3 changes: 3 additions & 0 deletions configs/spec_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ precmd:
- cmds:
- cmd: ""
preinit:
- cmds:
- cmd: ""
preconf:
- cmds:
- cmd: ""
postinit:
Expand Down
14 changes: 14 additions & 0 deletions internal/pkg/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var log = l.New()
type Tn struct {
PreCmd []PreCmd `yaml:"precmd"`
PreInit []PreInit `yaml:"preinit"`
PreConf []PreConf `yaml:"preconf"`
PostInit []PostInit `yaml:"postinit"`
PostFini []PostFini `yaml:"postfini"`
Nodes []Node `yaml:"nodes" mapstructure:"nodes"`
Expand All @@ -38,6 +39,11 @@ type PreInit struct {
Cmds []Cmd `yaml:"cmds" mapstructure:"cmds"`
}

// PreConf
type PreConf struct {
Cmds []Cmd `yaml:"cmds" mapstructure:"cmds"`
}

// PostInit
type PostInit struct {
Cmds []Cmd `yaml:"cmds" mapstructure:"cmds"`
Expand Down Expand Up @@ -232,6 +238,13 @@ func GenerateFile() (genContent string, err error) {
},
},
}
preconf := PreConf{
Cmds: []Cmd{
Cmd{
Cmd: "",
},
},
}
postinit := PostInit{
Cmds: []Cmd{
Cmd{
Expand Down Expand Up @@ -341,6 +354,7 @@ func GenerateFile() (genContent string, err error) {
tnconfig := &Tn{
PreCmd: []PreCmd{precmd},
PreInit: []PreInit{preinit},
PreConf: []PreConf{preconf},
PostInit: []PostInit{postinit},
PostFini: []PostFini{postfini},
Nodes: []Node{nodes},
Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/shell/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func TestTn_Exec(t *testing.T) {
type fields struct {
PreCmd []PreCmd
PreInit []PreInit
PreConf []PreConf
PostInit []PostInit
PostFini []PostFini
Nodes []Node
Expand All @@ -253,6 +254,7 @@ func TestTn_Exec(t *testing.T) {
tnconfig := &Tn{
PreCmd: tt.fields.PreCmd,
PreInit: tt.fields.PreInit,
PreConf: tt.fields.PreConf,
PostInit: tt.fields.PostInit,
PostFini: tt.fields.PostFini,
Nodes: tt.fields.Nodes,
Expand Down
Loading