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

🌱 Retry CRD detection during startup #2917

Merged
Merged
Changes from 2 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
48 changes: 29 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"gopkg.in/fsnotify.v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/wait"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
logsv1 "k8s.io/component-base/logs/api/v1"
Expand Down Expand Up @@ -268,37 +269,46 @@ func main() {
return perrors.Wrapf(err, "unable to create remote cluster cache tracker")
}

// Check for non-supervisor VSphereCluster and start controller if found
gvr := infrav1.GroupVersion.WithResource(reflect.TypeOf(&infrav1.VSphereCluster{}).Elem().Name())
isNonSupervisorCRDLoaded, err := isCRDDeployed(mgr, gvr)
if err != nil {
return err
govmomiGVR := infrav1.GroupVersion.WithResource(reflect.TypeOf(&infrav1.VSphereCluster{}).Elem().Name())
supervisorGVR := vmwarev1.GroupVersion.WithResource(reflect.TypeOf(&vmwarev1.VSphereCluster{}).Elem().Name())

var isSupervisorCRDLoaded, isGovimoniCRDLoaded bool
fabriziopandini marked this conversation as resolved.
Show resolved Hide resolved
if err := wait.PollUntilContextTimeout(ctx, 5*time.Second, 30*time.Second, true, func(_ context.Context) (bool, error) {
var errGovimomi, errSupervisor error

// Check for non-supervisor VSphereCluster and start controller if found
isGovimoniCRDLoaded, errGovimomi = isCRDDeployed(mgr, govmomiGVR)
fabriziopandini marked this conversation as resolved.
Show resolved Hide resolved

// Check for supervisor VSphereCluster and start controller if found
isSupervisorCRDLoaded, errSupervisor = isCRDDeployed(mgr, supervisorGVR)

if (isGovimoniCRDLoaded && errGovimomi == nil) || (isSupervisorCRDLoaded && errSupervisor == nil) {
return true, nil
}
return false, nil
}); err != nil {
return fmt.Errorf("failed to detect CRDs: %w", err)
fabriziopandini marked this conversation as resolved.
Show resolved Hide resolved
}

// Continuing startup does not make sense without having managers added.
if !isSupervisorCRDLoaded && !isGovimoniCRDLoaded {
return errors.New("neither supervisor nor govimomi CRDs detected")
fabriziopandini marked this conversation as resolved.
Show resolved Hide resolved
}
if isNonSupervisorCRDLoaded {

if isGovimoniCRDLoaded {
if err := setupVAPIControllers(ctx, controllerCtx, mgr, tracker); err != nil {
return fmt.Errorf("setupVAPIControllers: %w", err)
}
} else {
setupLog.Info(fmt.Sprintf("CRD for %s not loaded, skipping.", gvr.String()))
setupLog.Info(fmt.Sprintf("CRD for %s not loaded, skipping.", govmomiGVR.String()))
}

// Check for supervisor VSphereCluster and start controller if found
gvr = vmwarev1.GroupVersion.WithResource(reflect.TypeOf(&vmwarev1.VSphereCluster{}).Elem().Name())
isSupervisorCRDLoaded, err := isCRDDeployed(mgr, gvr)
if err != nil {
return err
}
if isSupervisorCRDLoaded {
if err := setupSupervisorControllers(ctx, controllerCtx, mgr, tracker); err != nil {
return fmt.Errorf("setupSupervisorControllers: %w", err)
}
} else {
setupLog.Info(fmt.Sprintf("CRD for %s not loaded, skipping.", gvr.String()))
}

// Continuing startup does not make sense without having managers added.
if !isSupervisorCRDLoaded && !isNonSupervisorCRDLoaded {
return errors.New("neither supervisor nor non-supervisor CRDs detected")
setupLog.Info(fmt.Sprintf("CRD for %s not loaded, skipping.", supervisorGVR.String()))
}

return nil
Expand Down
Loading