Skip to content

Commit

Permalink
extract namespace from network annotation when cheking for kubevirt r…
Browse files Browse the repository at this point in the history
…elated pod instance

Signed-off-by: Ram Lavi <ralavi@redhat.com>
  • Loading branch information
RamLavi committed May 11, 2020
1 parent 97e9201 commit 5634fdc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions pkg/pool-manager/pod_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ func (p *PoolManager) AllocatePodMac(pod *corev1.Pod) error {
}

// validate if the pod is related to kubevirt
if p.isRelatedToKubevirt(pod) {
// since the pod request may not have owned the vm namespace in this early state of vm making,
// we need to receive the namespace from the network annotation, and because the namespace is
// the same for all the networks, we simply take the namespace from the first network
if p.isRelatedToKubevirt(pod, networks[0].Namespace) {
// nothing to do here. the mac is already by allocated by the virtual machine webhook
log.V(1).Info("This pod have ownerReferences from kubevirt skipping")
return nil
Expand Down Expand Up @@ -220,7 +223,7 @@ func (p *PoolManager) initPodMap() error {
}

// validate if the pod is related to kubevirt
if p.isRelatedToKubevirt(&pod) {
if p.isRelatedToKubevirt(&pod, networks[0].Namespace) {
// nothing to do here. the mac is already by allocated by the virtual machine webhook
log.V(1).Info("This pod have ownerReferences from kubevirt skipping")
continue
Expand Down
4 changes: 2 additions & 2 deletions pkg/pool-manager/virtualmachine_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,14 @@ func (p *PoolManager) IsKubevirtEnabled() bool {
return p.isKubevirt
}

func (p *PoolManager) isRelatedToKubevirt(pod *corev1.Pod) bool {
func (p *PoolManager) isRelatedToKubevirt(pod *corev1.Pod, kubevirtObjectNamespace string) bool {
if pod.ObjectMeta.OwnerReferences == nil {
return false
}

for _, ref := range pod.OwnerReferences {
if ref.Kind == kubevirt.VirtualMachineInstanceGroupVersionKind.Kind {
requestUrl := fmt.Sprintf("apis/kubevirt.io/v1alpha3/namespaces/%s/virtualmachines/%s", pod.Namespace, ref.Name)
requestUrl := fmt.Sprintf("apis/kubevirt.io/v1alpha3/namespaces/%s/virtualmachines/%s", kubevirtObjectNamespace, ref.Name)
log.V(1).Info("test", "requestURI", requestUrl)
result := p.kubeClient.ExtensionsV1beta1().RESTClient().Get().RequestURI(requestUrl).Do()

Expand Down

0 comments on commit 5634fdc

Please sign in to comment.