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

Fix panic when spec.core is unset in custom Management #1058

Merged
merged 1 commit into from
Feb 10, 2025
Merged
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
26 changes: 16 additions & 10 deletions internal/controller/management_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,17 +539,21 @@ func applyKCMDefaults(config *apiextensionsv1.JSON) (*apiextensionsv1.JSON, erro
}

func getWrappedComponents(ctx context.Context, cl client.Client, mgmt *kcm.Management) ([]component, error) {
if mgmt.Spec.Core == nil {
return nil, nil
}

release := &kcm.Release{}
if err := cl.Get(ctx, client.ObjectKey{Name: mgmt.Spec.Release}, release); err != nil {
return nil, fmt.Errorf("failed to get Release %s: %w", mgmt.Spec.Release, err)
}

components := make([]component, 0, len(mgmt.Spec.Providers)+2)
kcmComp := component{Component: mgmt.Spec.Core.KCM, helmReleaseName: kcm.CoreKCMName}

kcmComponent := kcm.Component{}
capiComponent := kcm.Component{}
if mgmt.Spec.Core != nil {
kcmComponent = mgmt.Spec.Core.KCM
capiComponent = mgmt.Spec.Core.CAPI
}

kcmComp := component{Component: kcmComponent, helmReleaseName: kcm.CoreKCMName}
if kcmComp.Template == "" {
kcmComp.Template = release.Spec.KCM.Template
}
Expand All @@ -561,7 +565,7 @@ func getWrappedComponents(ctx context.Context, cl client.Client, mgmt *kcm.Manag
components = append(components, kcmComp)

capiComp := component{
Component: mgmt.Spec.Core.CAPI, helmReleaseName: kcm.CoreCAPIName,
Component: capiComponent, helmReleaseName: kcm.CoreCAPIName,
dependsOn: []fluxmeta.NamespacedObjectReference{{Name: kcm.CoreKCMName}}, isCAPIProvider: true,
}
if capiComp.Template == "" {
Expand Down Expand Up @@ -599,11 +603,13 @@ func getWrappedComponents(ctx context.Context, cl client.Client, mgmt *kcm.Manag
func (r *ManagementReconciler) enableAdditionalComponents(ctx context.Context, mgmt *kcm.Management) error {
l := ctrl.LoggerFrom(ctx)

kcmComponent := &mgmt.Spec.Core.KCM
config := make(map[string]any)

if kcmComponent.Config != nil {
if err := json.Unmarshal(kcmComponent.Config.Raw, &config); err != nil {
if mgmt.Spec.Core == nil {
mgmt.Spec.Core = new(kcm.Core)
}
if mgmt.Spec.Core.KCM.Config != nil {
if err := json.Unmarshal(mgmt.Spec.Core.KCM.Config.Raw, &config); err != nil {
return fmt.Errorf("failed to unmarshal KCM config into map[string]any: %w", err)
}
}
Expand Down Expand Up @@ -665,7 +671,7 @@ func (r *ManagementReconciler) enableAdditionalComponents(ctx context.Context, m
return fmt.Errorf("failed to marshal KCM config: %w", err)
}

kcmComponent.Config = &apiextensionsv1.JSON{Raw: updatedConfig}
mgmt.Spec.Core.KCM.Config = &apiextensionsv1.JSON{Raw: updatedConfig}

return nil
}
Expand Down