Skip to content

🐛Use k8s.io/apimachinery/pkg/util/json to unmarshal in fakeclient #3208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/client/fake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package fake
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"reflect"
Expand Down Expand Up @@ -58,6 +57,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets please add a test for the issue, otherwise this will likely break again in the future

Copy link
Member

@sbueringer sbueringer May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[I might be mixing up stuff]

IIRC this is heavily aligned to the upstream client-go fake client and we want to avoid differences in behavior.

What is the upstream fake client doing here? (or is it not using the json package at all and this is just from additional code that we have here)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this is heavily aligned to the upstream client-go fake client and we want to avoid differences in behavior.

What is the upstream fake client doing here? (or is it not using the json package at all and this is just from additional code that we have here)

I am not seeing anything in client-go fakeclient where this would be present. I may be overlooking it but it seems they use k8s.io/apimachinery/pkg/util/json in client-go but not for the fakeclient. They are using instances of encoding/json to Marshal for the ApplyConfigurations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sbueringer I think you are confusing this with json patch, I don't think there is any reason for upstream to do json encoding in the fake client. We need it because of edge cases like "Object gets stored and retrieved in different representations like unstructured/structure", that issue does not exist in upstream fake clients as they don't support that

Copy link
Member

@sbueringer sbueringer May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, thx for the additional info!

I know that it's not the json patch case, was just wondering if it's a similar case

utilrand "k8s.io/apimachinery/pkg/util/rand"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/strategicpatch"
Expand Down
Loading