move Restart and Templating to config options
and run gofmt Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
@@ -6,8 +6,6 @@ type Source struct {
|
|||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
ConsulToken string `json:"consul_token"`
|
ConsulToken string `json:"consul_token"`
|
||||||
VaultToken string `json:"vault_token"`
|
VaultToken string `json:"vault_token"`
|
||||||
Templating bool `json:"templating"`
|
|
||||||
Restart bool `json:"restart"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type JobVersion struct {
|
type JobVersion struct {
|
||||||
|
14
out/main.go
14
out/main.go
@@ -19,6 +19,8 @@ type Params struct {
|
|||||||
JobPath string `json:"job_path"`
|
JobPath string `json:"job_path"`
|
||||||
Vars map[string]string `json:"vars"`
|
Vars map[string]string `json:"vars"`
|
||||||
VarFiles map[string]string `json:"var_files"`
|
VarFiles map[string]string `json:"var_files"`
|
||||||
|
Templating bool `json:"templating"`
|
||||||
|
Restart bool `json:"restart"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OutConfig struct {
|
type OutConfig struct {
|
||||||
@@ -45,7 +47,7 @@ func main() {
|
|||||||
templPath := filepath.Join(sourceDir, config.Params.JobPath)
|
templPath := filepath.Join(sourceDir, config.Params.JobPath)
|
||||||
templFile, err := ioutil.ReadFile(templPath)
|
templFile, err := ioutil.ReadFile(templPath)
|
||||||
common.Check(err, "Could not read input file "+templPath)
|
common.Check(err, "Could not read input file "+templPath)
|
||||||
if ( config.Source.Templating != false ) {
|
if config.Params.Templating != false {
|
||||||
tmpl, err := template.New("job").Parse(string(templFile))
|
tmpl, err := template.New("job").Parse(string(templFile))
|
||||||
common.Check(err, "Error parsing template")
|
common.Check(err, "Error parsing template")
|
||||||
|
|
||||||
@@ -68,7 +70,7 @@ func main() {
|
|||||||
common.Check(err, "Error writing output file")
|
common.Check(err, "Error writing output file")
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( config.Source.Restart != false ) {
|
if config.Params.Restart != false {
|
||||||
cmd := exec.Command(
|
cmd := exec.Command(
|
||||||
"nomad",
|
"nomad",
|
||||||
"job",
|
"job",
|
||||||
@@ -81,12 +83,8 @@ func main() {
|
|||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
cmd.Stderr = &out
|
cmd.Stderr = &out
|
||||||
err = cmd.Run()
|
_ = cmd.Run()
|
||||||
if err != nil {
|
//Ignore even if the job fails to purge
|
||||||
fmt.Fprintf(os.Stderr, "Error executing nomad: %s\n", err)
|
|
||||||
fmt.Fprint(os.Stderr, out.String())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cmd := exec.Command(
|
cmd := exec.Command(
|
||||||
"nomad",
|
"nomad",
|
||||||
|
Reference in New Issue
Block a user