Skip to content

Commit

Permalink
Do not register VM controller if KubeVirt CRDs are not installed
Browse files Browse the repository at this point in the history
Signed-off-by: João Vilaça <[email protected]>
  • Loading branch information
machadovilaca committed Sep 12, 2023
1 parent 8976a5f commit 3ca0878
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions controllers/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"context"
"fmt"
"path/filepath"
"strings"

"github.com/go-logr/logr"
v1 "github.com/openshift/api/config/v1"
kubevirtv1 "kubevirt.io/api/core/v1"
"kubevirt.io/ssp-operator/internal/common"
crd_watch "kubevirt.io/ssp-operator/internal/crd-watch"
"kubevirt.io/ssp-operator/internal/operands"
Expand Down Expand Up @@ -103,6 +105,11 @@ func setupManager(ctx context.Context, cancel context.CancelFunc, mgr controller
requiredCrds = append(requiredCrds, getRequiredCrds(sspOperands[i])...)
}

// Add VMController necessary VirtualMachine CRD
vmKind := strings.ToLower(kubevirtv1.VirtualMachineGroupVersionKind.Kind) + "s"
vmCRD := vmKind + "." + kubevirtv1.VirtualMachineGroupVersionKind.Group
requiredCrds = append(requiredCrds, vmCRD)

crdWatch := crd_watch.New(requiredCrds...)
// Cleanly stops the manager and exit. The pod will be restarted.
crdWatch.AllCrdsAddedHandler = cancel
Expand Down Expand Up @@ -139,13 +146,17 @@ func setupManager(ctx context.Context, cancel context.CancelFunc, mgr controller
return fmt.Errorf("error adding service controller: %w", err)
}

vmController, err := CreateVmController(mgr)
if err != nil {
return fmt.Errorf("failed to create vm controller: %w", err)
}
if crdWatch.CrdExists(vmCRD) {
vmController, cErr := CreateVmController(mgr)
if cErr != nil {
return fmt.Errorf("[vm controller] failed to create vm controller: %w", cErr)
}

if cErr = mgr.Add(getRunnable(mgr, vmController)); cErr != nil {
return fmt.Errorf("[vm controller] error adding: %w", cErr)
}

if err = mgr.Add(getRunnable(mgr, vmController)); err != nil {
return fmt.Errorf("error adding vm-controller: %w", err)
mgr.GetLogger().Info("[vm controller] added")
}

reconciler := NewSspReconciler(mgr.GetClient(), mgr.GetAPIReader(), infrastructureTopology, sspOperands, crdWatch)
Expand Down

0 comments on commit 3ca0878

Please sign in to comment.