Skip to content

Commit

Permalink
[no ci] works with consul fix, needs cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
shoenig committed Jan 6, 2023
1 parent 5f1ae91 commit b26956f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions client/allocrunner/taskrunner/envoy_bootstrap_hook.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package taskrunner

import (
"bytes"
"context"
"encoding/json"
"errors"
Expand All @@ -23,6 +24,7 @@ import (
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/nomad/structs/config"
"github.com/shoenig/netlog"
"oss.indeed.com/go/libtime/decay"
)

Expand Down Expand Up @@ -266,7 +268,7 @@ func (h *envoyBootstrapHook) Prestart(ctx context.Context, req *ifs.TaskPrestart
bootstrapFilePath := filepath.Join(req.TaskDir.SecretsDir, "envoy_bootstrap.json")

// Write everything related to the command to enable debugging
bootstrapStderrPath := filepath.Join(req.TaskDir.LogDir, "envoy_bootstrap.stderr.0")
// bootstrapStderrPath := filepath.Join(req.TaskDir.LogDir, "envoy_bootstrap.stderr.0")
bootstrapEnvPath := filepath.Join(req.TaskDir.SecretsDir, ".envoy_bootstrap.env")
bootstrapCmdPath := filepath.Join(req.TaskDir.SecretsDir, ".envoy_bootstrap.cmd")

Expand Down Expand Up @@ -342,12 +344,14 @@ func (h *envoyBootstrapHook) Prestart(ctx context.Context, req *ifs.TaskPrestart
cmd.Stdout = stdout

// Redirect stderr into another file for later debugging.
stderr, fileErr := os.OpenFile(bootstrapStderrPath, os.O_RDWR|os.O_CREATE, 0644)
if fileErr != nil {
return false, fmt.Errorf("failed to create alloc/logs/envoy_bootstrap.stderr.0 for envoy: %w", fileErr)
}
defer stderr.Close()
cmd.Stderr = stderr
//stderr, fileErr := os.OpenFile(bootstrapStderrPath, os.O_RDWR|os.O_CREATE, 0644)
//if fileErr != nil {
// return false, fmt.Errorf("failed to create alloc/logs/envoy_bootstrap.stderr.0 for envoy: %w", fileErr)
//}
//defer stderr.Close()
// cmd.Stderr = stderr
buf := new(bytes.Buffer)
cmd.Stderr = buf

// Generate bootstrap
cmdErr = cmd.Run()
Expand All @@ -359,6 +363,8 @@ func (h *envoyBootstrapHook) Prestart(ctx context.Context, req *ifs.TaskPrestart
return false, nil
}

netlog.Red("create envoy", "error", buf.String())

// Command failed, prepare for retry
//
// Cleanup the bootstrap file. An errors here is not
Expand Down

0 comments on commit b26956f

Please sign in to comment.