Skip to content

Commit

Permalink
fix(client-go): Solve the problem of testing error after client-go ve…
Browse files Browse the repository at this point in the history
…rsion upgrade
  • Loading branch information
00pf00 committed Jan 15, 2024
1 parent 8757e40 commit 1fa33c3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion pkg/ipam/floatingip/ipam_crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package floatingip

import (
"context"
"encoding/json"
"fmt"
"net"
Expand Down Expand Up @@ -142,7 +143,7 @@ func TestAllocateSpecificIP(t *testing.T) {
}

func checkFIP(ipam *crdIpam, expect ...string) error {
fips, err := ipam.client.GalaxyV1alpha1().FloatingIPs().List(v1.ListOptions{})
fips, err := ipam.client.GalaxyV1alpha1().FloatingIPs().List(context.Background(), v1.ListOptions{})
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/ipam/floatingip/store_crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package floatingip

import (
"context"
"fmt"
"net"
"strings"
Expand Down Expand Up @@ -44,7 +45,7 @@ func TestAddFloatingIPEventByUser(t *testing.T) {
if err := assign(fipCrd, fip); err != nil {
t.Fatal(err)
}
if _, err := ipam.client.GalaxyV1alpha1().FloatingIPs().Create(fipCrd); err != nil {
if _, err := ipam.client.GalaxyV1alpha1().FloatingIPs().Create(context.Background(), fipCrd, v1.CreateOptions{}); err != nil {
t.Fatal(err)
}
if err := waitFor(ipam, fip.IP, fip.Key, true, node1IPNet.String()); err != nil {
Expand Down Expand Up @@ -107,7 +108,7 @@ func TestDeleteFloatingIPEvent(t *testing.T) {
ip := net.ParseIP(fipCrd.Name)
fipCrd.Labels[constant.ReserveFIPLabel] = ""
fipCrd.Spec.Key = "pool__reserved-for-node_"
if _, err := ipam.client.GalaxyV1alpha1().FloatingIPs().Create(fipCrd); err != nil {
if _, err := ipam.client.GalaxyV1alpha1().FloatingIPs().Create(context.Background(), fipCrd, v1.CreateOptions{}); err != nil {
t.Fatal(err)
}
if err := waitFor(ipam, ip, fipCrd.Spec.Key, true, node1IPNet.String()); err != nil {
Expand All @@ -124,7 +125,7 @@ func TestDeleteFloatingIPEvent(t *testing.T) {

// test if an event is created by user, deleteFloatingIPEvent should handle it
fipCrd.Labels[constant.ReserveFIPLabel] = ""
if err := ipam.client.GalaxyV1alpha1().FloatingIPs().Delete(fipCrd.Name, &v1.DeleteOptions{}); err != nil {
if err := ipam.client.GalaxyV1alpha1().FloatingIPs().Delete(context.Background(), fipCrd.Name, v1.DeleteOptions{}); err != nil {
t.Fatal(err)
}
if err := waitFor(ipam, ip, "", false, node1IPNet.String()); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/ipam/schedulerplugin/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package schedulerplugin

import (
"context"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -223,7 +224,7 @@ func TestReleaseIPOfFinishedPod(t *testing.T) {
t.Fatalf("case %d: %v", i, err)
}
testCase.updatePodStatus(pod)
if _, err := fipPlugin.Client.CoreV1().Pods(pod.Namespace).UpdateStatus(pod); err != nil {
if _, err := fipPlugin.Client.CoreV1().Pods(pod.Namespace).UpdateStatus(context.Background(), pod, v1.UpdateOptions{}); err != nil {
t.Fatalf("case %d: %v", i, err)
}
if err := wait.Poll(time.Microsecond*10, time.Second*30, func() (done bool, err error) {
Expand Down Expand Up @@ -285,7 +286,7 @@ func TestFilterBindRequestIPRange(t *testing.T) {
t.Fatal(err)
}
pod.Annotations = cniArgsAnnotation(request)
if _, err := fipPlugin.Client.CoreV1().Pods(pod.Namespace).Update(pod); err != nil {
if _, err := fipPlugin.Client.CoreV1().Pods(pod.Namespace).Update(context.Background(), pod, v1.UpdateOptions{}); err != nil {
t.Fatal(err)
}
// wait for lister updates
Expand Down
2 changes: 1 addition & 1 deletion pkg/ipam/schedulerplugin/crdkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestGetGroupVersionResource(t *testing.T) {
if gvr == nil {
t.Fatal()
}
if gvr.Group != FooCrd.Spec.Group || gvr.Version != FooCrd.Spec.Version ||
if gvr.Group != FooCrd.Spec.Group || gvr.Version != FooCrd.Spec.Versions[0].Name ||
gvr.Resource != FooCrd.Spec.Names.Plural {
t.Fatal(gvr)
}
Expand Down

0 comments on commit 1fa33c3

Please sign in to comment.