Skip to content

Commit

Permalink
chore: add fake antrea client.
Browse files Browse the repository at this point in the history
Signed-off-by: Asklv <boironic@gmail.com>
  • Loading branch information
IRONICBo committed Jun 16, 2024
1 parent 4eae08c commit 101d7bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion pkg/agent/monitortool/latency_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ func (l *LatencyStore) ConvertList(currentNodeName string) []statsv1alpha1.PeerN
targetIPLatencyStats := make([]statsv1alpha1.TargetIPLatencyStats, 0, len(nodeIPs))
for _, nodeIP := range nodeIPs {
nodeIPStr := nodeIP.String()
latencyEntry := l.nodeIPLatencyMap[nodeIPStr]
latencyEntry, ok := l.nodeIPLatencyMap[nodeIPStr]
if !ok {
continue
}
entry := statsv1alpha1.TargetIPLatencyStats{
TargetIP: nodeIPStr,
LastSendTime: metav1.NewTime(latencyEntry.LastSendTime),
Expand Down
13 changes: 10 additions & 3 deletions pkg/agent/monitortool/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/fake"
componentbaseconfig "k8s.io/component-base/config"
"k8s.io/utils/clock"
clocktesting "k8s.io/utils/clock/testing"

"antrea.io/antrea/pkg/agent/client"
"antrea.io/antrea/pkg/agent/config"
monitortesting "antrea.io/antrea/pkg/agent/monitortool/testing"
"antrea.io/antrea/pkg/agent/util/nettest"
crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1"
"antrea.io/antrea/pkg/client/clientset/versioned"
fakeversioned "antrea.io/antrea/pkg/client/clientset/versioned/fake"
crdinformers "antrea.io/antrea/pkg/client/informers/externalversions"
"antrea.io/antrea/pkg/util/ip"
Expand Down Expand Up @@ -136,6 +135,14 @@ func (c *fakeClock) NewTicker(d time.Duration) clock.Ticker {
return c.FakeClock.NewTicker(d)
}

type antreaClientGetter struct {
clientset versioned.Interface
}

func (g *antreaClientGetter) GetAntreaClient() (versioned.Interface, error) {
return g.clientset, nil
}

type testMonitor struct {
*NodeLatencyMonitor
clientset *fake.Clientset
Expand All @@ -162,7 +169,7 @@ func newTestMonitor(
crdClientset := fakeversioned.NewSimpleClientset(crdObjects...)
crdInformerFactory := crdinformers.NewSharedInformerFactory(crdClientset, 0)
nlmInformer := crdInformerFactory.Crd().V1alpha1().NodeLatencyMonitors()
antreaClientProvider, _ := client.NewAntreaClientProvider(componentbaseconfig.ClientConnectionConfiguration{}, clientset)
antreaClientProvider := &antreaClientGetter{fakeversioned.NewSimpleClientset(crdObjects...)}
m := NewNodeLatencyMonitor(antreaClientProvider, nodeInformer, nlmInformer, nodeConfig, trafficEncapMode)
fakeClock := newFakeClock(clockT)
m.clock = fakeClock
Expand Down

0 comments on commit 101d7bb

Please sign in to comment.