Skip to content

Commit

Permalink
Propagate verbosity level to kind command
Browse files Browse the repository at this point in the history
  • Loading branch information
fjammes committed Nov 6, 2024
1 parent 3f841fa commit f404a50
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
8 changes: 6 additions & 2 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ func createCluster(clusterName string) {
optName = " --name " + clusterName
}

cmd_tpl := "%v create cluster --config %v%v"
verbose_opt := ""
if verbosity > 0 {
verbose_opt = " --verbosity " + fmt.Sprintf("%d", verbosity)
}

cmd_tpl := "%v create cluster --config %v%v" + verbose_opt
cmd := fmt.Sprintf(cmd_tpl, internal.Kind, kindConfigFile, optName)

_, _, err = ExecCmd(cmd, false)
Expand Down Expand Up @@ -103,7 +108,6 @@ func createCluster(clusterName string) {

slog.Info("Wait for Kubernetes nodes to be up and running")
cmd = "kubectl wait --timeout=180s --for=condition=Ready node --all"
ExecCmd(cmd, false)
_, _, err = ExecCmd(cmd, false)
if err != nil {
slog.Error("kubectl wait failed", "error", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func ExecCmd(command string, interactive bool) (string, string, error) {

var stdoutBuf, stderrBuf bytes.Buffer
if !dryRun {
slog.Info("Launch command", "command", command)
slog.Info("Run shell", "command", command)
cmd := exec.Command(ShellToUse, "-c", command)
if interactive {
cmd.Stdin = os.Stdin
Expand Down
22 changes: 12 additions & 10 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,18 @@ func GetConfig() (KtbxConfig, error) {
c.Workers = 0
}

info, err := os.Stat(c.AuditPolicy)
if err != nil {
slog.Error("Audit policy file not found", "file", c.AuditPolicy, "error", err)
return *c, errors.New("audit policy file not found: " + c.AuditPolicy)
}

if info.IsDir() {
slog.Error("Audit policy file is a directory", "file", c.AuditPolicy)
// return error
return *c, errors.New("audit policy file is a directory: " + c.AuditPolicy)
if c.AuditPolicy != "" {
info, err := os.Stat(c.AuditPolicy)
if err != nil {
slog.Error("Audit policy file not found", "file", c.AuditPolicy, "error", err)
return *c, errors.New("audit policy file not found: " + c.AuditPolicy)
}

if info.IsDir() {
slog.Error("Audit policy file is a directory", "file", c.AuditPolicy)
// return error
return *c, errors.New("audit policy file is a directory: " + c.AuditPolicy)
}
}

return *c, nil
Expand Down

0 comments on commit f404a50

Please sign in to comment.