kubeadm: use 'writer' everywhere in util/apiclient/wait.go

This commit is contained in:
Lubomir I. Ivanov 2025-03-24 21:08:17 +02:00
parent 310723b21c
commit 2037f39e20

View File

@ -246,7 +246,7 @@ func getControlPlaneComponents(podMap map[string]*v1.Pod, addressAPIServer strin
// WaitForControlPlaneComponents waits for all control plane components to report "ok". // WaitForControlPlaneComponents waits for all control plane components to report "ok".
func (w *KubeWaiter) WaitForControlPlaneComponents(podMap map[string]*v1.Pod, apiSeverAddress string) error { func (w *KubeWaiter) WaitForControlPlaneComponents(podMap map[string]*v1.Pod, apiSeverAddress string) error {
fmt.Printf("[control-plane-check] Waiting for healthy control plane components."+ _, _ = fmt.Fprintf(w.writer, "[control-plane-check] Waiting for healthy control plane components."+
" This can take up to %v\n", w.timeout) " This can take up to %v\n", w.timeout)
components, err := getControlPlaneComponents(podMap, apiSeverAddress) components, err := getControlPlaneComponents(podMap, apiSeverAddress)
@ -259,7 +259,7 @@ func (w *KubeWaiter) WaitForControlPlaneComponents(podMap map[string]*v1.Pod, ap
for _, comp := range components { for _, comp := range components {
url := fmt.Sprintf("https://%s/%s", comp.addressPort, comp.endpoint) url := fmt.Sprintf("https://%s/%s", comp.addressPort, comp.endpoint)
fmt.Printf("[control-plane-check] Checking %s at %s\n", comp.name, url) _, _ = fmt.Fprintf(w.writer, "[control-plane-check] Checking %s at %s\n", comp.name, url)
go func(comp controlPlaneComponent) { go func(comp controlPlaneComponent) {
tr := &http.Transport{ tr := &http.Transport{
@ -305,11 +305,11 @@ func (w *KubeWaiter) WaitForControlPlaneComponents(podMap map[string]*v1.Pod, ap
return true, nil return true, nil
}) })
if err != nil { if err != nil {
fmt.Printf("[control-plane-check] %s is not healthy after %v\n", comp.name, time.Since(start)) _, _ = fmt.Fprintf(w.writer, "[control-plane-check] %s is not healthy after %v\n", comp.name, time.Since(start))
errChan <- lastError errChan <- lastError
return return
} }
fmt.Printf("[control-plane-check] %s is healthy after %v\n", comp.name, time.Since(start)) _, _ = fmt.Fprintf(w.writer, "[control-plane-check] %s is healthy after %v\n", comp.name, time.Since(start))
errChan <- nil errChan <- nil
}(comp) }(comp)
} }
@ -324,7 +324,7 @@ func (w *KubeWaiter) WaitForControlPlaneComponents(podMap map[string]*v1.Pod, ap
// WaitForAPI waits for the API Server's /healthz endpoint to report "ok" // WaitForAPI waits for the API Server's /healthz endpoint to report "ok"
func (w *KubeWaiter) WaitForAPI() error { func (w *KubeWaiter) WaitForAPI() error {
fmt.Printf("[api-check] Waiting for a healthy API server. This can take up to %v\n", w.timeout) _, _ = fmt.Fprintf(w.writer, "[api-check] Waiting for a healthy API server. This can take up to %v\n", w.timeout)
start := time.Now() start := time.Now()
err := wait.PollUntilContextTimeout( err := wait.PollUntilContextTimeout(
@ -340,11 +340,11 @@ func (w *KubeWaiter) WaitForAPI() error {
return true, nil return true, nil
}) })
if err != nil { if err != nil {
fmt.Printf("[api-check] The API server is not healthy after %v\n", time.Since(start)) _, _ = fmt.Fprintf(w.writer, "[api-check] The API server is not healthy after %v\n", time.Since(start))
return err return err
} }
fmt.Printf("[api-check] The API server is healthy after %v\n", time.Since(start)) _, _ = fmt.Fprintf(w.writer, "[api-check] The API server is healthy after %v\n", time.Since(start))
return nil return nil
} }
@ -359,12 +359,12 @@ func (w *KubeWaiter) WaitForPodsWithLabel(kvLabel string) error {
listOpts := metav1.ListOptions{LabelSelector: kvLabel} listOpts := metav1.ListOptions{LabelSelector: kvLabel}
pods, err := w.client.CoreV1().Pods(metav1.NamespaceSystem).List(context.TODO(), listOpts) pods, err := w.client.CoreV1().Pods(metav1.NamespaceSystem).List(context.TODO(), listOpts)
if err != nil { if err != nil {
fmt.Fprintf(w.writer, "[apiclient] Error getting Pods with label selector %q [%v]\n", kvLabel, err) _, _ = fmt.Fprintf(w.writer, "[apiclient] Error getting Pods with label selector %q [%v]\n", kvLabel, err)
return false, nil return false, nil
} }
if lastKnownPodNumber != len(pods.Items) { if lastKnownPodNumber != len(pods.Items) {
fmt.Fprintf(w.writer, "[apiclient] Found %d Pods for label selector %s\n", len(pods.Items), kvLabel) _, _ = fmt.Fprintf(w.writer, "[apiclient] Found %d Pods for label selector %s\n", len(pods.Items), kvLabel)
lastKnownPodNumber = len(pods.Items) lastKnownPodNumber = len(pods.Items)
} }
@ -391,10 +391,10 @@ func (w *KubeWaiter) WaitForKubelet(healthzAddress string, healthzPort int32) er
) )
if healthzPort == 0 { if healthzPort == 0 {
fmt.Println("[kubelet-check] Skipping the kubelet health check because the healthz port is set to 0") _, _ = fmt.Fprintln(w.writer, "[kubelet-check] Skipping the kubelet health check because the healthz port is set to 0")
return nil return nil
} }
fmt.Printf("[kubelet-check] Waiting for a healthy kubelet at %s. This can take up to %v\n", _, _ = fmt.Fprintf(w.writer, "[kubelet-check] Waiting for a healthy kubelet at %s. This can take up to %v\n",
healthzEndpoint, w.timeout) healthzEndpoint, w.timeout)
formatError := func(cause string) error { formatError := func(cause string) error {
@ -429,11 +429,11 @@ func (w *KubeWaiter) WaitForKubelet(healthzAddress string, healthzPort int32) er
return true, nil return true, nil
}) })
if err != nil { if err != nil {
fmt.Printf("[kubelet-check] The kubelet is not healthy after %v\n", time.Since(start)) _, _ = fmt.Fprintf(w.writer, "[kubelet-check] The kubelet is not healthy after %v\n", time.Since(start))
return lastError return lastError
} }
fmt.Printf("[kubelet-check] The kubelet is healthy after %v\n", time.Since(start)) _, _ = fmt.Fprintf(w.writer, "[kubelet-check] The kubelet is healthy after %v\n", time.Since(start))
return nil return nil
} }
@ -540,10 +540,10 @@ func PrintControlPlaneErrorHelpScreen(outputWriter io.Writer, criSocket string)
Socket: criSocket, Socket: criSocket,
} }
_ = controlPlaneFailTempl.Execute(outputWriter, context) _ = controlPlaneFailTempl.Execute(outputWriter, context)
fmt.Println("") _, _ = fmt.Fprintln(outputWriter, "")
} }
// PrintKubeletErrorHelpScreen prints help text on kubelet errors. // PrintKubeletErrorHelpScreen prints help text on kubelet errors.
func PrintKubeletErrorHelpScreen(outputWriter io.Writer) { func PrintKubeletErrorHelpScreen(outputWriter io.Writer) {
fmt.Fprintln(outputWriter, kubeletFailMsg) _, _ = fmt.Fprintln(outputWriter, kubeletFailMsg)
} }