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

Add disable-vmi-controller option and fix 4459 #35

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@ -88,7 +89,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
Loading