Merge pull request #7869 from erikgb/no-new-simple-clientset
Migrate away from deprecated fake NewSimpleClientset func
This commit is contained in:
commit
8e319f7603
@ -306,7 +306,7 @@ func TestScheduleN(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
cl := fake.NewSimpleClientset()
|
||||
cl := fake.NewClientset()
|
||||
factory := cminformers.NewSharedInformerFactory(cl, 0)
|
||||
challengesInformer := factory.Acme().V1().Challenges()
|
||||
for _, ch := range test.challenges {
|
||||
|
||||
@ -134,7 +134,7 @@ func runUpdateObjectTests(t *testing.T) {
|
||||
t.Log("Simulating a situation where the target object has been deleted")
|
||||
objects = nil
|
||||
}
|
||||
cl := fake.NewSimpleClientset(objects...)
|
||||
cl := fake.NewClientset(objects...)
|
||||
if tt.updateError != nil {
|
||||
cl.PrependReactor("update", "challenges", func(action clienttesting.Action) (handled bool, ret runtime.Object, err error) {
|
||||
t.Log("Simulating a challenge update error")
|
||||
@ -165,7 +165,11 @@ func runUpdateObjectTests(t *testing.T) {
|
||||
actual, err := cl.AcmeV1().Challenges(oldChallenge.Namespace).Get(t.Context(), oldChallenge.Name, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
if updateObjectErr == nil {
|
||||
assert.Equal(t, newChallenge, actual, "updateObject did not return an error so the object in the API should have been updated")
|
||||
// We ignore differences in .ManagedFields since the expected object does not have them.
|
||||
// FIXME: don't ignore this field
|
||||
expected := newChallenge
|
||||
expected.ManagedFields = actual.ManagedFields
|
||||
assert.Equal(t, expected, actual, "updateObject did not return an error so the object in the API should have been updated")
|
||||
} else {
|
||||
if !errors.Is(updateObjectErr, simulatedUpdateError) {
|
||||
assert.Equal(t, newChallenge.Finalizers, actual.Finalizers, "The Update did not fail so the Finalizers of the API object should have been updated")
|
||||
|
||||
@ -485,7 +485,7 @@ func TestProcessItem(t *testing.T) {
|
||||
},
|
||||
expectedEvents: []string{`Normal Requested Created new CertificateRequest resource "test-1"`},
|
||||
expectedActions: []testpkg.Action{
|
||||
testpkg.NewAction(coretesting.NewDeleteAction(cmapi.SchemeGroupVersion.WithResource("certificaterequests"), "testns", "test")),
|
||||
testpkg.NewAction(coretesting.NewDeleteAction(cmapi.SchemeGroupVersion.WithResource("certificaterequests"), "testns", "test-1")),
|
||||
testpkg.NewCustomMatch(coretesting.NewCreateAction(cmapi.SchemeGroupVersion.WithResource("certificaterequests"), "testns",
|
||||
gen.CertificateRequestFrom(bundle1.certificateRequest,
|
||||
gen.SetCertificateRequestName("test-1"),
|
||||
|
||||
@ -18,8 +18,8 @@ package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/kr/pretty"
|
||||
coretesting "k8s.io/client-go/testing"
|
||||
)
|
||||
@ -79,19 +79,16 @@ func (a *action) Action() coretesting.Action {
|
||||
|
||||
// Matches compares action.action with another Action.
|
||||
func (a *action) Matches(act coretesting.Action) error {
|
||||
matches := reflect.DeepEqual(a.action, act)
|
||||
if matches {
|
||||
return nil
|
||||
diff := cmp.Diff(a.action, act,
|
||||
// We ignore differences in .ManagedFields since the expected object does not have them.
|
||||
// FIXME: don't ignore this field
|
||||
cmp.FilterPath(func(p cmp.Path) bool {
|
||||
// FIXME: Must ignore managed fields as newer fake clients are tracking them
|
||||
return p.Last().String() == ".ManagedFields"
|
||||
}, cmp.Ignore()),
|
||||
)
|
||||
if diff != "" {
|
||||
return fmt.Errorf("unexpected difference between actions (-want +got):\n%s", pretty.Diff(a.action, act))
|
||||
}
|
||||
|
||||
objAct, ok := act.(coretesting.CreateAction)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
objExp, ok := a.action.(coretesting.CreateAction)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("unexpected difference between actions: %s", pretty.Diff(objExp.GetObject(), objAct.GetObject()))
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -126,8 +126,9 @@ func (b *Builder) Init() {
|
||||
b.T.Fatalf("error adding meta to scheme: %v", err)
|
||||
}
|
||||
b.ACMEOptions.ACMEHTTP01SolverRunAsNonRoot = true // default from cmd/controller/app/options/options.go
|
||||
b.Client = kubefake.NewSimpleClientset(b.KubeObjects...)
|
||||
b.CMClient = cmfake.NewSimpleClientset(b.CertManagerObjects...)
|
||||
b.Client = kubefake.NewClientset(b.KubeObjects...)
|
||||
b.CMClient = cmfake.NewClientset(b.CertManagerObjects...)
|
||||
// FIXME: It seems like the gateway-api fake.NewClientset is misbehaving and is not usable per July 2025
|
||||
b.GWClient = gwfake.NewSimpleClientset(b.GWObjects...)
|
||||
b.MetadataClient = metadatafake.NewSimpleMetadataClient(scheme, b.PartialMetadataObjects...)
|
||||
b.DiscoveryClient = discoveryfake.NewDiscovery().WithServerResourcesForGroupVersion(func(groupVersion string) (*metav1.APIResourceList, error) {
|
||||
|
||||
@ -470,6 +470,8 @@ func TestCleanupIngresses(t *testing.T) {
|
||||
t.Errorf("error getting ingress resource: %v", err)
|
||||
}
|
||||
|
||||
expectedIng.ManagedFields = actualIng.ManagedFields
|
||||
|
||||
if diff := cmp.Diff(expectedIng, actualIng); diff != "" {
|
||||
t.Errorf("expected did not match actual (-want +got):\n%s", diff)
|
||||
}
|
||||
@ -657,11 +659,14 @@ func TestMergeIngressObjectMetaWithIngressResourceTemplate(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
expectedIngress.APIVersion = resp.APIVersion
|
||||
expectedIngress.Kind = resp.Kind
|
||||
expectedIngress.OwnerReferences = resp.OwnerReferences
|
||||
expectedIngress.ManagedFields = resp.ManagedFields
|
||||
expectedIngress.Name = resp.Name
|
||||
|
||||
if !reflect.DeepEqual(resp, expectedIngress) {
|
||||
t.Errorf("unexpected ingress generated from merge\nexp=%+v\ngot=%+v", expectedIngress, resp)
|
||||
if diff := cmp.Diff(expectedIngress, resp); diff != "" {
|
||||
t.Errorf("unexpected ingress generated from merge (-want +got):\n%s", diff)
|
||||
}
|
||||
},
|
||||
},
|
||||
@ -735,11 +740,14 @@ func TestOverrideNginxIngressWhitelistAnnotation(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
expectedIngress.APIVersion = resp.APIVersion
|
||||
expectedIngress.Kind = resp.Kind
|
||||
expectedIngress.OwnerReferences = resp.OwnerReferences
|
||||
expectedIngress.ManagedFields = resp.ManagedFields
|
||||
expectedIngress.Name = resp.Name
|
||||
|
||||
if !reflect.DeepEqual(resp, expectedIngress) {
|
||||
t.Errorf("unexpected ingress generated from merge\nexp=%+v\ngot=%+v", expectedIngress, resp)
|
||||
if diff := cmp.Diff(expectedIngress, resp); diff != "" {
|
||||
t.Errorf("unexpected ingress generated from merge (-want +got):\n%s", diff)
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
@ -430,7 +430,7 @@ func TestVault_Setup(t *testing.T) {
|
||||
IssuerConfig: tt.givenIssuer,
|
||||
},
|
||||
}
|
||||
cmclient := cmfake.NewSimpleClientset(givenIssuer)
|
||||
cmclient := cmfake.NewClientset(givenIssuer)
|
||||
|
||||
v := &Vault{
|
||||
Context: &controller.Context{CMClient: cmclient},
|
||||
|
||||
@ -92,7 +92,7 @@ func Test_ACMEChallenges(t *testing.T) {
|
||||
gen.SetChallengeNamespace("test-challenge"),
|
||||
))
|
||||
|
||||
fakeClient := fake.NewSimpleClientset()
|
||||
fakeClient := fake.NewClientset()
|
||||
factory := externalversions.NewSharedInformerFactory(fakeClient, 0)
|
||||
challengesInformer := factory.Acme().V1().Challenges()
|
||||
for _, ch := range challenges {
|
||||
|
||||
@ -74,7 +74,7 @@ func testAuthority(t *testing.T, name string, cs *kubefake.Clientset) *DynamicAu
|
||||
}
|
||||
|
||||
func TestDynamicAuthority(t *testing.T) {
|
||||
fake := kubefake.NewSimpleClientset()
|
||||
fake := kubefake.NewClientset()
|
||||
|
||||
da := testAuthority(t, "authority", fake)
|
||||
|
||||
@ -135,7 +135,7 @@ func TestDynamicAuthority(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDynamicAuthorityMulti(t *testing.T) {
|
||||
fake := kubefake.NewSimpleClientset()
|
||||
fake := kubefake.NewClientset()
|
||||
|
||||
authorities := make([]*DynamicAuthority, 0)
|
||||
for i := range 200 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user