Skip to content

Commit 2891a9c

Browse files
committed
Improve errors in crs normalize data and scope
1 parent d7d1ffa commit 2891a9c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

exp/addons/internal/controllers/clusterresourceset_helpers.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func normalizeData(resource *unstructured.Unstructured) ([][]byte, error) {
204204
keys := make([]string, 0)
205205
data, ok := resource.UnstructuredContent()["data"]
206206
if !ok {
207-
return nil, errors.New("failed to get data field from the resource")
207+
return nil, errors.Errorf("failed to get data field from resource %s", klog.KObj(resource))
208208
}
209209

210210
unstructuredData := data.(map[string]interface{})
@@ -216,8 +216,11 @@ func normalizeData(resource *unstructured.Unstructured) ([][]byte, error) {
216216
dataList := make([][]byte, 0)
217217
for _, key := range keys {
218218
val, ok, err := unstructured.NestedString(unstructuredData, key)
219-
if !ok || err != nil {
220-
return nil, errors.New("failed to get value field from the resource")
219+
if err != nil {
220+
return nil, errors.Wrapf(err, "getting value for field %s in data from resource %s", key, klog.KObj(resource))
221+
}
222+
if !ok {
223+
return nil, errors.Errorf("value for field %s not present in data from resource %s", key, klog.KObj(resource))
221224
}
222225

223226
byteArr := []byte(val)

exp/addons/internal/controllers/clusterresourceset_scope.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,9 @@ func (r *reconcileStrategyScope) applyObj(ctx context.Context, c client.Client,
140140
if err = c.Patch(ctx, obj, patch); err != nil {
141141
return errors.Wrapf(
142142
err,
143-
"patching object %s %s/%s",
143+
"patching object %s %s",
144144
obj.GroupVersionKind(),
145-
obj.GetNamespace(),
146-
obj.GetName(),
145+
klog.KObj(obj),
147146
)
148147
}
149148

@@ -165,7 +164,7 @@ func (r *reconcileApplyOnceScope) apply(ctx context.Context, c client.Client) er
165164
func (r *reconcileApplyOnceScope) applyObj(ctx context.Context, c client.Client, obj *unstructured.Unstructured) error {
166165
// The create call is idempotent, so if the object already exists
167166
// then do not consider it to be an error.
168-
if err := createUnstructured(ctx, c, obj); !apierrors.IsAlreadyExists(err) {
167+
if err := createUnstructured(ctx, c, obj); err != nil && !apierrors.IsAlreadyExists(err) {
169168
return err
170169
}
171170
return nil

0 commit comments

Comments
 (0)