mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 21:12:07 +00:00
Retry when update node with configmap fails.
This commit is contained in:
parent
54d6db1191
commit
a4a537d2d1
@ -124,6 +124,8 @@ const (
|
|||||||
DiscoveryRetryInterval = 5 * time.Second
|
DiscoveryRetryInterval = 5 * time.Second
|
||||||
// MarkMasterTimeout specifies how long kubeadm should wait for applying the label and taint on the master before timing out
|
// MarkMasterTimeout specifies how long kubeadm should wait for applying the label and taint on the master before timing out
|
||||||
MarkMasterTimeout = 2 * time.Minute
|
MarkMasterTimeout = 2 * time.Minute
|
||||||
|
// UpdateNodeTimeout specifies how long kubeadm should wait for updating node with the initial remote configuration of kubelet before timing out
|
||||||
|
UpdateNodeTimeout = 2 * time.Minute
|
||||||
|
|
||||||
// MinimumAddressesInServiceSubnet defines minimum amount of nodes the Service subnet should allow.
|
// MinimumAddressesInServiceSubnet defines minimum amount of nodes the Service subnet should allow.
|
||||||
// We need at least ten, because the DNS service is always at the tenth cluster clusterIP
|
// We need at least ten, because the DNS service is always at the tenth cluster clusterIP
|
||||||
@ -143,10 +145,10 @@ const (
|
|||||||
// MasterConfigurationConfigMapKey specifies in what ConfigMap key the master configuration should be stored
|
// MasterConfigurationConfigMapKey specifies in what ConfigMap key the master configuration should be stored
|
||||||
MasterConfigurationConfigMapKey = "MasterConfiguration"
|
MasterConfigurationConfigMapKey = "MasterConfiguration"
|
||||||
|
|
||||||
// KubeletBaseConfigurationConfigMap specifies in what ConfigMap in the kube-system namespace the initial remote configuration should be stored
|
// KubeletBaseConfigurationConfigMap specifies in what ConfigMap in the kube-system namespace the initial remote configuration of kubelet should be stored
|
||||||
KubeletBaseConfigurationConfigMap = "kubelet-base-config-1.9"
|
KubeletBaseConfigurationConfigMap = "kubelet-base-config-1.9"
|
||||||
|
|
||||||
// KubeletBaseConfigurationConfigMapKey specifies in what ConfigMap key the initial remote configuration should be stored
|
// KubeletBaseConfigurationConfigMapKey specifies in what ConfigMap key the initial remote configuration of kubelet should be stored
|
||||||
// TODO: Use the constant ("kubelet.config.k8s.io") defined in pkg/kubelet/kubeletconfig/util/keys/keys.go
|
// TODO: Use the constant ("kubelet.config.k8s.io") defined in pkg/kubelet/kubeletconfig/util/keys/keys.go
|
||||||
// after https://github.com/kubernetes/kubernetes/pull/53833 being merged.
|
// after https://github.com/kubernetes/kubernetes/pull/53833 being merged.
|
||||||
KubeletBaseConfigurationConfigMapKey = "kubelet"
|
KubeletBaseConfigurationConfigMapKey = "kubelet"
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
||||||
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||||
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
@ -68,41 +69,45 @@ func CreateBaseKubeletConfiguration(cfg *kubeadmapi.MasterConfiguration, client
|
|||||||
|
|
||||||
// UpdateNodeWithConfigMap updates node ConfigSource with KubeletBaseConfigurationConfigMap
|
// UpdateNodeWithConfigMap updates node ConfigSource with KubeletBaseConfigurationConfigMap
|
||||||
func UpdateNodeWithConfigMap(client clientset.Interface, nodeName string) error {
|
func UpdateNodeWithConfigMap(client clientset.Interface, nodeName string) error {
|
||||||
node, err := client.CoreV1().Nodes().Get(nodeName, metav1.GetOptions{})
|
// Loop on every falsy return. Return with an error if raised. Exit successfully if true is returned.
|
||||||
if err != nil {
|
return wait.Poll(kubeadmconstants.APICallRetryInterval, kubeadmconstants.UpdateNodeTimeout, func() (bool, error) {
|
||||||
return err
|
node, err := client.CoreV1().Nodes().Get(nodeName, metav1.GetOptions{})
|
||||||
}
|
if err != nil {
|
||||||
|
return false, nil
|
||||||
oldData, err := json.Marshal(node)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
kubeletCfg, err := client.CoreV1().ConfigMaps(metav1.NamespaceSystem).Get(kubeadmconstants.KubeletBaseConfigurationConfigMap, metav1.GetOptions{})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
node.Spec.ConfigSource.ConfigMapRef.UID = kubeletCfg.UID
|
|
||||||
|
|
||||||
newData, err := json.Marshal(node)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
patchBytes, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, v1.Node{})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := client.CoreV1().Nodes().Patch(node.Name, types.StrategicMergePatchType, patchBytes); err != nil {
|
|
||||||
if apierrs.IsConflict(err) {
|
|
||||||
fmt.Println("Temporarily unable to update node metadata due to conflict (will retry)")
|
|
||||||
}
|
}
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
oldData, err := json.Marshal(node)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
kubeletCfg, err := client.CoreV1().ConfigMaps(metav1.NamespaceSystem).Get(kubeadmconstants.KubeletBaseConfigurationConfigMap, metav1.GetOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
node.Spec.ConfigSource.ConfigMapRef.UID = kubeletCfg.UID
|
||||||
|
|
||||||
|
newData, err := json.Marshal(node)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
patchBytes, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, v1.Node{})
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := client.CoreV1().Nodes().Patch(node.Name, types.StrategicMergePatchType, patchBytes); err != nil {
|
||||||
|
if apierrs.IsConflict(err) {
|
||||||
|
fmt.Println("Temporarily unable to update node metadata due to conflict (will retry)")
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// createKubeletBaseConfigMapRBACRules creates the RBAC rules for exposing the base kubelet ConfigMap in the kube-system namespace to unauthenticated users
|
// createKubeletBaseConfigMapRBACRules creates the RBAC rules for exposing the base kubelet ConfigMap in the kube-system namespace to unauthenticated users
|
||||||
|
Loading…
Reference in New Issue
Block a user