Skip to content

Commit 6a3b1a9

Browse files
author
Christophe VILA
committed
Better error management when executing readiness check with debug logs activated
1 parent 1f4ba0f commit 6a3b1a9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pkg/kubectl/kubectl.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,15 @@ func areWorkloadsReady(k8sObjectType string, names []string, namespace string, d
8484
template := generateTemplate(names, "{{$ready := 0}}{{if .status.readyReplicas}}{{$ready = .status.readyReplicas}}{{end}}{{$current := .spec.replicas}}{{if .status.currentReplicas}}{{$current = .status.currentReplicas}}{{end}}{{$updated := 0}}{{if .status.updatedReplicas}}{{$updated = .status.updatedReplicas}}{{end}}{{printf \"{name: %s, ready: %d, current: %d, updated: %d}\" .metadata.name $ready $current $updated}}")
8585
log.Info(3, "kubectl template: %s", template)
8686
cmd := exec.Command("kubectl", "--namespace", namespace, "get", k8sObjectType, "-o", "go-template="+template)
87-
result, _ := cmd.Output()
88-
log.Info(3, "kubectl output: %s", string(result))
89-
cmd.Stdout = os.Stdout
9087
cmd.Stderr = os.Stderr
91-
_ = cmd.Run()
88+
result, err := cmd.Output()
89+
if err != nil {
90+
// Activating debug logs should not generate additional errors so let's only warn the user and go further
91+
// If there is a real error linked to kubectl execution, it will pop up just after
92+
log.Info(3, "warning: cannot get kubectl output because of an error (%s)", err)
93+
} else {
94+
log.Info(3, "kubectl output: %s", string(result))
95+
}
9296
}
9397
template := generateTemplate(names, "{{$ready := 0}}{{if .status.readyReplicas}}{{$ready = .status.readyReplicas}}{{end}}{{$current := .spec.replicas}}{{if .status.currentReplicas}}{{$current = .status.currentReplicas}}{{end}}{{$updated := 0}}{{if .status.updatedReplicas}}{{$updated = .status.updatedReplicas}}{{end}}{{if or (lt $ready .spec.replicas) (lt $current .spec.replicas) (lt $updated .spec.replicas)}}{{printf \"%s \" .metadata.name}}{{end}}")
9498
if debug {

0 commit comments

Comments
 (0)