Use context.Background() directly in kubeadm polling API calls

Replace context.TODO() and poll timeout context propagation with direct
context.Background() calls to prevent timeout errors from masking actual
API errors. Affects discovery/file.go, phases/upgrade/health.go, and
util/apiclient/wait.go for consistent error reporting.
This commit is contained in:
hoteye
2025-09-22 21:23:13 +08:00
parent 0b6dba8eb0
commit 1e4e6e10c1
2 changed files with 3 additions and 3 deletions

View File

@@ -94,7 +94,7 @@ func ValidateConfigInfo(config *clientcmdapi.Config, discoveryTimeout time.Durat
err = wait.PollUntilContextTimeout(context.Background(),
constants.DiscoveryRetryInterval, discoveryTimeout,
true, func(_ context.Context) (bool, error) {
clusterinfoCM, lastError = client.CoreV1().ConfigMaps(metav1.NamespacePublic).Get(context.TODO(), bootstrapapi.ConfigMapClusterInfo, metav1.GetOptions{})
clusterinfoCM, lastError = client.CoreV1().ConfigMaps(metav1.NamespacePublic).Get(context.Background(), bootstrapapi.ConfigMapClusterInfo, metav1.GetOptions{})
if lastError != nil {
if apierrors.IsForbidden(lastError) {
// If the request fails with a forbidden error, the cluster admin has not granted access to the cluster info configmap for anonymous clients.

View File

@@ -327,7 +327,7 @@ func (w *KubeWaiter) WaitForPodsWithLabel(kvLabel string) error {
constants.KubernetesAPICallRetryInterval, w.timeout,
true, func(_ context.Context) (bool, error) {
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.Background(), listOpts)
if err != nil {
_, _ = fmt.Fprintf(w.writer, "[apiclient] Error getting Pods with label selector %q [%v]\n", kvLabel, err)
return false, nil
@@ -493,7 +493,7 @@ func (w *KubeWaiter) WaitForStaticPodHashChange(nodeName, component, previousHas
func getStaticPodSingleHash(client clientset.Interface, nodeName string, component string) (string, error) {
staticPodName := fmt.Sprintf("%s-%s", component, nodeName)
staticPod, err := client.CoreV1().Pods(metav1.NamespaceSystem).Get(context.TODO(), staticPodName, metav1.GetOptions{})
staticPod, err := client.CoreV1().Pods(metav1.NamespaceSystem).Get(context.Background(), staticPodName, metav1.GetOptions{})
if err != nil {
return "", errors.Wrapf(err, "failed to obtain static Pod hash for component %s on Node %s", component, nodeName)
}