diff --git a/build/charts/antrea/templates/agent/clusterrole.yaml b/build/charts/antrea/templates/agent/clusterrole.yaml index d8c3941a449..c63e0ad11e5 100644 --- a/build/charts/antrea/templates/agent/clusterrole.yaml +++ b/build/charts/antrea/templates/agent/clusterrole.yaml @@ -5,6 +5,18 @@ metadata: labels: app: antrea rules: + - apiGroups: + - stats.antrea.io + resources: + - networkpolicystats + - antreaclusternetworkpolicystats + - antreanetworkpolicystats + - nodeiplatencystats + verbs: + - get + - list + - create + - update - apiGroups: - "" resources: @@ -82,14 +94,6 @@ rules: - nodestatssummaries verbs: - create - - apiGroups: - - controlplane.antrea.io - resources: - - nodeiplatencystats - verbs: - - create - - get - - list - apiGroups: - controlplane.antrea.io resources: diff --git a/build/charts/antrea/templates/antctl/clusterrole.yaml b/build/charts/antrea/templates/antctl/clusterrole.yaml index 638a6b3813d..bcf74e284b4 100644 --- a/build/charts/antrea/templates/antctl/clusterrole.yaml +++ b/build/charts/antrea/templates/antctl/clusterrole.yaml @@ -26,10 +26,12 @@ rules: - networkpolicystats - antreaclusternetworkpolicystats - antreanetworkpolicystats - - nodeiplatencystat + - nodeiplatencystats verbs: - get - list + - create + - update - apiGroups: - system.antrea.io resources: diff --git a/build/images/Dockerfile.build.agent.ubi b/build/images/Dockerfile.build.agent.ubi index 300f67a6103..3462ed1cd1e 100644 --- a/build/images/Dockerfile.build.agent.ubi +++ b/build/images/Dockerfile.build.agent.ubi @@ -21,7 +21,7 @@ WORKDIR /antrea RUN --mount=type=cache,target=/go/pkg/mod/ \ --mount=type=bind,source=go.sum,target=go.sum \ --mount=type=bind,source=go.mod,target=go.mod \ - go env -w GOPROXY=https://goproxy.cn,direct;go mod download + go mod download COPY . /antrea diff --git a/build/images/Dockerfile.build.agent.ubuntu b/build/images/Dockerfile.build.agent.ubuntu index c08c6b0cf85..4d1168aff46 100644 --- a/build/images/Dockerfile.build.agent.ubuntu +++ b/build/images/Dockerfile.build.agent.ubuntu @@ -21,7 +21,7 @@ WORKDIR /antrea RUN --mount=type=cache,target=/go/pkg/mod/ \ --mount=type=bind,source=go.sum,target=go.sum \ --mount=type=bind,source=go.mod,target=go.mod \ - go env -w GOPROXY=https://goproxy.cn,direct;go mod download + go mod download COPY . /antrea diff --git a/build/images/Dockerfile.build.controller.ubi b/build/images/Dockerfile.build.controller.ubi index ab2737acd2d..d13b1105db8 100644 --- a/build/images/Dockerfile.build.controller.ubi +++ b/build/images/Dockerfile.build.controller.ubi @@ -21,7 +21,7 @@ WORKDIR /antrea RUN --mount=type=cache,target=/go/pkg/mod/ \ --mount=type=bind,source=go.sum,target=go.sum \ --mount=type=bind,source=go.mod,target=go.mod \ - go env -w GOPROXY=https://goproxy.cn,direct;go mod download + go mod download COPY . /antrea diff --git a/build/images/Dockerfile.build.controller.ubuntu b/build/images/Dockerfile.build.controller.ubuntu index 30cfe66d49a..9a2e03bfb21 100644 --- a/build/images/Dockerfile.build.controller.ubuntu +++ b/build/images/Dockerfile.build.controller.ubuntu @@ -21,7 +21,7 @@ WORKDIR /antrea RUN --mount=type=cache,target=/go/pkg/mod/ \ --mount=type=bind,source=go.sum,target=go.sum \ --mount=type=bind,source=go.mod,target=go.mod \ - go env -w GOPROXY=https://goproxy.cn,direct;go mod download + go mod download COPY . /antrea diff --git a/build/yamls/antrea-aks.yml b/build/yamls/antrea-aks.yml index 5627a1c0f25..e4c5f526dcf 100644 --- a/build/yamls/antrea-aks.yml +++ b/build/yamls/antrea-aks.yml @@ -4144,6 +4144,18 @@ metadata: labels: app: antrea rules: + - apiGroups: + - stats.antrea.io + resources: + - networkpolicystats + - antreaclusternetworkpolicystats + - antreanetworkpolicystats + - nodeiplatencystats + verbs: + - get + - list + - create + - update - apiGroups: - "" resources: @@ -4221,14 +4233,6 @@ rules: - nodestatssummaries verbs: - create - - apiGroups: - - controlplane.antrea.io - resources: - - nodeiplatencystats - verbs: - - create - - get - - list - apiGroups: - controlplane.antrea.io resources: @@ -4405,10 +4409,12 @@ rules: - networkpolicystats - antreaclusternetworkpolicystats - antreanetworkpolicystats - - nodeiplatencystat + - nodeiplatencystats verbs: - get - list + - create + - update - apiGroups: - system.antrea.io resources: diff --git a/build/yamls/antrea-eks.yml b/build/yamls/antrea-eks.yml index c7d5ebac697..50c2148e5ee 100644 --- a/build/yamls/antrea-eks.yml +++ b/build/yamls/antrea-eks.yml @@ -4144,6 +4144,18 @@ metadata: labels: app: antrea rules: + - apiGroups: + - stats.antrea.io + resources: + - networkpolicystats + - antreaclusternetworkpolicystats + - antreanetworkpolicystats + - nodeiplatencystats + verbs: + - get + - list + - create + - update - apiGroups: - "" resources: @@ -4221,14 +4233,6 @@ rules: - nodestatssummaries verbs: - create - - apiGroups: - - controlplane.antrea.io - resources: - - nodeiplatencystats - verbs: - - create - - get - - list - apiGroups: - controlplane.antrea.io resources: @@ -4405,10 +4409,12 @@ rules: - networkpolicystats - antreaclusternetworkpolicystats - antreanetworkpolicystats - - nodeiplatencystat + - nodeiplatencystats verbs: - get - list + - create + - update - apiGroups: - system.antrea.io resources: diff --git a/build/yamls/antrea-gke.yml b/build/yamls/antrea-gke.yml index fb187ce0646..585e74ea270 100644 --- a/build/yamls/antrea-gke.yml +++ b/build/yamls/antrea-gke.yml @@ -4144,6 +4144,18 @@ metadata: labels: app: antrea rules: + - apiGroups: + - stats.antrea.io + resources: + - networkpolicystats + - antreaclusternetworkpolicystats + - antreanetworkpolicystats + - nodeiplatencystats + verbs: + - get + - list + - create + - update - apiGroups: - "" resources: @@ -4221,14 +4233,6 @@ rules: - nodestatssummaries verbs: - create - - apiGroups: - - controlplane.antrea.io - resources: - - nodeiplatencystats - verbs: - - create - - get - - list - apiGroups: - controlplane.antrea.io resources: @@ -4405,10 +4409,12 @@ rules: - networkpolicystats - antreaclusternetworkpolicystats - antreanetworkpolicystats - - nodeiplatencystat + - nodeiplatencystats verbs: - get - list + - create + - update - apiGroups: - system.antrea.io resources: diff --git a/build/yamls/antrea-ipsec.yml b/build/yamls/antrea-ipsec.yml index f899d6b7696..1e1b609228a 100644 --- a/build/yamls/antrea-ipsec.yml +++ b/build/yamls/antrea-ipsec.yml @@ -4157,6 +4157,18 @@ metadata: labels: app: antrea rules: + - apiGroups: + - stats.antrea.io + resources: + - networkpolicystats + - antreaclusternetworkpolicystats + - antreanetworkpolicystats + - nodeiplatencystats + verbs: + - get + - list + - create + - update - apiGroups: - "" resources: @@ -4234,14 +4246,6 @@ rules: - nodestatssummaries verbs: - create - - apiGroups: - - controlplane.antrea.io - resources: - - nodeiplatencystats - verbs: - - create - - get - - list - apiGroups: - controlplane.antrea.io resources: @@ -4418,10 +4422,12 @@ rules: - networkpolicystats - antreaclusternetworkpolicystats - antreanetworkpolicystats - - nodeiplatencystat + - nodeiplatencystats verbs: - get - list + - create + - update - apiGroups: - system.antrea.io resources: diff --git a/build/yamls/antrea.yml b/build/yamls/antrea.yml index b9e761f2a65..992360224e2 100644 --- a/build/yamls/antrea.yml +++ b/build/yamls/antrea.yml @@ -4144,6 +4144,18 @@ metadata: labels: app: antrea rules: + - apiGroups: + - stats.antrea.io + resources: + - networkpolicystats + - antreaclusternetworkpolicystats + - antreanetworkpolicystats + - nodeiplatencystats + verbs: + - get + - list + - create + - update - apiGroups: - "" resources: @@ -4221,14 +4233,6 @@ rules: - nodestatssummaries verbs: - create - - apiGroups: - - controlplane.antrea.io - resources: - - nodeiplatencystats - verbs: - - create - - get - - list - apiGroups: - controlplane.antrea.io resources: @@ -4405,10 +4409,12 @@ rules: - networkpolicystats - antreaclusternetworkpolicystats - antreanetworkpolicystats - - nodeiplatencystat + - nodeiplatencystats verbs: - get - list + - create + - update - apiGroups: - system.antrea.io resources: diff --git a/cmd/antrea-agent/agent.go b/cmd/antrea-agent/agent.go index 46e7e1c9e86..831b01198e8 100644 --- a/cmd/antrea-agent/agent.go +++ b/cmd/antrea-agent/agent.go @@ -934,16 +934,16 @@ func run(o *Options) error { } // Start the node latency monitor. - // if features.DefaultFeatureGate.Enabled(features.NodeLatencyMonitor) && o.nodeType == config.K8sNode { - nodeLatencyMonitor := monitortool.NewNodeLatencyMonitor( - antreaClientProvider, - nodeInformer, - nodeLatencyMonitorInformer, - nodeConfig, - networkConfig.TrafficEncapMode, - ) - go nodeLatencyMonitor.Run(stopCh) - // } + if features.DefaultFeatureGate.Enabled(features.NodeLatencyMonitor) && o.nodeType == config.K8sNode { + nodeLatencyMonitor := monitortool.NewNodeLatencyMonitor( + antreaClientProvider, + nodeInformer, + nodeLatencyMonitorInformer, + nodeConfig, + networkConfig.TrafficEncapMode, + ) + go nodeLatencyMonitor.Run(stopCh) + } <-stopCh klog.Info("Stopping Antrea agent") diff --git a/multicluster/build/images/Dockerfile.build b/multicluster/build/images/Dockerfile.build index 52e77280246..f4225c1a726 100644 --- a/multicluster/build/images/Dockerfile.build +++ b/multicluster/build/images/Dockerfile.build @@ -20,7 +20,7 @@ WORKDIR /antrea RUN --mount=type=cache,target=/go/pkg/mod/ \ --mount=type=bind,source=go.sum,target=go.sum \ --mount=type=bind,source=go.mod,target=go.mod \ - go env -w GOPROXY=https://goproxy.cn,direct;go mod download + go mod download COPY . /antrea diff --git a/pkg/agent/monitortool/latency_store.go b/pkg/agent/monitortool/latency_store.go index 78882a72798..f76e3350227 100644 --- a/pkg/agent/monitortool/latency_store.go +++ b/pkg/agent/monitortool/latency_store.go @@ -20,6 +20,7 @@ import ( "sync" "time" + stv1aplpha1 "antrea.io/antrea/pkg/apis/stats/v1alpha1" "github.com/containernetworking/plugins/pkg/ip" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/sets" @@ -233,3 +234,34 @@ func (s *LatencyStore) DeleteStaleNodeIPs() { } } } + +// ConvertList converts the latency store to a list of NodeIPLatencyEntry. +func (l *LatencyStore) ConvertList() []stv1aplpha1.NodeIPLatencyEntry { + l.mutex.RLock() + defer l.mutex.RUnlock() + + entries := make([]stv1aplpha1.NodeIPLatencyEntry, 0, len(l.nodeIPLatencyMap)) + for nodeIP, entry := range l.nodeIPLatencyMap { + // Find the Node name for the given Node IP + var nodeName string + for name, ips := range l.nodeTargetIPsMap { + for _, ip := range ips { + if ip.String() == nodeIP { + nodeName = name + break + } + } + } + + tempEntry := stv1aplpha1.NodeIPLatencyEntry{ + NodeName: nodeName, + TargetIP: nodeIP, + LastSendTime: entry.LastSendTime.Unix(), + LastRecvTime: entry.LastRecvTime.Unix(), + LastMeasuredRTT: entry.LastMeasuredRTT.Nanoseconds(), + } + entries = append(entries, tempEntry) + } + + return entries +} diff --git a/pkg/agent/monitortool/monitor.go b/pkg/agent/monitortool/monitor.go index b0000a746f5..a3d715aaae8 100644 --- a/pkg/agent/monitortool/monitor.go +++ b/pkg/agent/monitortool/monitor.go @@ -15,16 +15,20 @@ package monitortool import ( + "context" "math/rand" "net" "sync" "sync/atomic" "time" + stv1aplpha1 "antrea.io/antrea/pkg/apis/stats/v1alpha1" + "antrea.io/antrea/pkg/util/env" "golang.org/x/net/icmp" "golang.org/x/net/ipv4" "golang.org/x/net/ipv6" corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" coreinformers "k8s.io/client-go/informers/core/v1" "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" @@ -133,7 +137,7 @@ func (m *NodeLatencyMonitor) onNodeAdd(obj interface{}) { m.latencyStore.addNode(node) - klog.V(4).InfoS("Node added", "Node", klog.KObj(node)) + klog.InfoS("Node added", "Node", klog.KObj(node)) } // onNodeUpdate is the event handler for updating Node. @@ -145,7 +149,7 @@ func (m *NodeLatencyMonitor) onNodeUpdate(oldObj, newObj interface{}) { m.latencyStore.updateNode(node) - klog.V(4).InfoS("Node updated", "Node", klog.KObj(node)) + klog.InfoS("Node updated", "Node", klog.KObj(node)) } // onNodeDelete is the event handler for deleting Node. @@ -174,7 +178,7 @@ func (m *NodeLatencyMonitor) onNodeDelete(obj interface{}) { // onNodeLatencyMonitorAdd is the event handler for adding NodeLatencyMonitor. func (m *NodeLatencyMonitor) onNodeLatencyMonitorAdd(obj interface{}) { nlm := obj.(*v1alpha1.NodeLatencyMonitor) - klog.V(4).InfoS("NodeLatencyMonitor added", "NodeLatencyMonitor", klog.KObj(nlm)) + klog.InfoS("NodeLatencyMonitor added", "NodeLatencyMonitor", klog.KObj(nlm)) m.updateLatencyConfig(nlm) } @@ -183,7 +187,7 @@ func (m *NodeLatencyMonitor) onNodeLatencyMonitorAdd(obj interface{}) { func (m *NodeLatencyMonitor) onNodeLatencyMonitorUpdate(oldObj, newObj interface{}) { oldNLM := oldObj.(*v1alpha1.NodeLatencyMonitor) newNLM := newObj.(*v1alpha1.NodeLatencyMonitor) - klog.V(4).InfoS("NodeLatencyMonitor updated", "NodeLatencyMonitor", klog.KObj(newNLM)) + klog.InfoS("NodeLatencyMonitor updated", "NodeLatencyMonitor", klog.KObj(newNLM)) if oldNLM.GetGeneration() == newNLM.GetGeneration() { return @@ -236,7 +240,7 @@ func (m *NodeLatencyMonitor) sendPing(socket net.PacketConn, addr net.IP) error Code: 0, Body: body, } - klog.V(4).InfoS("Sending ICMP message", "IP", ip, "SeqID", seqID, "body", body) + klog.InfoS("Sending ICMP message", "IP", ip, "SeqID", seqID, "body", body) // Serialize the ICMP message msgBytes, err := msg.Marshal(nil) @@ -331,7 +335,7 @@ func (m *NodeLatencyMonitor) recvPing(socket net.PacketConn, isIPv4 bool) { // Calculate the round-trip time end := time.Now() rtt := end.Sub(sentTime) - klog.V(4).InfoS("Updating latency entry for Node IP", "IP", destIP, "lastSendTime", sentTime, "lastRecvTime", end, "RTT", rtt) + klog.InfoS("Updating latency entry for Node IP", "IP", destIP, "lastSendTime", sentTime, "lastRecvTime", end, "RTT", rtt) // Update the latency store mutator := func(entry *NodeIPLatencyEntry) { @@ -344,7 +348,7 @@ func (m *NodeLatencyMonitor) recvPing(socket net.PacketConn, isIPv4 bool) { // pingAll sends ICMP messages to all the Nodes. func (m *NodeLatencyMonitor) pingAll(ipv4Socket, ipv6Socket net.PacketConn) { - klog.V(4).InfoS("Pinging all Nodes") + klog.InfoS("Pinging all Nodes") nodeIPs := m.latencyStore.ListNodeIPs() for _, toIP := range nodeIPs { if toIP.To4() != nil && ipv4Socket != nil { @@ -359,7 +363,34 @@ func (m *NodeLatencyMonitor) pingAll(ipv4Socket, ipv6Socket net.PacketConn) { klog.ErrorS(nil, "Cannot send ICMP message to Node IP because socket is not initialized for IP family", "IP", toIP) } } - klog.V(4).InfoS("Done pinging all Nodes") + klog.InfoS("Done pinging all Nodes") +} + +// GetSummary returns the latency summary of the given Node IP. +func (m *NodeLatencyMonitor) GetSummary() *stv1aplpha1.NodeIPLatencyStat { + nodeName, _ := env.GetNodeName() + return &stv1aplpha1.NodeIPLatencyStat{ + ObjectMeta: metav1.ObjectMeta{ + Name: nodeName, + }, + NodeIPLatencyList: m.latencyStore.ConvertList(), + } +} + +func (m *NodeLatencyMonitor) report() { + summary := m.GetSummary() + if summary == nil { + klog.InfoS("Latency summary is nil") + return + } + antreaClient, err := m.antreaClientProvider.GetAntreaClient() + if err != nil { + klog.ErrorS(err, "Failed to get Antrea client") + return + } + if _, err := antreaClient.StatsV1alpha1().NodeIPLatencyStats().Create(context.TODO(), summary, metav1.CreateOptions{}); err != nil { + klog.ErrorS(err, "Failed to update NodeIPLatencyStats") + } } // Run starts the NodeLatencyMonitor. @@ -410,6 +441,7 @@ func (m *NodeLatencyMonitor) monitorLoop(stopCh <-chan struct{}) { // to avoid consistency issues and because it would not be sufficient to avoid stale entries completely. // This means that we have to periodically invoke DeleteStaleNodeIPs to avoid stale entries in the map. m.latencyStore.DeleteStaleNodeIPs() + m.report() case <-stopCh: return case latencyConfig := <-m.latencyConfigChanged: diff --git a/pkg/apis/stats/v1alpha1/types.go b/pkg/apis/stats/v1alpha1/types.go index dd6755b3206..1831d16594a 100644 --- a/pkg/apis/stats/v1alpha1/types.go +++ b/pkg/apis/stats/v1alpha1/types.go @@ -148,8 +148,9 @@ type RuleTrafficStats struct { } // +genclient +// +genclient:nonNamespaced // +resourceName=nodeiplatencystats -// +genclient:readonly +// +genclient:onlyVerbs=create // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // NodeIPLatencyStat contains the latency stat of a Node. diff --git a/pkg/apiserver/apiserver.go b/pkg/apiserver/apiserver.go index 4cf272d3a58..f435d704992 100644 --- a/pkg/apiserver/apiserver.go +++ b/pkg/apiserver/apiserver.go @@ -241,7 +241,7 @@ func installAPIGroup(s *APIServer, c completedConfig) error { statsStorage["antreaclusternetworkpolicystats"] = antreaclusternetworkpolicystats.NewREST(c.extraConfig.statsAggregator) statsStorage["antreanetworkpolicystats"] = antreanetworkpolicystats.NewREST(c.extraConfig.statsAggregator) statsStorage["multicastgroups"] = multicastgroup.NewREST(c.extraConfig.statsAggregator) - statsStorage["nodeiplatency"] = nodelatencystat.NewREST() + statsStorage["nodeiplatencystats"] = nodelatencystat.NewREST() statsGroup.VersionedResourcesStorageMap["v1alpha1"] = statsStorage groups := []*genericapiserver.APIGroupInfo{&cpGroup, &systemGroup, &statsGroup} diff --git a/pkg/apiserver/registry/stats/nodelatencystat/rest.go b/pkg/apiserver/registry/stats/nodelatencystat/rest.go index ebf66eb2983..e37e3d14d59 100644 --- a/pkg/apiserver/registry/stats/nodelatencystat/rest.go +++ b/pkg/apiserver/registry/stats/nodelatencystat/rest.go @@ -64,6 +64,7 @@ func (n *nodeLatencyCollectorImpl) Get(name string) *statsv1alpha1.NodeIPLatency func (n *nodeLatencyCollectorImpl) List() []statsv1alpha1.NodeIPLatencyStat { objs := n.nodeLatencyStats.List() + klog.InfoS("NodeIPLatencyStat list", "objs", objs) entries := make([]statsv1alpha1.NodeIPLatencyStat, len(objs)) for i := range objs { entries[i] = *(objs[i].(*statsv1alpha1.NodeIPLatencyStat)) @@ -108,10 +109,7 @@ func NewREST() *REST { }() return &REST{ - nodeLatencyCollector: &nodeLatencyCollectorImpl{ - nodeLatencyStats: cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, uidIndex: uidIndexFunc}), - dataCh: make(chan *statsv1alpha1.NodeIPLatencyStat, 1000), - }, + nodeLatencyCollector: nodeLatencyCollector, } } diff --git a/pkg/apiserver/registry/stats/nodelatencystat/rest_test.go b/pkg/apiserver/registry/stats/nodelatencystat/rest_test.go index 2cc541cbac5..a67bc6590ba 100644 --- a/pkg/apiserver/registry/stats/nodelatencystat/rest_test.go +++ b/pkg/apiserver/registry/stats/nodelatencystat/rest_test.go @@ -13,47 +13,3 @@ // limitations under the License. package nodelatencystat - -// import ( -// "context" -// "testing" - -// "github.com/stretchr/testify/assert" -// v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - -// "antrea.io/antrea/pkg/apis/controlplane" -// ) - -// func TestREST(t *testing.T) { -// r := NewREST(nil) -// assert.Equal(t, &controlplane.NodeIPLatencyStat{}, r.New()) -// assert.False(t, r.NamespaceScoped()) -// } - -// type fakeCollector struct { -// gotSummary *controlplane.NodeIPLatencyStat -// } - -// func (f *fakeCollector) Collect(summary *controlplane.NodeIPLatencyStat) { -// f.gotSummary = summary -// } - -// func (f *fakeCollector) Get(name string) (*controlplane.NodeIPLatencyStat, error) { -// return nil, nil -// } - -// func TestRESTCreate(t *testing.T) { -// collector := &fakeCollector{} -// r := NewREST(collector) - -// summary := &controlplane.NodeIPLatencyStat{ -// ObjectMeta: v1.ObjectMeta{ -// Name: "foo", -// }, -// } -// actualObj, err := r.Create(context.TODO(), summary, nil, &v1.CreateOptions{}) -// assert.NoError(t, err) -// // Empty struct is returned on success. -// assert.Equal(t, &controlplane.NodeIPLatencyStat{}, actualObj) -// assert.Equal(t, summary, collector.gotSummary) -// } diff --git a/pkg/client/clientset/versioned/typed/stats/v1alpha1/fake/fake_nodeiplatencystat.go b/pkg/client/clientset/versioned/typed/stats/v1alpha1/fake/fake_nodeiplatencystat.go index e2558209216..e70477b349f 100644 --- a/pkg/client/clientset/versioned/typed/stats/v1alpha1/fake/fake_nodeiplatencystat.go +++ b/pkg/client/clientset/versioned/typed/stats/v1alpha1/fake/fake_nodeiplatencystat.go @@ -21,57 +21,24 @@ import ( v1alpha1 "antrea.io/antrea/pkg/apis/stats/v1alpha1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - watch "k8s.io/apimachinery/pkg/watch" testing "k8s.io/client-go/testing" ) // FakeNodeIPLatencyStats implements NodeIPLatencyStatInterface type FakeNodeIPLatencyStats struct { Fake *FakeStatsV1alpha1 - ns string } var nodeiplatencystatsResource = v1alpha1.SchemeGroupVersion.WithResource("nodeiplatencystats") var nodeiplatencystatsKind = v1alpha1.SchemeGroupVersion.WithKind("NodeIPLatencyStat") -// Get takes name of the nodeIPLatencyStat, and returns the corresponding nodeIPLatencyStat object, and an error if there is any. -func (c *FakeNodeIPLatencyStats) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.NodeIPLatencyStat, err error) { +// Create takes the representation of a nodeIPLatencyStat and creates it. Returns the server's representation of the nodeIPLatencyStat, and an error, if there is any. +func (c *FakeNodeIPLatencyStats) Create(ctx context.Context, nodeIPLatencyStat *v1alpha1.NodeIPLatencyStat, opts v1.CreateOptions) (result *v1alpha1.NodeIPLatencyStat, err error) { obj, err := c.Fake. - Invokes(testing.NewGetAction(nodeiplatencystatsResource, c.ns, name), &v1alpha1.NodeIPLatencyStat{}) - + Invokes(testing.NewRootCreateAction(nodeiplatencystatsResource, nodeIPLatencyStat), &v1alpha1.NodeIPLatencyStat{}) if obj == nil { return nil, err } return obj.(*v1alpha1.NodeIPLatencyStat), err } - -// List takes label and field selectors, and returns the list of NodeIPLatencyStats that match those selectors. -func (c *FakeNodeIPLatencyStats) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.NodeIPLatencyStatList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(nodeiplatencystatsResource, nodeiplatencystatsKind, c.ns, opts), &v1alpha1.NodeIPLatencyStatList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.NodeIPLatencyStatList{ListMeta: obj.(*v1alpha1.NodeIPLatencyStatList).ListMeta} - for _, item := range obj.(*v1alpha1.NodeIPLatencyStatList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested nodeIPLatencyStats. -func (c *FakeNodeIPLatencyStats) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(nodeiplatencystatsResource, c.ns, opts)) - -} diff --git a/pkg/client/clientset/versioned/typed/stats/v1alpha1/fake/fake_stats_client.go b/pkg/client/clientset/versioned/typed/stats/v1alpha1/fake/fake_stats_client.go index f339063e840..b87fb1fe531 100644 --- a/pkg/client/clientset/versioned/typed/stats/v1alpha1/fake/fake_stats_client.go +++ b/pkg/client/clientset/versioned/typed/stats/v1alpha1/fake/fake_stats_client.go @@ -42,8 +42,8 @@ func (c *FakeStatsV1alpha1) NetworkPolicyStats(namespace string) v1alpha1.Networ return &FakeNetworkPolicyStats{c, namespace} } -func (c *FakeStatsV1alpha1) NodeIPLatencyStats(namespace string) v1alpha1.NodeIPLatencyStatInterface { - return &FakeNodeIPLatencyStats{c, namespace} +func (c *FakeStatsV1alpha1) NodeIPLatencyStats() v1alpha1.NodeIPLatencyStatInterface { + return &FakeNodeIPLatencyStats{c} } // RESTClient returns a RESTClient that is used to communicate diff --git a/pkg/client/clientset/versioned/typed/stats/v1alpha1/nodeiplatencystat.go b/pkg/client/clientset/versioned/typed/stats/v1alpha1/nodeiplatencystat.go index dbcb3655038..c00d59ccd1d 100644 --- a/pkg/client/clientset/versioned/typed/stats/v1alpha1/nodeiplatencystat.go +++ b/pkg/client/clientset/versioned/typed/stats/v1alpha1/nodeiplatencystat.go @@ -18,84 +18,45 @@ package v1alpha1 import ( "context" - "time" v1alpha1 "antrea.io/antrea/pkg/apis/stats/v1alpha1" scheme "antrea.io/antrea/pkg/client/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - watch "k8s.io/apimachinery/pkg/watch" rest "k8s.io/client-go/rest" ) // NodeIPLatencyStatsGetter has a method to return a NodeIPLatencyStatInterface. // A group's client should implement this interface. type NodeIPLatencyStatsGetter interface { - NodeIPLatencyStats(namespace string) NodeIPLatencyStatInterface + NodeIPLatencyStats() NodeIPLatencyStatInterface } // NodeIPLatencyStatInterface has methods to work with NodeIPLatencyStat resources. type NodeIPLatencyStatInterface interface { - Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.NodeIPLatencyStat, error) - List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.NodeIPLatencyStatList, error) - Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Create(ctx context.Context, nodeIPLatencyStat *v1alpha1.NodeIPLatencyStat, opts v1.CreateOptions) (*v1alpha1.NodeIPLatencyStat, error) NodeIPLatencyStatExpansion } // nodeIPLatencyStats implements NodeIPLatencyStatInterface type nodeIPLatencyStats struct { client rest.Interface - ns string } // newNodeIPLatencyStats returns a NodeIPLatencyStats -func newNodeIPLatencyStats(c *StatsV1alpha1Client, namespace string) *nodeIPLatencyStats { +func newNodeIPLatencyStats(c *StatsV1alpha1Client) *nodeIPLatencyStats { return &nodeIPLatencyStats{ client: c.RESTClient(), - ns: namespace, } } -// Get takes name of the nodeIPLatencyStat, and returns the corresponding nodeIPLatencyStat object, and an error if there is any. -func (c *nodeIPLatencyStats) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.NodeIPLatencyStat, err error) { +// Create takes the representation of a nodeIPLatencyStat and creates it. Returns the server's representation of the nodeIPLatencyStat, and an error, if there is any. +func (c *nodeIPLatencyStats) Create(ctx context.Context, nodeIPLatencyStat *v1alpha1.NodeIPLatencyStat, opts v1.CreateOptions) (result *v1alpha1.NodeIPLatencyStat, err error) { result = &v1alpha1.NodeIPLatencyStat{} - err = c.client.Get(). - Namespace(c.ns). - Resource("nodeiplatencystats"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of NodeIPLatencyStats that match those selectors. -func (c *nodeIPLatencyStats) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.NodeIPLatencyStatList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.NodeIPLatencyStatList{} - err = c.client.Get(). - Namespace(c.ns). + err = c.client.Post(). Resource("nodeiplatencystats"). VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). + Body(nodeIPLatencyStat). Do(ctx). Into(result) return } - -// Watch returns a watch.Interface that watches the requested nodeIPLatencyStats. -func (c *nodeIPLatencyStats) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("nodeiplatencystats"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} diff --git a/pkg/client/clientset/versioned/typed/stats/v1alpha1/stats_client.go b/pkg/client/clientset/versioned/typed/stats/v1alpha1/stats_client.go index 8fd9e3f0485..2752fa70f18 100644 --- a/pkg/client/clientset/versioned/typed/stats/v1alpha1/stats_client.go +++ b/pkg/client/clientset/versioned/typed/stats/v1alpha1/stats_client.go @@ -54,8 +54,8 @@ func (c *StatsV1alpha1Client) NetworkPolicyStats(namespace string) NetworkPolicy return newNetworkPolicyStats(c, namespace) } -func (c *StatsV1alpha1Client) NodeIPLatencyStats(namespace string) NodeIPLatencyStatInterface { - return newNodeIPLatencyStats(c, namespace) +func (c *StatsV1alpha1Client) NodeIPLatencyStats() NodeIPLatencyStatInterface { + return newNodeIPLatencyStats(c) } // NewForConfig creates a new StatsV1alpha1Client for the given config.