Skip to content

Commit

Permalink
fix code format
Browse files Browse the repository at this point in the history
Signed-off-by: clyi <[email protected]>
  • Loading branch information
changluyi committed Nov 28, 2024
1 parent 7638b53 commit b973b6d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 84 deletions.
15 changes: 10 additions & 5 deletions pkg/controller/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"fmt"
"reflect"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/tools/cache"
"k8s.io/klog/v2"
kubevirtv1 "kubevirt.io/api/core/v1"

"github.com/kubeovn/kube-ovn/pkg/ovs"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
)

func (c *Controller) enqueueAddVMIMigration(obj interface{}) {
Expand Down Expand Up @@ -54,7 +54,7 @@ func (c *Controller) handleAddOrUpdateVMIMigration(key string) error {

vmiMigration, err := c.config.KubevirtClient.VirtualMachineInstanceMigration(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
utilruntime.HandleError(fmt.Errorf("failed to get VMI migration by key %s: %v", key, err))
utilruntime.HandleError(fmt.Errorf("failed to get VMI migration by key %s: %w", key, err))
return err
}
if vmiMigration.Status.MigrationState == nil {
Expand All @@ -64,7 +64,7 @@ func (c *Controller) handleAddOrUpdateVMIMigration(key string) error {

vmi, err := c.config.KubevirtClient.VirtualMachineInstance(namespace).Get(context.TODO(), vmiMigration.Spec.VMIName, metav1.GetOptions{})
if err != nil {
utilruntime.HandleError(fmt.Errorf("failed to get VMI by name %s: %v", vmiMigration.Spec.VMIName, err))
utilruntime.HandleError(fmt.Errorf("failed to get VMI by name %s: %w", vmiMigration.Spec.VMIName, err))
return err
}

Expand All @@ -88,9 +88,14 @@ func (c *Controller) handleAddOrUpdateVMIMigration(key string) error {

sourcePodName := vmi.Status.MigrationState.SourcePod
sourcePod, err := c.config.KubeClient.CoreV1().Pods(namespace).Get(context.TODO(), sourcePodName, metav1.GetOptions{})
if err != nil {
klog.Errorf("failed to get source pod %s, %w", sourcePodName, err)

Check failure on line 92 in pkg/controller/kubevirt.go

View workflow job for this annotation

GitHub Actions / Build kube-ovn

k8s.io/klog/v2.Errorf does not support error-wrapping directive %w
return err
}

podNets, err := c.getPodKubeovnNets(sourcePod)
if err != nil {
klog.Errorf("failed to get pod nets %v", err)
klog.Errorf("failed to get pod nets %w", err)

Check failure on line 98 in pkg/controller/kubevirt.go

View workflow job for this annotation

GitHub Actions / Build kube-ovn

k8s.io/klog/v2.Errorf does not support error-wrapping directive %w
return err
}

Expand Down
79 changes: 0 additions & 79 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,6 @@ func (c *Controller) reconcileAllocateSubnets(cachedPod, pod *v1.Pod, needAlloca
// var vmKey, srcNodeName, targetNodeName string
if isVMPod && c.config.EnableKeepVMIP {
vmKey = fmt.Sprintf("%s/%s", namespace, vmName)
// if isMigrate, migrated, migratedFail, srcNodeName, targetNodeName, err = c.migrateVM(pod, vmKey); err != nil {
// klog.Error(err)
// return nil, err
// }
}
// Avoid create lsp for already running pod in ovn-nb when controller restart
for _, podNet := range needAllocatePodNets {
Expand Down Expand Up @@ -605,24 +601,6 @@ func (c *Controller) reconcileAllocateSubnets(cachedPod, pod *v1.Pod, needAlloca
return nil, err
}

// if isMigrate {
// if migrated {
// klog.Infof("migrate end reset options for lsp %s from %s to %s, migrated fail: %t", portName, srcNodeName, targetNodeName, migratedFail)
// if err := c.OVNNbClient.ResetLogicalSwitchPortMigrateOptions(portName, srcNodeName, targetNodeName, migratedFail); err != nil {
// err = fmt.Errorf("failed to clean migrate options for lsp %s, %w", portName, err)
// klog.Error(err)
// return nil, err
// }
// } else {
// klog.Infof("migrate start set options for lsp %s from %s to %s", portName, srcNodeName, targetNodeName)
// if err := c.OVNNbClient.SetLogicalSwitchPortMigrateOptions(portName, srcNodeName, targetNodeName); err != nil {
// err = fmt.Errorf("failed to set migrate options for lsp %s, %w", portName, err)
// klog.Error(err)
// return nil, err
// }
// }
// }

if pod.Annotations[fmt.Sprintf(util.Layer2ForwardAnnotationTemplate, podNet.ProviderName)] == "true" {
if err := c.OVNNbClient.EnablePortLayer2forward(portName); err != nil {
c.recorder.Eventf(pod, v1.EventTypeWarning, "SetOVNPortL2ForwardFailed", err.Error())
Expand Down Expand Up @@ -2098,63 +2076,6 @@ func (c *Controller) getVirtualIPs(pod *v1.Pod, podNets []*kubeovnNet) map[strin
return vipsMap
}

// migrate vm return migrate, migrated, fail, src node, target node, err
func (c *Controller) migrateVM(pod *v1.Pod, vmKey string) (bool, bool, bool, string, string, error) {
// try optimize vm migration, no need return error
// migrate true means need ovn set migrate options
// migrated ok means need set migrate options to target node
// migrated failed means need set migrate options to source node
if _, ok := pod.Annotations[util.MigrationJobAnnotation]; !ok {
return false, false, false, "", "", nil
}
if _, ok := pod.Annotations[util.MigrationSourceAnnotation]; ok {
klog.Infof("will migrate out vm %s pod %s from source node %s", vmKey, pod.Name, pod.Spec.NodeName)
return false, false, false, "", "", nil
}
// ovn set migrator only in the process of target vm pod
if _, ok := pod.Annotations[util.MigrationTargetAnnotation]; !ok {
return false, false, false, "", "", nil
}
srcNode, ok := pod.Annotations[util.MigrationSourceNodeAnnotation]
if !ok || srcNode == "" {
err := fmt.Errorf("vm %s migration source node is not set", vmKey)
klog.Warning(err)
return false, false, false, "", "", nil
}
targetNode := pod.Spec.NodeName
if targetNode == "" {
err := fmt.Errorf("vm %s migration target node is not set", vmKey)
klog.Warning(err)
return false, false, false, "", "", nil
}
migratePhase, ok := pod.Annotations[util.MigrationPhaseAnnotation]
if !ok {
err := fmt.Errorf("vm %s migration phase is not set", vmKey)
klog.Warning(err)
return false, false, false, "", "", nil
}
// check migrate phase
if migratePhase == "" {
err := fmt.Errorf("vm %s migration phase is empty", vmKey)
klog.Warning(err)
return false, false, false, "", "", nil
}
if migratePhase == util.MigrationPhaseStarted {
klog.Infof("start to migrate src vm %s from %s to %s", vmKey, srcNode, targetNode)
return true, false, false, srcNode, targetNode, nil
}
if migratePhase == util.MigrationPhaseSucceeded {
klog.Infof("succeed to migrate src vm %s from %s to %s", vmKey, srcNode, targetNode)
return true, true, false, srcNode, targetNode, nil
}
if migratePhase == util.MigrationPhaseFailed {
klog.Infof("failed to migrate src vm %s from %s to %s", vmKey, srcNode, targetNode)
return true, true, true, srcNode, targetNode, nil
}

return false, false, false, "", "", nil
}

func setPodRoutesAnnotation(annotations map[string]string, provider string, routes []request.Route) error {
key := fmt.Sprintf(util.RoutesAnnotationTemplate, provider)
if len(routes) == 0 {
Expand Down

0 comments on commit b973b6d

Please sign in to comment.