Skip to content

Commit 5dc69b6

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

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

internal/controllers/clusterresourceset/clusterresourceset_scope.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func reconcileScopeForResource(
5858
return nil, err
5959
}
6060

61-
return newResourceReconcileScope(crs, resourceRef, resourceSetBinding, normalizedData, objs), nil
61+
return newResourceReconcileScope(crs, resourceRef, resourceSetBinding, normalizedData, objs)
6262
}
6363

6464
func newResourceReconcileScope(
@@ -67,7 +67,7 @@ func newResourceReconcileScope(
6767
resourceSetBinding *addonsv1.ResourceSetBinding,
6868
normalizedData [][]byte,
6969
objs []unstructured.Unstructured,
70-
) resourceReconcileScope {
70+
) (resourceReconcileScope, error) {
7171
base := baseResourceReconcileScope{
7272
clusterResourceSet: clusterResourceSet,
7373
resourceRef: resourceRef,
@@ -79,11 +79,11 @@ func newResourceReconcileScope(
7979

8080
switch addonsv1.ClusterResourceSetStrategy(clusterResourceSet.Spec.Strategy) {
8181
case addonsv1.ClusterResourceSetStrategyApplyOnce:
82-
return &reconcileApplyOnceScope{base}
82+
return &reconcileApplyOnceScope{base}, nil
8383
case addonsv1.ClusterResourceSetStrategyReconcile:
84-
return &reconcileStrategyScope{base}
84+
return &reconcileStrategyScope{base}, nil
8585
default:
86-
return nil
86+
return nil, errors.Errorf("unsupported or empty resource strategy: %q", clusterResourceSet.Spec.Strategy)
8787
}
8888
}
8989

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

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

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

0 commit comments

Comments
 (0)