Change:
Is this a BUG REPORT or FEATURE REQUEST?: /kind bug What happened: The change here removes exiternal id, but the call to instance id was not made used at all, it will always return false. At this time no node was able to register What you expected to happen: ProviderId was used in check How to reproduce it (as minimally and precisely as possible): Anything else we need to know?: Environment:
similar to are you using --cloud-provider in your controller manager? are you also setting it on your kubelet?
I'm using acs-engine to deploy the cluster. Config is as following: I've proposed a fix. PTAL
/sig cluster-lifecycle

Discussion:
return } // Node that isn't present according to the cloud provider shouldn't have its address updated <del> exists, err := ensureNodeExistsByProviderIDOrInstanceID(instances, node) </del> <ins> exists, err := ensureNodeExistsByProviderID(instances, node) </ins> if err != nil { // Continue to update node address when not sure the node is not exists glog.Errorf("%v", err)

// Check with the cloud provider to see if the node still exists. If it // doesn't, delete the node immediately. <del> exists, err := ensureNodeExistsByProviderIDOrInstanceID(instances, node) </del> <ins> exists, err := ensureNodeExistsByProviderID(instances, node) </ins> if err != nil { glog.Errorf("Error getting data for node %s from cloud: %v", node.Name, err) continue

return newTaints } <del> // ensureNodeExistsByProviderIDOrInstanceID first checks if the instance exists by the provider id and then by calling instance id with node name func ensureNodeExistsByProviderIDOrInstanceID(instances cloudprovider.Instances, node *v1.Node) (bool, error) { exists, err := instances.InstanceExistsByProviderID(context.TODO(), node.Spec.ProviderID) if err != nil { providerIDErr := err _, err = instances.InstanceID(context.TODO(), types.NodeName(node.Name)) //TODO(anupn): Changing the check as InstanceID does not return error if err == nil { return false, nil </del> <ins> // ensureNodeExistsByProviderID checks if the instance exists by the provider id, // If provider id in spec is empty it calls instanceId with node name to get provider id func ensureNodeExistsByProviderID(instances cloudprovider.Instances, node *v1.Node) (bool, error) { providerID := node.Spec.ProviderID if providerID == "" { var err error providerID, err = instances.InstanceID(context.TODO(), types.NodeName(node.Name)) if err != nil { return false, err </ins> } <del> return false, fmt.Errorf("InstanceExistsByProviderID: Error fetching by providerID: %v Error fetching by NodeName: %v", providerIDErr, err) </del> <ins> if providerID == "" { glog.Warningf("Cannot find valid providerID for node name %q, assuming non existence", node.Name) return false, nil } </ins> } <del> return exists, nil </del> <ins> return instances.InstanceExistsByProviderID(context.TODO(), providerID) </ins> } func getNodeAddressesByProviderIDOrName(instances cloudprovider.Instances, node *v1.Node) ([]v1.NodeAddress, error) {

"github.com/stretchr/testify/assert" ) <del> func TestEnsureNodeExistsByProviderIDOrNodeName(t *testing.T) { </del> <ins> func TestEnsureNodeExistsByProviderID(t *testing.T) { </ins> testCases := []struct { testName           string node               *v1.Node expectedCalls      []string <del> existsByNodeName   bool </del> <ins> expectedNodeExists bool hasInstanceID      bool </ins> existsByProviderID bool nodeNameErr        error providerIDErr      error

testName:           "node exists by provider id", existsByProviderID: true, providerIDErr:      nil, <del> existsByNodeName:   false, </del> <ins> hasInstanceID:      true, </ins> nodeNameErr:        errors.New("unimplemented"), expectedCalls:      []string{"instance-exists-by-provider-id"}, <ins> expectedNodeExists: true, </ins> node: &v1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: "node0",

testName:           "does not exist by provider id", existsByProviderID: false, providerIDErr:      nil, <del> existsByNodeName:   false, </del> <ins> hasInstanceID:      true, </ins> nodeNameErr:        errors.New("unimplemented"), expectedCalls:      []string{"instance-exists-by-provider-id"}, <ins> expectedNodeExists: false, </ins> node: &v1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: "node0",

}, }, { <del> testName:           "node exists by node name", existsByProviderID: false, providerIDErr:      errors.New("unimplemented"), existsByNodeName:   true, </del> <ins> testName:           "exists by instance id", existsByProviderID: true, providerIDErr:      nil, hasInstanceID:      true, </ins> nodeNameErr:        nil, <del> expectedCalls:      []string{"instance-exists-by-provider-id", "instance-id"}, </del> <ins> expectedCalls:      []string{"instance-id", "instance-exists-by-provider-id"}, expectedNodeExists: true, </ins> node: &v1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: "node0", }, <del> Spec: v1.NodeSpec{ ProviderID: "node0", </del> <ins> }, }, { testName:           "does not exist by no instance id", existsByProviderID: true, providerIDErr:      nil, hasInstanceID:      false, nodeNameErr:        cloudprovider.InstanceNotFound, expectedCalls:      []string{"instance-id"}, expectedNodeExists: false, node: &v1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: "node0", </ins> }, }, }, { <del> testName:           "does not exist by node name", </del> <ins> testName:           "provider id returns error", </ins> existsByProviderID: false, providerIDErr:      errors.New("unimplemented"), <del> existsByNodeName:   false, </del> <ins> hasInstanceID:      true, </ins> nodeNameErr:        cloudprovider.InstanceNotFound, <del> expectedCalls:      []string{"instance-exists-by-provider-id", "instance-id"}, </del> <ins> expectedCalls:      []string{"instance-exists-by-provider-id"}, expectedNodeExists: false, </ins> node: &v1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: "node0",

for _, tc := range testCases { t.Run(tc.testName, func(t *testing.T) { fc := &fakecloud.FakeCloud{ <del> Exists:             tc.existsByNodeName, </del> ExistsByProviderID: tc.existsByProviderID, Err:                tc.nodeNameErr, ErrByProviderID:    tc.providerIDErr, } <ins> if tc.hasInstanceID { fc.ExtID = map[types.NodeName]string{ types.NodeName(tc.node.Name): "provider-id://a", } } </ins> instances, _ := fc.Instances() <del> exists, err := ensureNodeExistsByProviderIDOrInstanceID(instances, tc.node) assert.NoError(t, err) </del> <ins> exists, err := ensureNodeExistsByProviderID(instances, tc.node) assert.Equal(t, err, tc.providerIDErr) </ins> assert.EqualValues(t, tc.expectedCalls, fc.Calls, "expected cloud provider methods `%v` to be called but `%v` was called ", tc.expectedCalls, fc.Calls) <del> assert.False(t, tc.existsByProviderID && tc.existsByProviderID != exists, "expected exist by provider id to be `%t` but got `%t`", </del> <ins> assert.Equal(t, tc.expectedNodeExists, exists, "expected exists to be `%t` but got `%t`", </ins> tc.existsByProviderID, exists) <del> assert.False(t, tc.existsByNodeName && tc.existsByNodeName == exists, "expected exist by node name to be `%t` but got `%t`", tc.existsByNodeName, exists) assert.False(t, !tc.existsByNodeName && !tc.existsByProviderID && exists, "node is not supposed to exist") </del> }) }