Merge pull request #122811 from neolit123/1.30-v1beta4-timeouts

kubeadm: keep a function with short timeout in idempotency.go
This commit is contained in:
Kubernetes Prow Robot 2024-01-17 04:37:11 +01:00 committed by GitHub
commit a4a56701b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 6 deletions

View File

@ -72,7 +72,7 @@ func (h *handler) FromDocumentMap(docmap kubeadmapi.DocumentMap) (kubeadmapi.Com
// fromConfigMap is an utility function, which will load the value of a key of a config map and use h.FromDocumentMap() to perform the parsing // fromConfigMap is an utility function, which will load the value of a key of a config map and use h.FromDocumentMap() to perform the parsing
// This is an utility func. Used by the component config support implementations. Don't use it outside of that context. // This is an utility func. Used by the component config support implementations. Don't use it outside of that context.
func (h *handler) fromConfigMap(client clientset.Interface, cmName, cmKey string, mustExist bool) (kubeadmapi.ComponentConfig, error) { func (h *handler) fromConfigMap(client clientset.Interface, cmName, cmKey string, mustExist bool) (kubeadmapi.ComponentConfig, error) {
configMap, err := apiclient.GetConfigMapWithRetry(client, metav1.NamespaceSystem, cmName) configMap, err := apiclient.GetConfigMapWithShortRetry(client, metav1.NamespaceSystem, cmName)
if err != nil { if err != nil {
if !mustExist && (apierrors.IsNotFound(err) || apierrors.IsForbidden(err)) { if !mustExist && (apierrors.IsNotFound(err) || apierrors.IsForbidden(err)) {
klog.Warningf("Warning: No %s config is loaded. Continuing without it: %v", h.GroupVersion, err) klog.Warningf("Warning: No %s config is loaded. Continuing without it: %v", h.GroupVersion, err)

View File

@ -19,6 +19,7 @@ package apiclient
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"time"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -331,13 +332,14 @@ func PatchNode(client clientset.Interface, nodeName string, patchFn func(*v1.Nod
return lastError return lastError
} }
// GetConfigMapWithRetry tries to retrieve a ConfigMap using the given client, // GetConfigMapWithShortRetry tries to retrieve a ConfigMap using the given client, retrying for a short
// retrying if we get an unexpected error. // time if it gets an unexpected error. The main usage of this function is in areas of the code that
func GetConfigMapWithRetry(client clientset.Interface, namespace, name string) (*v1.ConfigMap, error) { // fallback to a default ConfigMap value in case the one from the API cannot be quickly obtained.
func GetConfigMapWithShortRetry(client clientset.Interface, namespace, name string) (*v1.ConfigMap, error) {
var cm *v1.ConfigMap var cm *v1.ConfigMap
var lastError error var lastError error
err := wait.PollUntilContextTimeout(context.Background(), err := wait.PollUntilContextTimeout(context.Background(),
constants.KubernetesAPICallRetryInterval, kubeadmapi.GetActiveTimeouts().KubernetesAPICall.Duration, time.Millisecond*50, time.Millisecond*350,
true, func(ctx context.Context) (bool, error) { true, func(ctx context.Context) (bool, error) {
var err error var err error
cm, err = client.CoreV1().ConfigMaps(namespace).Get(ctx, name, metav1.GetOptions{}) cm, err = client.CoreV1().ConfigMaps(namespace).Get(ctx, name, metav1.GetOptions{})

View File

@ -71,7 +71,7 @@ func FetchInitConfigurationFromCluster(client clientset.Interface, printer outpu
// getInitConfigurationFromCluster is separate only for testing purposes, don't call it directly, use FetchInitConfigurationFromCluster instead // getInitConfigurationFromCluster is separate only for testing purposes, don't call it directly, use FetchInitConfigurationFromCluster instead
func getInitConfigurationFromCluster(kubeconfigDir string, client clientset.Interface, newControlPlane, skipComponentConfigs bool) (*kubeadmapi.InitConfiguration, error) { func getInitConfigurationFromCluster(kubeconfigDir string, client clientset.Interface, newControlPlane, skipComponentConfigs bool) (*kubeadmapi.InitConfiguration, error) {
// Also, the config map really should be KubeadmConfigConfigMap... // Also, the config map really should be KubeadmConfigConfigMap...
configMap, err := apiclient.GetConfigMapWithRetry(client, metav1.NamespaceSystem, constants.KubeadmConfigConfigMap) configMap, err := apiclient.GetConfigMapWithShortRetry(client, metav1.NamespaceSystem, constants.KubeadmConfigConfigMap)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to get config map") return nil, errors.Wrap(err, "failed to get config map")
} }