Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto detect kubevirt install #4791

Merged
merged 6 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ type Controller struct {
vmiMigrationSynced cache.InformerSynced
addOrUpdateVMIMigrationQueue workqueue.TypedRateLimitingInterface[string]
kubevirtInformerFactory kubevirtController.KubeInformerFactory
hasKubevirtVMIMigration bool

recorder record.EventRecorder
informerFactory kubeinformers.SharedInformerFactory
Expand Down Expand Up @@ -638,11 +637,6 @@ func Run(ctx context.Context, config *Configuration) {
controller.kubeovnInformerFactory.Start(ctx.Done())
controller.anpInformerFactory.Start(ctx.Done())

controller.hasKubevirtVMIMigration = controller.isVMIMigrationCRDInstalled()
if controller.config.EnableLiveMigrationOptimize && controller.hasKubevirtVMIMigration {
kubevirtInformerFactory.Start(ctx.Done())
}

klog.Info("Waiting for informer caches to sync")
cacheSyncs := []cache.InformerSynced{
controller.vpcNatGatewaySynced, controller.vpcEgressGatewaySynced,
Expand All @@ -664,10 +658,6 @@ func Run(ctx context.Context, config *Configuration) {
cacheSyncs = append(cacheSyncs, controller.anpsSynced, controller.banpsSynced)
}

if controller.config.EnableLiveMigrationOptimize && controller.hasKubevirtVMIMigration {
cacheSyncs = append(cacheSyncs, controller.vmiMigrationSynced)
}

if !cache.WaitForCacheSync(ctx.Done(), cacheSyncs...) {
util.LogFatalAndExit(nil, "failed to wait for caches to sync")
}
Expand Down Expand Up @@ -921,7 +911,7 @@ func Run(ctx context.Context, config *Configuration) {
}
}

if config.EnableLiveMigrationOptimize && controller.hasKubevirtVMIMigration {
if config.EnableLiveMigrationOptimize {
changluyi marked this conversation as resolved.
Show resolved Hide resolved
if _, err = vmiMigrationInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: controller.enqueueAddVMIMigration,
UpdateFunc: controller.enqueueUpdateVMIMigration,
Expand All @@ -930,6 +920,10 @@ func Run(ctx context.Context, config *Configuration) {
}
}

if controller.config.EnableLiveMigrationOptimize {
controller.StartMigrationInformerFactory(ctx, kubevirtInformerFactory)
}
changluyi marked this conversation as resolved.
Show resolved Hide resolved

controller.Run(ctx)
}

Expand Down Expand Up @@ -1335,7 +1329,7 @@ func (c *Controller) startWorkers(ctx context.Context) {
go wait.Until(runWorker("delete base admin network policy", c.deleteBanpQueue, c.handleDeleteBanp), time.Second, ctx.Done())
}

if c.config.EnableLiveMigrationOptimize && c.hasKubevirtVMIMigration {
if c.config.EnableLiveMigrationOptimize {
go wait.Until(runWorker("add/update vmiMigration ", c.addOrUpdateVMIMigrationQueue, c.handleAddOrUpdateVMIMigration), 50*time.Millisecond, ctx.Done())
}
}
Expand Down
27 changes: 26 additions & 1 deletion pkg/controller/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import (
"context"
"fmt"
"reflect"
"time"

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"
kubevirtController "kubevirt.io/kubevirt/pkg/controller"

"github.com/kubeovn/kube-ovn/pkg/ovs"
"github.com/kubeovn/kube-ovn/pkg/util"
)

func (c *Controller) enqueueAddVMIMigration(obj interface{}) {
Expand Down Expand Up @@ -138,6 +141,28 @@ func (c *Controller) isVMIMigrationCRDInstalled() bool {
if err != nil {
return false
}
klog.Info("Detect VMI Migration CRD")
klog.Info("Found KubeVirt VMI Migration CRD")
return true
}

func (c *Controller) StartMigrationInformerFactory(ctx context.Context, kubevirtInformerFactory kubevirtController.KubeInformerFactory) {
ticker := time.NewTicker(10 * time.Second)
go func() {
defer ticker.Stop()
for {
select {
case <-ticker.C:
if c.isVMIMigrationCRDInstalled() {
klog.Info("Start VMI migration informer")
kubevirtInformerFactory.Start(ctx.Done())
if !cache.WaitForCacheSync(ctx.Done(), c.vmiMigrationSynced) {
util.LogFatalAndExit(nil, "failed to wait for vmi migration caches to sync")
}
return
}
case <-ctx.Done():
return
}
}
}()
}
2 changes: 0 additions & 2 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,6 @@ func (c *Controller) reconcileAllocateSubnets(cachedPod, pod *v1.Pod, needAlloca

var err error
var vmKey string
// var isMigrate, migrated, migratedFail bool
// var vmKey, srcNodeName, targetNodeName string
if isVMPod && c.config.EnableKeepVMIP {
vmKey = fmt.Sprintf("%s/%s", namespace, vmName)
}
Expand Down
Loading