Skip to content

Commit

Permalink
fix no ip bug; add event if not find ecs according to ip
Browse files Browse the repository at this point in the history
  • Loading branch information
gujingit committed Jun 10, 2022
1 parent 2bfcd7c commit ca95a8e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/node/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func findCloudECSByIp(ins prvd.IInstance, node *v1.Node) (*prvd.NodeAttribute, e
klog.Infof("try to find ecs for node %s by internal ip %v", node.Name, internalIP)
cloudIns, err := ins.GetInstancesByIP(context.TODO(), internalIP)
if err != nil {
return nil, fmt.Errorf("list instances by ip %s fail: %s", node.Name, err.Error())
return nil, fmt.Errorf("list instances by ip fail: %s", err.Error())
}
if cloudIns == nil {
return nil, ErrNotFound
Expand Down
53 changes: 27 additions & 26 deletions pkg/controller/node/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,36 @@ func (m *ReconcileNode) syncCloudNode(node *corev1.Node) error {
klog.V(5).Infof("node %s is registered without cloud taint. return ok", node.Name)
return nil
}
return m.doAddCloudNode(node)

start := time.Now()
defer func() {
metric.NodeLatency.WithLabelValues("remove_taint").Observe(metric.MsSince(start))
}()

nodeRef := &corev1.ObjectReference{
Kind: "Node",
Name: node.Name,
UID: types.UID(node.Name),
Namespace: "",
}

err := m.doAddCloudNode(node)
if err != nil {
m.record.Event(
nodeRef,
corev1.EventTypeWarning,
helper.FailedAddNode,
fmt.Sprintf("Error adding node: %s", helper.GetLogMessage(err)),
)
return fmt.Errorf("doAddCloudNode %s error: %s", node.Name, err.Error())
}
m.record.Event(nodeRef, corev1.EventTypeNormal, helper.InitializedNode, "Initialize node successfully")
log.Info("Successfully initialized node", "node", node.Name)
return nil
}

// This processes nodes that were added into the cluster, and cloud initialize them if appropriate
func (m *ReconcileNode) doAddCloudNode(node *corev1.Node) error {
start := time.Now()
instance, err := findCloudECS(m.cloud, node)
if err != nil {
if err == ErrNotFound {
Expand Down Expand Up @@ -180,30 +204,7 @@ func (m *ReconcileNode) doAddCloudNode(node *corev1.Node) error {
_ = m.syncNode([]corev1.Node{*node})
return true, nil
}

nodeRef := &corev1.ObjectReference{
Kind: "Node",
Name: node.Name,
UID: types.UID(node.Name),
Namespace: "",
}

err = wait.PollImmediate(2*time.Second, 20*time.Second, initializer)
if err != nil {
m.record.Event(
nodeRef,
corev1.EventTypeWarning,
helper.FailedAddNode,
fmt.Sprintf("Error adding node: %s", helper.GetLogMessage(err)),
)
return fmt.Errorf("doAddCloudNode %s error: %s", node.Name, err.Error())
}

m.record.Event(nodeRef, corev1.EventTypeNormal, helper.InitializedNode, "Initialize node successfully")
metric.NodeLatency.WithLabelValues("remove_taint").Observe(metric.MsSince(start))
log.Info("Successfully initialized node", "node", node.Name)

return nil
return wait.PollImmediate(5*time.Second, 20*time.Second, initializer)
}

// syncNode sync the nodeAddress & cloud node existence
Expand Down
9 changes: 3 additions & 6 deletions pkg/provider/alibaba/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,9 @@ func (e *ECSProvider) GetInstancesByIP(ctx context.Context, ips []string) (*prvd
return nil, fmt.Errorf("describe instances by ip %s error: %s", ips, err.Error())
}

if len(resp.Instances.Instance) == 0 {
return nil, nil
}

if len(resp.Instances.Instance) > 1 {
return nil, fmt.Errorf("find multiple instances by ip %s", ips)
if len(resp.Instances.Instance) != 1 {
klog.V(5).Infof("RequestId: %s, API: %s, ips: %s", resp.RequestId, "DescribeInstances", req.PrivateIpAddresses)
return nil, fmt.Errorf("find none or multiple instances by ip %s", ips)
}

ins := resp.Instances.Instance[0]
Expand Down

0 comments on commit ca95a8e

Please sign in to comment.