Skip to content

Commit a731385

Browse files
author
Ryan Zhang
committed
temp
1 parent 9a376db commit a731385

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

pkg/controllers/workgenerator/controller.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req controllerruntime.Reques
188188
Status: metav1.ConditionFalse,
189189
Type: string(fleetv1beta1.ResourceBindingOverridden),
190190
Reason: condition.OverriddenFailedReason,
191-
Message: fmt.Sprintf("Failed to apply the override rules on the resources: %s", errorMessage),
191+
Message: errorMessage,
192192
ObservedGeneration: resourceBinding.Generation,
193193
})
194194
} else {
@@ -624,13 +624,13 @@ func (r *Reconciler) fetchAllResourceSnapshots(ctx context.Context, resourceBind
624624
func (r *Reconciler) getConfigMapEnvelopWorkObj(ctx context.Context, workNamePrefix string, resourceBinding *fleetv1beta1.ClusterResourceBinding,
625625
resourceSnapshot *fleetv1beta1.ClusterResourceSnapshot, envelopeObj *unstructured.Unstructured, resourceOverrideSnapshotHash, clusterResourceOverrideSnapshotHash string) (*fleetv1beta1.Work, error) {
626626
// we group all the resources in one configMap to one work
627-
manifest, err := extractResFromConfigMap(envelopeObj)
627+
manifests, err := extractResFromConfigMap(envelopeObj)
628628
if err != nil {
629629
klog.ErrorS(err, "configMap has invalid content", "snapshot", klog.KObj(resourceSnapshot),
630630
"resourceBinding", klog.KObj(resourceBinding), "configMapWrapper", klog.KObj(envelopeObj))
631631
return nil, controller.NewUserError(err)
632632
}
633-
klog.V(2).InfoS("Successfully extract the enveloped resources from the configMap", "numOfResources", len(manifest),
633+
klog.V(2).InfoS("Successfully extract the enveloped resources from the configMap", "numOfResources", len(manifests),
634634
"snapshot", klog.KObj(resourceSnapshot), "resourceBinding", klog.KObj(resourceBinding), "configMapWrapper", klog.KObj(envelopeObj))
635635

636636
// Try to see if we already have a work represent the same enveloped object for this CRP in the same cluster
@@ -643,7 +643,7 @@ func (r *Reconciler) getConfigMapEnvelopWorkObj(ctx context.Context, workNamePre
643643
fleetv1beta1.EnvelopeNamespaceLabel: envelopeObj.GetNamespace(),
644644
}
645645
workList := &fleetv1beta1.WorkList{}
646-
if err := r.Client.List(ctx, workList, envelopWorkLabelMatcher); err != nil {
646+
if err = r.Client.List(ctx, workList, envelopWorkLabelMatcher); err != nil {
647647
return nil, controller.NewAPIServerError(true, err)
648648
}
649649
// we need to create a new work object
@@ -680,7 +680,7 @@ func (r *Reconciler) getConfigMapEnvelopWorkObj(ctx context.Context, workNamePre
680680
},
681681
Spec: fleetv1beta1.WorkSpec{
682682
Workload: fleetv1beta1.WorkloadTemplate{
683-
Manifests: manifest,
683+
Manifests: manifests,
684684
},
685685
ApplyStrategy: resourceBinding.Spec.ApplyStrategy,
686686
},
@@ -699,7 +699,7 @@ func (r *Reconciler) getConfigMapEnvelopWorkObj(ctx context.Context, workNamePre
699699
work.Annotations[fleetv1beta1.ParentResourceSnapshotNameAnnotation] = resourceBinding.Spec.ResourceSnapshotName
700700
work.Annotations[fleetv1beta1.ParentResourceOverrideSnapshotHashAnnotation] = resourceOverrideSnapshotHash
701701
work.Annotations[fleetv1beta1.ParentClusterResourceOverrideSnapshotHashAnnotation] = clusterResourceOverrideSnapshotHash
702-
work.Spec.Workload.Manifests = manifest
702+
work.Spec.Workload.Manifests = manifests
703703
work.Spec.ApplyStrategy = resourceBinding.Spec.ApplyStrategy
704704
return &work, nil
705705
}

pkg/controllers/workgenerator/override.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ func (r *Reconciler) applyOverrides(resource *placementv1beta1.ResourceContent,
137137
continue // should not happen
138138
}
139139
if err := applyOverrideRules(resource, cluster, snapshot.Spec.OverrideSpec.Policy.OverrideRules); err != nil {
140-
klog.ErrorS(err, "Failed to apply the override rules", "clusterResourceOverrideSnapshot", klog.KObj(snapshot))
141-
return false, err
140+
overrideErr := fmt.Errorf("failed to apply the cluster override rule `%s` on resource `%s/%s/%s`: err = %s", snapshot.Name, uResource.GroupVersionKind(), uResource.GetNamespace(), uResource.GetName(), err.Error())
141+
klog.ErrorS(err, "Failed to apply the override rules", "resource", klog.KObj(&uResource), "clusterResourceOverrideSnapshot", klog.KObj(snapshot))
142+
return false, controller.NewUserError(overrideErr)
142143
}
143144
}
144145
klog.V(2).InfoS("Applied clusterResourceOverrideSnapshots", "resource", klog.KObj(&uResource), "numberOfOverrides", len(croMap[key]))
@@ -160,8 +161,9 @@ func (r *Reconciler) applyOverrides(resource *placementv1beta1.ResourceContent,
160161
continue // should not happen
161162
}
162163
if err := applyOverrideRules(resource, cluster, snapshot.Spec.OverrideSpec.Policy.OverrideRules); err != nil {
163-
klog.ErrorS(err, "Failed to apply the override rules", "resourceOverrideSnapshot", klog.KObj(snapshot))
164-
return false, err
164+
overrideErr := fmt.Errorf("failed to apply the resource override rule %s/%s on resource `%s/%s/%s`: err = %s", snapshot.Namespace, snapshot.Name, uResource.GroupVersionKind(), uResource.GetNamespace(), uResource.GetName(), err.Error())
165+
klog.ErrorS(err, "Failed to apply the override rules", "resource", klog.KObj(&uResource), "resourceOverrideSnapshot", klog.KObj(snapshot))
166+
return false, controller.NewUserError(overrideErr)
165167
}
166168
}
167169
klog.V(2).InfoS("Applied resourceOverrideSnapshots", "resource", klog.KObj(&uResource), "numberOfOverrides", len(roMap[key]))
@@ -174,7 +176,7 @@ func applyOverrideRules(resource *placementv1beta1.ResourceContent, cluster *clu
174176
matched, err := overrider.IsClusterMatched(cluster, rule)
175177
if err != nil {
176178
klog.ErrorS(controller.NewUnexpectedBehaviorError(err), "Found an invalid override rule")
177-
return controller.NewUserError(err) // should not happen though and should be rejected by the webhook
179+
return err // should not happen though and should be rejected by the webhook
178180
}
179181
if !matched {
180182
continue

pkg/controllers/workgenerator/override_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ func TestApplyOverrides_clusterScopedResource(t *testing.T) {
11231123
}
11241124

11251125
var clusterRole rbacv1.ClusterRole
1126-
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, &clusterRole); err != nil {
1126+
if err = runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, &clusterRole); err != nil {
11271127
t.Fatalf("Failed to convert the result to clusterole: %v, want nil", err)
11281128
}
11291129

0 commit comments

Comments
 (0)