kubeadm: keep a function with short timeout in idempotency.go
- Name the function GetConfigMapWithShortRetry to be easier to understand that the function is with a very short timeout. Add note that this function should be used in cases there is a fallback to local config. - Apply custom hardcoded interval of 50ms and timeout of 350ms to it. Previously the fucntion used exp backoff with 5 steps up to ~340ms.
This commit is contained in:
		@@ -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)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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{})
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user