Skip to content

Commit

Permalink
Improve errors in crs normalize data and scope
Browse files Browse the repository at this point in the history
  • Loading branch information
g-gaston committed Jan 25, 2023
1 parent d7d1ffa commit 2891a9c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 6 additions & 3 deletions exp/addons/internal/controllers/clusterresourceset_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func normalizeData(resource *unstructured.Unstructured) ([][]byte, error) {
keys := make([]string, 0)
data, ok := resource.UnstructuredContent()["data"]
if !ok {
return nil, errors.New("failed to get data field from the resource")
return nil, errors.Errorf("failed to get data field from resource %s", klog.KObj(resource))
}

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

byteArr := []byte(val)
Expand Down
7 changes: 3 additions & 4 deletions exp/addons/internal/controllers/clusterresourceset_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,9 @@ func (r *reconcileStrategyScope) applyObj(ctx context.Context, c client.Client,
if err = c.Patch(ctx, obj, patch); err != nil {
return errors.Wrapf(
err,
"patching object %s %s/%s",
"patching object %s %s",
obj.GroupVersionKind(),
obj.GetNamespace(),
obj.GetName(),
klog.KObj(obj),
)
}

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

0 comments on commit 2891a9c

Please sign in to comment.