Skip to content

Commit

Permalink
Adppted some review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
wahabmk committed Jan 13, 2025
1 parent f346ffd commit 6226c15
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 17 additions & 23 deletions internal/controller/management_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"slices"
"strings"
"sync"

fluxv2 "github.com/fluxcd/helm-controller/api/v2"
fluxmeta "github.com/fluxcd/pkg/apis/meta"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
Expand All @@ -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()
Expand All @@ -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")

Expand All @@ -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 {
Expand Down

0 comments on commit 6226c15

Please sign in to comment.