diff --git a/Makefile b/Makefile index 271122a9..feed846f 100644 --- a/Makefile +++ b/Makefile @@ -156,7 +156,7 @@ collect-airgap-providers: yq helm clusterctl $(PROVIDER_TEMPLATES_DIR) $(LOCALBI $(SHELL) hack/collect-airgap-providers.sh .PHONY: helm-package -helm-package: $(CHARTS_PACKAGE_DIR) $(EXTENSION_CHARTS_PACKAGE_DIR) helm # collect-airgap-providers +helm-package: $(CHARTS_PACKAGE_DIR) $(EXTENSION_CHARTS_PACKAGE_DIR) helm collect-airgap-providers @make $(patsubst %,package-%-tmpl,$(TEMPLATE_FOLDERS)) .PHONY: k0s-image diff --git a/internal/controller/management_controller.go b/internal/controller/management_controller.go index 973d2aaf..88b00f78 100644 --- a/internal/controller/management_controller.go +++ b/internal/controller/management_controller.go @@ -21,6 +21,7 @@ import ( "fmt" "slices" "strings" + "sync" fluxv2 "github.com/fluxcd/helm-controller/api/v2" fluxmeta "github.com/fluxcd/pkg/apis/meta" @@ -51,13 +52,12 @@ import ( // ManagementReconciler reconciles a Management object type ManagementReconciler struct { client.Client - Manager manager.Manager - Scheme *runtime.Scheme - Config *rest.Config - DynamicClient *dynamic.DynamicClient - SystemNamespace string - CreateAccessManagement bool - SveltosDependentControllersStarted bool + Manager manager.Manager + Scheme *runtime.Scheme + Config *rest.Config + DynamicClient *dynamic.DynamicClient + SystemNamespace string + CreateAccessManagement bool } func (r *ManagementReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { @@ -199,9 +199,7 @@ func (r *ManagementReconciler) Update(ctx context.Context, management *kcm.Manag management.Status.ObservedGeneration = management.Generation management.Status.Release = management.Spec.Release - if err := r.startDependentControllers(ctx, management); err != nil { - return ctrl.Result{}, err - } + r.startDependentControllers(ctx, management) if err := r.Status().Update(ctx, management); err != nil { errs = errors.Join(errs, fmt.Errorf("failed to update status for Management %s: %w", management.Name, err)) @@ -218,14 +216,14 @@ func (r *ManagementReconciler) Update(ctx context.Context, management *kcm.Manag return ctrl.Result{}, nil } -func (r *ManagementReconciler) startDependentControllers(ctx context.Context, management *kcm.Management) error { +func (r *ManagementReconciler) startDependentControllers(ctx context.Context, management *kcm.Management) { l := ctrl.LoggerFrom(ctx) - if !r.SveltosDependentControllersStarted { - if management.Status.Components[kcm.ProviderSveltosName].Success { + if management.Status.Components[kcm.ProviderSveltosName].Success { + sync.OnceFunc(func() { dc, err := dynamic.NewForConfig(r.Manager.GetConfig()) if err != nil { - return fmt.Errorf("failed to create dynamic client: %w", err) + panic(fmt.Errorf("failed to create dynamic client: %w", err)) } currentNamespace := utils.CurrentNamespace() @@ -237,7 +235,7 @@ func (r *ManagementReconciler) startDependentControllers(ctx context.Context, ma DynamicClient: dc, SystemNamespace: currentNamespace, }).SetupWithManager(r.Manager); err != nil { - return fmt.Errorf("failed to setup controller for ClusterDeployment: %w", err) + panic(fmt.Errorf("failed to setup controller for ClusterDeployment: %w", err)) } l.Info("Setup for ClusterDeployment controller successful") @@ -246,17 +244,13 @@ func (r *ManagementReconciler) startDependentControllers(ctx context.Context, ma Client: r.Manager.GetClient(), SystemNamespace: currentNamespace, }).SetupWithManager(r.Manager); err != nil { - return fmt.Errorf("failed to setup controller for MultiClusterService: %w", err) + panic(fmt.Errorf("failed to setup controller for MultiClusterService: %w", err)) } l.Info("Setup for MultiClusterService controller successful") - - r.SveltosDependentControllersStarted = true - } else { - l.Info(fmt.Sprintf("Waiting for %s provider to be ready to setup contollers dependent on it", kcm.ProviderSveltosName)) - } + })() + } else { + l.Info(fmt.Sprintf("Waiting for %s provider to be ready to setup contollers dependent on it", kcm.ProviderSveltosName)) } - - return nil } func (r *ManagementReconciler) cleanupRemovedComponents(ctx context.Context, management *kcm.Management) error {