Skip to content

Commit

Permalink
Merge pull request #32 from SchSeba/fix_vmi_object
Browse files Browse the repository at this point in the history
Fix pod annotation clear
  • Loading branch information
SchSeba authored May 8, 2019
2 parents 6a5c06c + bae4efa commit 70f1db5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/pool-manager/pod_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ func (p *PoolManager) AllocatePodMac(pod *corev1.Pod) error {
}

network.MacRequest = macAddr
networkList = append(networkList, network)
allocations = append(allocations, macAddr)
}
networkList = append(networkList, network)
}

networkListJson, err := json.Marshal(networkList)
Expand Down
15 changes: 15 additions & 0 deletions pkg/pool-manager/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,21 @@ var _ = Describe("Pool", func() {
_, exist = poolManager.macPoolMap["02:00:00:00:00:01"]
Expect(exist).To(BeFalse())
})
It("should allocate requested mac when empty", func() {
fakeClient := fake.NewSimpleClientset()
startPoolRangeEnv, err := net.ParseMAC("02:00:00:00:00:00")
Expect(err).ToNot(HaveOccurred())
endPoolRangeEnv, err := net.ParseMAC("02:00:00:00:00:02")
Expect(err).ToNot(HaveOccurred())
poolManager, err := NewPoolManager(fakeClient, startPoolRangeEnv, endPoolRangeEnv, false)
Expect(err).ToNot(HaveOccurred())
newPod := samplePod
newPod.Name = "newPod"

err = poolManager.AllocatePodMac(&newPod)
Expect(err).ToNot(HaveOccurred())
Expect(newPod.Annotations[networksAnnotation]).To(Equal(afterAllocationAnnotation[networksAnnotation]))
})
})

})
2 changes: 1 addition & 1 deletion pkg/webhook/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (a *podAnnotator) Handle(ctx context.Context, req types.Request) types.Resp
copyPod.Namespace = req.AdmissionRequest.Namespace
}

log.V(1).Info("got a create pod event", "podName", pod.Name, "podNamespace", pod.Namespace)
log.V(1).Info("got a create pod event", "podName", copyPod.Name, "podNamespace", copyPod.Namespace)
err = a.poolManager.AllocatePodMac(copyPod)
if err != nil {
return admission.ErrorResponse(http.StatusInternalServerError, err)
Expand Down

0 comments on commit 70f1db5

Please sign in to comment.