Skip to content

Commit

Permalink
fix(clustertool): fix kubeconfig not boing loaded correctly and put s…
Browse files Browse the repository at this point in the history
…ome more silence into healthchecks
  • Loading branch information
PrivatePuffin committed Nov 7, 2024
1 parent 2a2519e commit 5e89c62
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions clustertool/pkg/gencmd/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func RunBootstrap(args []string) {
log.Info().Msgf("Bootstrap: waiting for VIP %v to come online...", helper.TalEnv["VIP_IP"])
nodestatus.WaitForHealth(helper.TalEnv["VIP_IP"], []string{"running"})

log.Info().Msgf("Bootstrap: Configuring kubectl for VIP: %v", helper.TalEnv["VIP_IP"])
log.Info().Msgf("Bootstrap: Configuring kubeconfig/kubectl for VIP: %v", helper.TalEnv["VIP_IP"])
// Ensure kubeconfig is loaded
kubeconfigcmds := GenPlain("health", helper.TalEnv["VIP_IP"], extraArgs)
kubeconfigcmds := GenPlain("kubeconfig", helper.TalEnv["VIP_IP"], extraArgs)
ExecCmd(kubeconfigcmds[0])

// Desired pod names
Expand Down
17 changes: 11 additions & 6 deletions clustertool/pkg/nodestatus/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func CheckHealth(node string, status string, silent bool) error {
if err != nil {
errstring := "healthcheck failed. status: " + string(out) + " error: " + err.Error()
if !silent {
log.Info().Msgf("Healthcheck: check on node : failed %v", node)
log.Info().Msgf("failed with error: %s", errstring)
log.Error().Msgf("Healthcheck: check on node : failed %v", node)
log.Error().Msgf("failed with error: %s", errstring)
}
log.Error().Err(err).Str("node", node).Msg("Healthcheck failed")
return errors.New(errstring)
Expand All @@ -36,17 +36,22 @@ func CheckHealth(node string, status string, silent bool) error {
response := "Healthcheck: WARN detected node " + node + " in mode " + "maintenance" + ".\nLikely a new node, so trying commands anyway. Continuing..."
log.Warn().Msg(response)
} else if status == "" && strings.Contains(out, "running") {
_, err = CheckReadyStatus(node)
_, err = CheckReadyStatus(node, silent)
if err != nil {

errstring := "healthcheck failed. status: " + string(out) + " error: " + err.Error()
log.Error().Err(err).Str("node", node).Msg("Healthcheck failed while checking readiness")

if !silent {
log.Error().Err(err).Str("node", node).Msg("Healthcheck failed while checking readiness")
}
return errors.New(errstring)
}
} else {
if !silent {
log.Info().Msgf("Healthcheck: check on node : failed %v", node)
log.Error().Str("node", node).Msg("Healthcheck failed with unexpected status")
}
log.Error().Str("node", node).Msg("Healthcheck failed with unexpected status")

return errors.New("healthcheck failed")
}
log.Debug().Str("node", node).Msg("Health check completed successfully")
Expand Down Expand Up @@ -83,7 +88,7 @@ func WaitForHealth(node string, status []string) (string, error) {
log.Debug().Str("node", node).Str("check", check).Msg("Performing initial health check")
err := CheckHealth(node, check, true)
if err == nil {
log.Info().Str("node", node).Str("status", check).Msg("Initial health check passed")
log.Debug().Str("node", node).Str("status", check).Msg("Initial health check passed")
return check, nil
}
}
Expand Down
6 changes: 4 additions & 2 deletions clustertool/pkg/nodestatus/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,17 @@ func CheckStatus(node string) (string, error) {
return string(out), nil
}

func CheckReadyStatus(node string) (string, error) {
func CheckReadyStatus(node string, silent bool) (string, error) {
log.Info().Str("node", node).Msg("Checking node readiness status")

argsslice := append(baseStatusCMD(node), "-o", "jsonpath={.spec.status.ready}")
out, err := helper.RunCommand(argsslice, true)

if err != nil {
errstring := "status: " + string(out) + " error: " + err.Error()
log.Error().Msg(errstring)
if !silent {
log.Error().Msg(errstring)
}
return "ERROR", errors.New(errstring)
}
if strings.Contains(string(out), "true") {
Expand Down

0 comments on commit 5e89c62

Please sign in to comment.