Skip to content

Commit

Permalink
add disable-vmi-controller option and fix 4459
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisho authored and FrankYang0529 committed Jul 5, 2024
1 parent 5e276ec commit f06da87
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
22 changes: 13 additions & 9 deletions pkg/cloud-controller-manager/ccm.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const (
threadiness = 2
)

var DisableVMIController bool

type CloudProvider struct {
localCoreFactory *ctlcore.Factory
lbFactory *ctllb.Factory
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion pkg/controller/virtualmachineinstance/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit f06da87

Please sign in to comment.