Commit 6e251178 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #32655 from dshulyak/fix_node_fake_update

Automatic merge from submit-queue Fix FakeNodeHandler Update behaviour Two problems: 1. Get is always using Existing nodes slice, and you will for sure miss any updated data 2. Each Update adds a duplicate node entry to UpdatedNodes slice For the 1st, we will try to find a node in UpdatedNodes slice (same as for the List). 2nd - append only if there is no node with same name as updated, if there is we will replace object in UpdatedNodes slice.
parents f230e6c7 0ddaa20b
...@@ -107,6 +107,12 @@ func (m *FakeNodeHandler) Get(name string) (*api.Node, error) { ...@@ -107,6 +107,12 @@ func (m *FakeNodeHandler) Get(name string) (*api.Node, error) {
m.RequestCount++ m.RequestCount++
m.lock.Unlock() m.lock.Unlock()
}() }()
for i := range m.UpdatedNodes {
if m.UpdatedNodes[i].Name == name {
nodeCopy := *m.UpdatedNodes[i]
return &nodeCopy, nil
}
}
for i := range m.Existing { for i := range m.Existing {
if m.Existing[i].Name == name { if m.Existing[i].Name == name {
nodeCopy := *m.Existing[i] nodeCopy := *m.Existing[i]
...@@ -169,6 +175,12 @@ func (m *FakeNodeHandler) Update(node *api.Node) (*api.Node, error) { ...@@ -169,6 +175,12 @@ func (m *FakeNodeHandler) Update(node *api.Node) (*api.Node, error) {
m.lock.Unlock() m.lock.Unlock()
}() }()
nodeCopy := *node nodeCopy := *node
for i, updateNode := range m.UpdatedNodes {
if updateNode.Name == nodeCopy.Name {
m.UpdatedNodes[i] = &nodeCopy
return node, nil
}
}
m.UpdatedNodes = append(m.UpdatedNodes, &nodeCopy) m.UpdatedNodes = append(m.UpdatedNodes, &nodeCopy)
return node, nil return node, nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment