Skip to content

Commit

Permalink
Updated to use sdk v0.1.5 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddie Knight authored Jun 10, 2021
1 parent 0ac6db1 commit f83ded0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
3 changes: 2 additions & 1 deletion example-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ InstallDir:
WriteDirectory:
Verbose:
AllPacks:
Run: # must be all-lowercase
LogLevel: info
Run: # must match the name of an installed service pack binary file
- "kubernetes"
# - "storage"
ServicePacks:
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ module github.com/probr/probr
go 1.14

require (
github.com/hashicorp/go-hclog v0.14.1
github.com/hashicorp/go-plugin v1.4.0
github.com/probr/probr-sdk v0.1.1
github.com/probr/probr-sdk v0.1.5
)

// For Development Only
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6J
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/probr/probr-sdk v0.1.1 h1:al8a1/Qgw41Dh/2KkpmFdmnotrtzu0g5RiFeAWv73ss=
github.com/probr/probr-sdk v0.1.1/go.mod h1:Cp/BmkTE08Q0Kw+t3YcVn89ZjMuET2sSeEKsYEiYTFQ=
github.com/probr/probr-sdk v0.1.5 h1:EqFfBiiXBCbAACL/AsGj4ynXksCXvZjeafYAiwiN2vo=
github.com/probr/probr-sdk v0.1.5/go.mod h1:Cp/BmkTE08Q0Kw+t3YcVn89ZjMuET2sSeEKsYEiYTFQ=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
Expand Down
7 changes: 5 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

sdkConfig "github.com/probr/probr-sdk/config"
"github.com/probr/probr-sdk/config/setter"
"github.com/probr/probr-sdk/logging"
)

type varOptions struct {
Expand All @@ -23,6 +24,7 @@ var Vars varOptions

// Init will set values with the content retrieved from a filepath, env vars, or defaults
func (ctx *varOptions) Init() (err error) {

if ctx.varsFileIsFound() {
sdkConfig.GlobalConfig.VarsFile = *ctx.VarsFile
ctx.decode()
Expand All @@ -31,11 +33,12 @@ func (ctx *varOptions) Init() (err error) {
return
}
} else {
log.Printf("[DEBUG] No vars file provided, unexpected behavior may occur")
log.Printf("[WARN] No vars file provided, unexpected behavior may occur")
}
sdkConfig.GlobalConfig.Init()
logging.UseLogger("core")
sdkConfig.GlobalConfig.PrepareOutputDirectory()
ctx.setEnvAndDefaults()

return
}

Expand Down
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ var (
)

func main() {

var subCommand string
if len(os.Args) > 1 {
subCommand = os.Args[1]
Expand Down
39 changes: 22 additions & 17 deletions run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
"strings"
"syscall"

hclog "github.com/hashicorp/go-hclog"
hcplugin "github.com/hashicorp/go-plugin"
sdkconfig "github.com/probr/probr-sdk/config"
"github.com/probr/probr-sdk/logging"
"github.com/probr/probr-sdk/plugin"
"github.com/probr/probr-sdk/probeengine"
"github.com/probr/probr-sdk/utils"
Expand All @@ -33,17 +34,17 @@ func CLIContext() {

// Run all plugins
if err := AllPlugins(cmdSet); err != nil {
log.Printf("[INFO] Output directory: %s", sdkconfig.GlobalConfig.WriteDirectory)
switch e := err.(type) {
case *ServicePackErrors:
log.Printf("Test Failures: %d out of %d test service packs failed", len(e.Errors), len(cmdSet))
log.Print(e.Error())
log.Printf("[ERROR] %d out of %d test service packs failed. %v", len(e.Errors), len(cmdSet), e)
os.Exit(1) // At least one service pack failed
default:
log.Printf("Internal plugin error: %v", err)
log.Print(utils.ReformatError(err.Error()))
os.Exit(2) // Internal error
}
}
log.Printf("Success")
log.Printf("[INFO] No errors encountered during plugin execution. Output directory: %s", sdkconfig.GlobalConfig.WriteDirectory)
os.Exit(0)
}

Expand Down Expand Up @@ -137,32 +138,36 @@ func getCommands() (cmdSet []*exec.Cmd, err error) {
// TODO: give any exec errors a familiar format

for _, pack := range config.Vars.Run {
binaryName, binErr := GetPackBinary(pack)
if binErr != nil {
err = binErr
cmd, err := getCommand(pack)
if err != nil {
break
}
cmd := exec.Command(binaryName)
cmd.Args = append(cmd.Args, fmt.Sprintf("--varsfile=%s", *config.Vars.VarsFile))
cmdSet = append(cmdSet, cmd)
}
log.Printf("BIN: %s", config.Vars.BinariesPath)
log.Printf("[DEBUG] Using bin: %s", config.Vars.BinariesPath)
if err == nil && len(cmdSet) == 0 {
available, _ := hcplugin.Discover("*", config.Vars.BinariesPath)
err = utils.ReformatError("No valid service packs specified. Requested: %v, Available: %v", config.Vars.Run, available)
}
return
}

// TODO
func getCommand(pack string) (cmd *exec.Cmd, err error) {
binaryName, binErr := GetPackBinary(pack)
if binErr != nil {
err = binErr
return
}
cmd = exec.Command(binaryName)
cmd.Args = append(cmd.Args, fmt.Sprintf("--varsfile=%s", *config.Vars.VarsFile))
return
}

// newClient client handles the lifecycle of a plugin application
// Plugin hosts should use one Client for each plugin executable
// (this is different from the client that manages gRPC)
func newClient(cmd *exec.Cmd) *hcplugin.Client {
logger := hclog.New(&hclog.LoggerOptions{
Name: plugin.ServicePackPluginName,
Output: os.Stdout,
Level: hclog.Debug,
})
var pluginMap = map[string]hcplugin.Plugin{
plugin.ServicePackPluginName: &plugin.ServicePackPlugin{},
}
Expand All @@ -171,6 +176,6 @@ func newClient(cmd *exec.Cmd) *hcplugin.Client {
HandshakeConfig: handshakeConfig,
Plugins: pluginMap,
Cmd: cmd,
Logger: logger,
Logger: logging.GetLogger("core"),
})
}

0 comments on commit f83ded0

Please sign in to comment.