Change:
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks! If the matter is security related, please disclose it privately via --What happened: introduces a regression that func is invoked on a Node obj without , hence it can fail fetching the node addresses when the is not set. What you expected to happen: I would expect cloud-controller-manager to be able to initialize new Node. How to reproduce it (as minimally and precisely as possible): the gcp legacy-cloud-controller v1.18.1 () that the node-controller cannot initialize a new Node. Logs of the cloud-controller-manager repeated multiple times: Ensure that the Node is with the taint. Ensure that the of the Node is not set. The cloud-controller-manager is not running on the host machine and that's why it cannot call the gce matadata. But it was never a hard requirement for cloud-controller-manager to run on the host machine. Anything else we need to know?: The legacy cloud-controller-manager v1.17.x is working perfectly fine. Environment: Kubernetes version (use ):v1.18.1 Cloud provider or hardware configuration: OS (e.g: ): Kernel (e.g. ): Install tools: Network plugin and version (if this is a network-related bug): Others:
/sig cloud-provider /kind regression
/cc
can we open a new issue re:

Discussion:
return } <del> nodeAddresses, err := getNodeAddressesByProviderIDOrName(ctx, instances, node) </del> <ins> nodeAddresses, err := getNodeAddressesByProviderIDOrName(ctx, instances, node.Spec.ProviderID, node.Name) </ins> if err != nil { klog.Errorf("Error getting node addresses for node %q: %v", node.Name, err) return

// All of the returned functions are idempotent, because they are used in a retry-if-conflict // loop, meaning they could get called multiple times. func (cnc *CloudNodeController) getNodeModifiersFromCloudProvider(ctx context.Context, node *v1.Node, instances cloudprovider.Instances) ([]nodeModifier, error) { <del> var nodeModifiers []nodeModifier </del> <ins> var ( nodeModifiers []nodeModifier providerID    string err           error ) </ins> if node.Spec.ProviderID == "" { <del> providerID, err := cloudprovider.GetInstanceProviderID(ctx, cnc.cloud, types.NodeName(node.Name)) </del> <ins> providerID, err = cloudprovider.GetInstanceProviderID(ctx, cnc.cloud, types.NodeName(node.Name)) </ins> if err == nil { nodeModifiers = append(nodeModifiers, func(n *v1.Node) { if n.Spec.ProviderID == "" {

// do not, the taint will be removed, and this will not be retried return nil, err } <ins> } else { providerID = node.Spec.ProviderID </ins> } <del> nodeAddresses, err := getNodeAddressesByProviderIDOrName(ctx, instances, node) </del> <ins> nodeAddresses, err := getNodeAddressesByProviderIDOrName(ctx, instances, providerID, node.Name) </ins> if err != nil { return nil, err }

} } <del> if instanceType, err := getInstanceTypeByProviderIDOrName(ctx, instances, node); err != nil { </del> <ins> if instanceType, err := getInstanceTypeByProviderIDOrName(ctx, instances, providerID, node.Name); err != nil { </ins> return nil, err } else if instanceType != "" { klog.V(2).Infof("Adding node label from cloud provider: %s=%s", v1.LabelInstanceType, instanceType)

} if zones, ok := cnc.cloud.Zones(); ok { <del> zone, err := getZoneByProviderIDOrName(ctx, zones, node) </del> <ins> zone, err := getZoneByProviderIDOrName(ctx, zones, providerID, node.Name) </ins> if err != nil { return nil, fmt.Errorf("failed to get zone from cloud provider: %v", err) }

return instances.InstanceExistsByProviderID(ctx, providerID) } <del> func getNodeAddressesByProviderIDOrName(ctx context.Context, instances cloudprovider.Instances, node *v1.Node) ([]v1.NodeAddress, error) { nodeAddresses, err := instances.NodeAddressesByProviderID(ctx, node.Spec.ProviderID) </del> <ins> func getNodeAddressesByProviderIDOrName(ctx context.Context, instances cloudprovider.Instances, providerID, nodeName string) ([]v1.NodeAddress, error) { nodeAddresses, err := instances.NodeAddressesByProviderID(ctx, providerID) </ins> if err != nil { providerIDErr := err <del> nodeAddresses, err = instances.NodeAddresses(ctx, types.NodeName(node.Name)) </del> <ins> nodeAddresses, err = instances.NodeAddresses(ctx, types.NodeName(nodeName)) </ins> if err != nil { return nil, fmt.Errorf("error fetching node by provider ID: %v, and error by node name: %v", providerIDErr, err) }

return nodeIP, nodeIPExists } <del> func getInstanceTypeByProviderIDOrName(ctx context.Context, instances cloudprovider.Instances, node *v1.Node) (string, error) { instanceType, err := instances.InstanceTypeByProviderID(ctx, node.Spec.ProviderID) </del> <ins> // getInstanceTypeByProviderIDOrName will attempt to get the instance type of node using its providerID // then it's name. If both attempts fail, an error is returned. func getInstanceTypeByProviderIDOrName(ctx context.Context, instances cloudprovider.Instances, providerID, nodeName string) (string, error) { instanceType, err := instances.InstanceTypeByProviderID(ctx, providerID) </ins> if err != nil { providerIDErr := err <del> instanceType, err = instances.InstanceType(ctx, types.NodeName(node.Name)) </del> <ins> instanceType, err = instances.InstanceType(ctx, types.NodeName(nodeName)) </ins> if err != nil { return "", fmt.Errorf("InstanceType: Error fetching by providerID: %v Error fetching by NodeName: %v", providerIDErr, err) }

} // getZoneByProviderIDorName will attempt to get the zone of node using its providerID <del> // then it's name. If both attempts fail, an error is returned func getZoneByProviderIDOrName(ctx context.Context, zones cloudprovider.Zones, node *v1.Node) (cloudprovider.Zone, error) { zone, err := zones.GetZoneByProviderID(ctx, node.Spec.ProviderID) </del> <ins> // then it's name. If both attempts fail, an error is returned. func getZoneByProviderIDOrName(ctx context.Context, zones cloudprovider.Zones, providerID, nodeName string) (cloudprovider.Zone, error) { zone, err := zones.GetZoneByProviderID(ctx, providerID) </ins> if err != nil { providerIDErr := err <del> zone, err = zones.GetZoneByNodeName(ctx, types.NodeName(node.Name)) </del> <ins> zone, err = zones.GetZoneByNodeName(ctx, types.NodeName(nodeName)) </ins> if err != nil { return cloudprovider.Zone{}, fmt.Errorf("Zone: Error fetching by providerID: %v Error fetching by NodeName: %v", providerIDErr, err) }