mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
remove last usage of external ID
This commit is contained in:
parent
b37564d9f2
commit
d02cf10123
@ -161,7 +161,7 @@ func (ss *scaleSet) GetInstanceIDByNodeName(name string) (string, error) {
|
|||||||
// GetNodeNameByProviderID gets the node name by provider ID.
|
// GetNodeNameByProviderID gets the node name by provider ID.
|
||||||
func (ss *scaleSet) GetNodeNameByProviderID(providerID string) (types.NodeName, error) {
|
func (ss *scaleSet) GetNodeNameByProviderID(providerID string) (types.NodeName, error) {
|
||||||
// NodeName is not part of providerID for vmss instances.
|
// NodeName is not part of providerID for vmss instances.
|
||||||
scaleSetName, err := extractScaleSetNameByExternalID(providerID)
|
scaleSetName, err := extractScaleSetNameByProviderID(providerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(4).Infof("Can not extract scale set name from providerID (%s), assuming it is mananaged by availability set: %v", providerID, err)
|
glog.V(4).Infof("Can not extract scale set name from providerID (%s), assuming it is mananaged by availability set: %v", providerID, err)
|
||||||
return ss.availabilitySet.GetNodeNameByProviderID(providerID)
|
return ss.availabilitySet.GetNodeNameByProviderID(providerID)
|
||||||
@ -295,9 +295,9 @@ func getScaleSetVMInstanceID(machineName string) (string, error) {
|
|||||||
return fmt.Sprintf("%d", instanceID), nil
|
return fmt.Sprintf("%d", instanceID), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// extractScaleSetNameByExternalID extracts the scaleset name by node's externalID.
|
// extractScaleSetNameByProviderID extracts the scaleset name by node's ProviderID.
|
||||||
func extractScaleSetNameByExternalID(externalID string) (string, error) {
|
func extractScaleSetNameByProviderID(providerID string) (string, error) {
|
||||||
matches := scaleSetNameRE.FindStringSubmatch(externalID)
|
matches := scaleSetNameRE.FindStringSubmatch(providerID)
|
||||||
if len(matches) != 2 {
|
if len(matches) != 2 {
|
||||||
return "", ErrorNotVmssInstance
|
return "", ErrorNotVmssInstance
|
||||||
}
|
}
|
||||||
@ -612,7 +612,7 @@ func (ss *scaleSet) EnsureHostsInPool(serviceName string, nodes []*v1.Node, back
|
|||||||
// Construct instanceIDs from nodes.
|
// Construct instanceIDs from nodes.
|
||||||
instanceIDs := []string{}
|
instanceIDs := []string{}
|
||||||
for _, curNode := range nodes {
|
for _, curNode := range nodes {
|
||||||
curScaleSetName, err := extractScaleSetNameByExternalID(curNode.Spec.ExternalID)
|
curScaleSetName, err := extractScaleSetNameByProviderID(curNode.Spec.ProviderID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(4).Infof("Node %q is not belonging to any scale sets, omitting it", curNode.Name)
|
glog.V(4).Infof("Node %q is not belonging to any scale sets, omitting it", curNode.Name)
|
||||||
continue
|
continue
|
||||||
@ -622,9 +622,9 @@ func (ss *scaleSet) EnsureHostsInPool(serviceName string, nodes []*v1.Node, back
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
instanceID, err := getLastSegment(curNode.Spec.ExternalID)
|
instanceID, err := getLastSegment(curNode.Spec.ProviderID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to get last segment from %q: %v", curNode.Spec.ExternalID, err)
|
glog.Errorf("Failed to get last segment from %q: %v", curNode.Spec.ProviderID, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -155,27 +154,6 @@ func (gce *GCECloud) InstanceTypeByProviderID(ctx context.Context, providerID st
|
|||||||
return instance.Type, nil
|
return instance.Type, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExternalID returns the cloud provider ID of the node with the specified NodeName (deprecated).
|
|
||||||
func (gce *GCECloud) ExternalID(ctx context.Context, nodeName types.NodeName) (string, error) {
|
|
||||||
instanceName := mapNodeNameToInstanceName(nodeName)
|
|
||||||
if gce.useMetadataServer {
|
|
||||||
// Use metadata, if possible, to fetch ID. See issue #12000
|
|
||||||
if gce.isCurrentInstance(instanceName) {
|
|
||||||
externalInstanceID, err := getCurrentExternalIDViaMetadata()
|
|
||||||
if err == nil {
|
|
||||||
return externalInstanceID, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to GCE API call if metadata server fails to retrieve ID
|
|
||||||
inst, err := gce.getInstanceByName(instanceName)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return strconv.FormatUint(inst.ID, 10), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running.
|
// InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running.
|
||||||
// If false is returned with no error, the instance will be immediately deleted by the cloud controller manager.
|
// If false is returned with no error, the instance will be immediately deleted by the cloud controller manager.
|
||||||
func (gce *GCECloud) InstanceExistsByProviderID(ctx context.Context, providerID string) (bool, error) {
|
func (gce *GCECloud) InstanceExistsByProviderID(ctx context.Context, providerID string) (bool, error) {
|
||||||
@ -516,14 +494,6 @@ func getInstanceIDViaMetadata() (string, error) {
|
|||||||
return parts[0], nil
|
return parts[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCurrentExternalIDViaMetadata() (string, error) {
|
|
||||||
externalID, err := metadata.Get("instance/id")
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("couldn't get external ID: %v", err)
|
|
||||||
}
|
|
||||||
return externalID, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getCurrentMachineTypeViaMetadata() (string, error) {
|
func getCurrentMachineTypeViaMetadata() (string, error) {
|
||||||
mType, err := metadata.Get("instance/machine-type")
|
mType, err := metadata.Get("instance/machine-type")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -123,34 +123,21 @@ func (kl *Kubelet) tryRegisterWithAPIServer(node *v1.Node) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if existingNode.Spec.ExternalID == node.Spec.ExternalID {
|
glog.Infof("Node %s was previously registered", kl.nodeName)
|
||||||
glog.Infof("Node %s was previously registered", kl.nodeName)
|
|
||||||
|
|
||||||
// Edge case: the node was previously registered; reconcile
|
// Edge case: the node was previously registered; reconcile
|
||||||
// the value of the controller-managed attach-detach
|
// the value of the controller-managed attach-detach
|
||||||
// annotation.
|
// annotation.
|
||||||
requiresUpdate := kl.reconcileCMADAnnotationWithExistingNode(node, existingNode)
|
requiresUpdate := kl.reconcileCMADAnnotationWithExistingNode(node, existingNode)
|
||||||
requiresUpdate = kl.updateDefaultLabels(node, existingNode) || requiresUpdate
|
requiresUpdate = kl.updateDefaultLabels(node, existingNode) || requiresUpdate
|
||||||
if requiresUpdate {
|
if requiresUpdate {
|
||||||
if _, _, err := nodeutil.PatchNodeStatus(kl.kubeClient.CoreV1(), types.NodeName(kl.nodeName), originalNode, existingNode); err != nil {
|
if _, _, err := nodeutil.PatchNodeStatus(kl.kubeClient.CoreV1(), types.NodeName(kl.nodeName), originalNode, existingNode); err != nil {
|
||||||
glog.Errorf("Unable to reconcile node %q with API server: error updating node: %v", kl.nodeName, err)
|
glog.Errorf("Unable to reconcile node %q with API server: error updating node: %v", kl.nodeName, err)
|
||||||
return false
|
return false
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Errorf("Previously node %q had externalID %q; now it is %q; will delete and recreate.",
|
return true
|
||||||
kl.nodeName, node.Spec.ExternalID, existingNode.Spec.ExternalID,
|
|
||||||
)
|
|
||||||
if err := kl.kubeClient.CoreV1().Nodes().Delete(node.Name, nil); err != nil {
|
|
||||||
glog.Errorf("Unable to register node %q with API server: error deleting old node: %v", kl.nodeName, err)
|
|
||||||
} else {
|
|
||||||
glog.Infof("Deleted old node object %q", kl.nodeName)
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateDefaultLabels will set the default labels on the node
|
// updateDefaultLabels will set the default labels on the node
|
||||||
@ -300,18 +287,10 @@ func (kl *Kubelet) initialNode() (*v1.Node, error) {
|
|||||||
return nil, fmt.Errorf("failed to get instances from cloud provider")
|
return nil, fmt.Errorf("failed to get instances from cloud provider")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(roberthbailey): Can we do this without having credentials to talk
|
|
||||||
// to the cloud provider?
|
|
||||||
// ExternalID is deprecated, so ProviderID is retrieved using InstanceID
|
|
||||||
externalID, err := instances.InstanceID(context.TODO(), kl.nodeName)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to get external ID from cloud provider: %v", err)
|
|
||||||
}
|
|
||||||
node.Spec.ExternalID = externalID
|
|
||||||
|
|
||||||
// TODO: We can't assume that the node has credentials to talk to the
|
// TODO: We can't assume that the node has credentials to talk to the
|
||||||
// cloudprovider from arbitrary nodes. At most, we should talk to a
|
// cloudprovider from arbitrary nodes. At most, we should talk to a
|
||||||
// local metadata server here.
|
// local metadata server here.
|
||||||
|
var err error
|
||||||
if node.Spec.ProviderID == "" {
|
if node.Spec.ProviderID == "" {
|
||||||
node.Spec.ProviderID, err = cloudprovider.GetInstanceProviderID(context.TODO(), kl.cloud, kl.nodeName)
|
node.Spec.ProviderID, err = cloudprovider.GetInstanceProviderID(context.TODO(), kl.cloud, kl.nodeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -343,9 +322,8 @@ func (kl *Kubelet) initialNode() (*v1.Node, error) {
|
|||||||
node.ObjectMeta.Labels[kubeletapis.LabelZoneRegion] = zone.Region
|
node.ObjectMeta.Labels[kubeletapis.LabelZoneRegion] = zone.Region
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
node.Spec.ExternalID = kl.hostname
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kl.setNodeStatus(node)
|
kl.setNodeStatus(node)
|
||||||
|
|
||||||
return node, nil
|
return node, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user