Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
fix: update the node name label as part of AzureAssignedIdentity update
Browse files Browse the repository at this point in the history
Signed-off-by: Anish Ramasekar <anish.ramasekar@gmail.com>
  • Loading branch information
aramase committed Sep 10, 2021
1 parent 24c257f commit 0eb2f41
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
6 changes: 5 additions & 1 deletion pkg/mic/mic.go
Expand Up @@ -834,9 +834,13 @@ func (c *Client) getAzureAssignedIdentitiesToUpdate(add, del map[string]aadpodid
}
for assignedIDName, addAssignedID := range add {
if delAssignedID, exists := del[assignedIDName]; exists {
objMeta := delAssignedID.ObjectMeta
// the label should always be the latest as the pod could have moved to a different node
// with the same assigned identity
objMeta.SetLabels(addAssignedID.GetObjectMeta().GetLabels())
addAssignedID.ObjectMeta = objMeta
// assigned identity exists in add and del list
// update the assigned identity to the latest
addAssignedID.ObjectMeta = delAssignedID.ObjectMeta
beforeUpdate[assignedIDName] = delAssignedID
afterUpdate[assignedIDName] = addAssignedID
// since this is part of update, remove the assignedID from the add and del list
Expand Down
30 changes: 29 additions & 1 deletion pkg/mic/mic_test.go
Expand Up @@ -414,7 +414,7 @@ func (c *TestPodClient) AddPod(podName, podNs, nodeName, binding string) {
c.pods = append(c.pods, pod)
}

func (c *TestPodClient) DeletePod(podName string, podNs string) {
func (c *TestPodClient) DeletePod(podName, podNs string) {
var newPods []*corev1.Pod
changed := false

Expand Down Expand Up @@ -1033,6 +1033,34 @@ func TestUpdateAssignedIdentities(t *testing.T) {
}
}
}

// test pod with same name moving to a new node
// the nodename label should be updated to test-node2
nodeClient.AddNode("test-node2")
podClient.DeletePod("test-pod", "default")
podClient.AddPod("test-pod", "default", "test-node2", "test-select")

eventCh <- internalaadpodid.PodUpdated

evtRecorder.WaitForEvents(1)
if !crdClient.waitForAssignedIDs(2) {
t.Fatalf("expected len of assigned identities to be 2")
}
listAssignedIDs, err = crdClient.ListAssignedIDs()
if err != nil {
t.Fatalf("list assigned ids failed , error: %+v", err)
}
// check updated assigned identity has the right resource id
if listAssignedIDs != nil {
for _, assignedID := range *listAssignedIDs {
if assignedID.Name != "test-pod-default-test-id" {
continue
}
if assignedID.ObjectMeta.Labels["nodename"] != "test-node2" {
t.Fatalf("expected node name: test-node2, got: %s", assignedID.ObjectMeta.Labels["nodename"])
}
}
}
}

func TestAddUpdateDel(t *testing.T) {
Expand Down

0 comments on commit 0eb2f41

Please sign in to comment.