Skip to content

Commit 56674b0

Browse files
committed
🐛 Fix potential panic if ClusterResourceSetStrategy is not defined or incorrect
1 parent dd105a3 commit 56674b0

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

internal/controllers/clusterresourceset/clusterresourceset_scope.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package clusterresourceset
1818

1919
import (
2020
"context"
21+
"fmt"
2122

2223
"github.com/pkg/errors"
2324
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -58,7 +59,7 @@ func reconcileScopeForResource(
5859
return nil, err
5960
}
6061

61-
return newResourceReconcileScope(crs, resourceRef, resourceSetBinding, normalizedData, objs), nil
62+
return newResourceReconcileScope(crs, resourceRef, resourceSetBinding, normalizedData, objs)
6263
}
6364

6465
func newResourceReconcileScope(
@@ -67,7 +68,7 @@ func newResourceReconcileScope(
6768
resourceSetBinding *addonsv1.ResourceSetBinding,
6869
normalizedData [][]byte,
6970
objs []unstructured.Unstructured,
70-
) resourceReconcileScope {
71+
) (resourceReconcileScope, error) {
7172
base := baseResourceReconcileScope{
7273
clusterResourceSet: clusterResourceSet,
7374
resourceRef: resourceRef,
@@ -79,11 +80,11 @@ func newResourceReconcileScope(
7980

8081
switch addonsv1.ClusterResourceSetStrategy(clusterResourceSet.Spec.Strategy) {
8182
case addonsv1.ClusterResourceSetStrategyApplyOnce:
82-
return &reconcileApplyOnceScope{base}
83+
return &reconcileApplyOnceScope{base}, nil
8384
case addonsv1.ClusterResourceSetStrategyReconcile:
84-
return &reconcileStrategyScope{base}
85+
return &reconcileStrategyScope{base}, nil
8586
default:
86-
return nil
87+
return nil, errors.Errorf("unsupported or empty resource strategy: %q", clusterResourceSet.Spec.Strategy)
8788
}
8889
}
8990

@@ -173,7 +174,7 @@ func (r *reconcileApplyOnceScope) applyObj(ctx context.Context, c client.Client,
173174

174175
type applyObj func(ctx context.Context, c client.Client, obj *unstructured.Unstructured) error
175176

176-
// apply reconciles unstructured objects using applyObj and aggreates the error if present.
177+
// apply reconciles unstructured objects using applyObj and aggregates the error if present.
177178
func apply(ctx context.Context, c client.Client, applyObj applyObj, objs []unstructured.Unstructured) error {
178179
errList := []error{}
179180
for i := range objs {

0 commit comments

Comments
 (0)