From 5dc69b65001f36c42fc550461af1ad414881bc24 Mon Sep 17 00:00:00 2001 From: Dmitry Volodin Date: Tue, 15 Apr 2025 14:54:28 +0300 Subject: [PATCH] :bug: Fix potential panic if ClusterResourceSetStrategy is not defined or incorrect --- .../clusterresourceset/clusterresourceset_scope.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/controllers/clusterresourceset/clusterresourceset_scope.go b/internal/controllers/clusterresourceset/clusterresourceset_scope.go index 7e27e210f791..d0c9c7ac5ed5 100644 --- a/internal/controllers/clusterresourceset/clusterresourceset_scope.go +++ b/internal/controllers/clusterresourceset/clusterresourceset_scope.go @@ -58,7 +58,7 @@ func reconcileScopeForResource( return nil, err } - return newResourceReconcileScope(crs, resourceRef, resourceSetBinding, normalizedData, objs), nil + return newResourceReconcileScope(crs, resourceRef, resourceSetBinding, normalizedData, objs) } func newResourceReconcileScope( @@ -67,7 +67,7 @@ func newResourceReconcileScope( resourceSetBinding *addonsv1.ResourceSetBinding, normalizedData [][]byte, objs []unstructured.Unstructured, -) resourceReconcileScope { +) (resourceReconcileScope, error) { base := baseResourceReconcileScope{ clusterResourceSet: clusterResourceSet, resourceRef: resourceRef, @@ -79,11 +79,11 @@ func newResourceReconcileScope( switch addonsv1.ClusterResourceSetStrategy(clusterResourceSet.Spec.Strategy) { case addonsv1.ClusterResourceSetStrategyApplyOnce: - return &reconcileApplyOnceScope{base} + return &reconcileApplyOnceScope{base}, nil case addonsv1.ClusterResourceSetStrategyReconcile: - return &reconcileStrategyScope{base} + return &reconcileStrategyScope{base}, nil default: - return nil + return nil, errors.Errorf("unsupported or empty resource strategy: %q", clusterResourceSet.Spec.Strategy) } } @@ -173,7 +173,7 @@ func (r *reconcileApplyOnceScope) applyObj(ctx context.Context, c client.Client, type applyObj func(ctx context.Context, c client.Client, obj *unstructured.Unstructured) error -// apply reconciles unstructured objects using applyObj and aggreates the error if present. +// apply reconciles unstructured objects using applyObj and aggregates the error if present. func apply(ctx context.Context, c client.Client, applyObj applyObj, objs []unstructured.Unstructured) error { errList := []error{} for i := range objs {