diff --git a/main.go b/main.go index 8e1e7769..155f92ad 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,9 @@ func main() { controllerInitializers := app.DefaultInitFuncConstructors fss := cliflag.NamedFlagSets{} + harv := fss.FlagSet("harvester") + harv.BoolVar(&ccm.DisableVMIController, "disable-vmi-controller", ccm.DisableVMIController, + "The disable-vmi-controller will disable sync topology to nodes and not affect the custom cluster.") command := app.NewCloudControllerManagerCommand(ccmOptions, cloudInitializer, controllerInitializers, fss, wait.NeverStop) diff --git a/pkg/cloud-controller-manager/ccm.go b/pkg/cloud-controller-manager/ccm.go index 263f0955..f9f7d290 100644 --- a/pkg/cloud-controller-manager/ccm.go +++ b/pkg/cloud-controller-manager/ccm.go @@ -26,6 +26,8 @@ const ( threadiness = 2 ) +var DisableVMIController bool + type CloudProvider struct { localCoreFactory *ctlcore.Factory lbFactory *ctllb.Factory @@ -114,15 +116,17 @@ func newCloudProvider(reader io.Reader) (cloudprovider.Interface, error) { func (c *CloudProvider) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stop <-chan struct{}) { client := clientBuilder.ClientOrDie(ProviderName) - vmi.Register( - c.Context, - client, - c.localCoreFactory.Core().V1().Node(), - c.kubevirtFactory.Kubevirt().V1().VirtualMachineInstance(), - c.kubevirtClient, - c.nodeToVMName, - c.namespace, - ) + if !DisableVMIController { + vmi.Register( + c.Context, + client, + c.localCoreFactory.Core().V1().Node(), + c.kubevirtFactory.Kubevirt().V1().VirtualMachineInstance(), + c.kubevirtClient, + c.nodeToVMName, + c.namespace, + ) + } go func() { if err := start.All(c.Context, threadiness, c.kubevirtFactory, c.localCoreFactory); err != nil { diff --git a/pkg/controller/virtualmachineinstance/controller.go b/pkg/controller/virtualmachineinstance/controller.go index 9bad99b9..494036d5 100644 --- a/pkg/controller/virtualmachineinstance/controller.go +++ b/pkg/controller/virtualmachineinstance/controller.go @@ -10,6 +10,7 @@ import ( ctlcorev1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1" "github.com/sirupsen/logrus" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" "k8s.io/client-go/kubernetes" cloudproviderapi "k8s.io/cloud-provider/api" cloudnodeutil "k8s.io/cloud-provider/node/helpers" @@ -89,7 +90,11 @@ func (h *Handler) OnVmiChanged(_ string, vmi *kubevirtv1.VirtualMachineInstance) node, err := h.nodeCache.Get(nodeName) if err != nil { - return vmi, err + if !errors.IsNotFound(err) { + return vmi, err + } + // This vm does not belong to current cluster if the node is not found + return vmi, nil } if !compareTopology(vmi.GetAnnotations(), node.GetLabels()) {