Skip to content

Commit

Permalink
feat: refactor monitor loop.
Browse files Browse the repository at this point in the history
Signed-off-by: IRONICBo <[email protected]>
  • Loading branch information
IRONICBo committed Apr 22, 2024
1 parent 3c8bb56 commit 6915393
Show file tree
Hide file tree
Showing 31 changed files with 493 additions and 424 deletions.
14 changes: 8 additions & 6 deletions build/charts/antrea/crds/nodelatencymonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
spec:
group: crd.antrea.io
versions:
- name: v1alpha2
- name: v1alpha1
served: true
storage: true
schema:
Expand All @@ -17,12 +17,14 @@ spec:
spec:
type: object
required:
- pingInterval
- pingIntervalSeconds
properties:
pingInterval:
pingIntervalSeconds:
type: integer
format: int32
minimum: 1
# Explanation: At least one second ("1") or higher in seconds.
description: "Ping interval in seconds, must be at least 1."
default: 10
metadata:
type: object
properties:
Expand All @@ -31,8 +33,8 @@ spec:
pattern: '^default$'
additionalPrinterColumns:
- description: Specifies the interval between pings.
jsonPath: .spec.pingInterval
name: PingInterval
jsonPath: .spec.pingIntervalSeconds
name: PingIntervalSeconds
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
Expand Down
14 changes: 8 additions & 6 deletions build/yamls/antrea-aks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4316,7 +4316,7 @@ metadata:
spec:
group: crd.antrea.io
versions:
- name: v1alpha2
- name: v1alpha1
served: true
storage: true
schema:
Expand All @@ -4328,12 +4328,14 @@ spec:
spec:
type: object
required:
- pingInterval
- pingIntervalSeconds
properties:
pingInterval:
pingIntervalSeconds:
type: integer
format: int32
minimum: 1
# Explanation: At least one second ("1") or higher in seconds.
description: "Ping interval in seconds, must be at least 1."
default: 10
metadata:
type: object
properties:
Expand All @@ -4342,8 +4344,8 @@ spec:
pattern: '^default$'
additionalPrinterColumns:
- description: Specifies the interval between pings.
jsonPath: .spec.pingInterval
name: PingInterval
jsonPath: .spec.pingIntervalSeconds
name: PingIntervalSeconds
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
Expand Down
14 changes: 8 additions & 6 deletions build/yamls/antrea-crds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4293,7 +4293,7 @@ metadata:
spec:
group: crd.antrea.io
versions:
- name: v1alpha2
- name: v1alpha1
served: true
storage: true
schema:
Expand All @@ -4305,12 +4305,14 @@ spec:
spec:
type: object
required:
- pingInterval
- pingIntervalSeconds
properties:
pingInterval:
pingIntervalSeconds:
type: integer
format: int32
minimum: 1
# Explanation: At least one second ("1") or higher in seconds.
description: "Ping interval in seconds, must be at least 1."
default: 10
metadata:
type: object
properties:
Expand All @@ -4319,8 +4321,8 @@ spec:
pattern: '^default$'
additionalPrinterColumns:
- description: Specifies the interval between pings.
jsonPath: .spec.pingInterval
name: PingInterval
jsonPath: .spec.pingIntervalSeconds
name: PingIntervalSeconds
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
Expand Down
14 changes: 8 additions & 6 deletions build/yamls/antrea-eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4316,7 +4316,7 @@ metadata:
spec:
group: crd.antrea.io
versions:
- name: v1alpha2
- name: v1alpha1
served: true
storage: true
schema:
Expand All @@ -4328,12 +4328,14 @@ spec:
spec:
type: object
required:
- pingInterval
- pingIntervalSeconds
properties:
pingInterval:
pingIntervalSeconds:
type: integer
format: int32
minimum: 1
# Explanation: At least one second ("1") or higher in seconds.
description: "Ping interval in seconds, must be at least 1."
default: 10
metadata:
type: object
properties:
Expand All @@ -4342,8 +4344,8 @@ spec:
pattern: '^default$'
additionalPrinterColumns:
- description: Specifies the interval between pings.
jsonPath: .spec.pingInterval
name: PingInterval
jsonPath: .spec.pingIntervalSeconds
name: PingIntervalSeconds
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
Expand Down
14 changes: 8 additions & 6 deletions build/yamls/antrea-gke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4316,7 +4316,7 @@ metadata:
spec:
group: crd.antrea.io
versions:
- name: v1alpha2
- name: v1alpha1
served: true
storage: true
schema:
Expand All @@ -4328,12 +4328,14 @@ spec:
spec:
type: object
required:
- pingInterval
- pingIntervalSeconds
properties:
pingInterval:
pingIntervalSeconds:
type: integer
format: int32
minimum: 1
# Explanation: At least one second ("1") or higher in seconds.
description: "Ping interval in seconds, must be at least 1."
default: 10
metadata:
type: object
properties:
Expand All @@ -4342,8 +4344,8 @@ spec:
pattern: '^default$'
additionalPrinterColumns:
- description: Specifies the interval between pings.
jsonPath: .spec.pingInterval
name: PingInterval
jsonPath: .spec.pingIntervalSeconds
name: PingIntervalSeconds
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
Expand Down
14 changes: 8 additions & 6 deletions build/yamls/antrea-ipsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4316,7 +4316,7 @@ metadata:
spec:
group: crd.antrea.io
versions:
- name: v1alpha2
- name: v1alpha1
served: true
storage: true
schema:
Expand All @@ -4328,12 +4328,14 @@ spec:
spec:
type: object
required:
- pingInterval
- pingIntervalSeconds
properties:
pingInterval:
pingIntervalSeconds:
type: integer
format: int32
minimum: 1
# Explanation: At least one second ("1") or higher in seconds.
description: "Ping interval in seconds, must be at least 1."
default: 10
metadata:
type: object
properties:
Expand All @@ -4342,8 +4344,8 @@ spec:
pattern: '^default$'
additionalPrinterColumns:
- description: Specifies the interval between pings.
jsonPath: .spec.pingInterval
name: PingInterval
jsonPath: .spec.pingIntervalSeconds
name: PingIntervalSeconds
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
Expand Down
14 changes: 8 additions & 6 deletions build/yamls/antrea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4316,7 +4316,7 @@ metadata:
spec:
group: crd.antrea.io
versions:
- name: v1alpha2
- name: v1alpha1
served: true
storage: true
schema:
Expand All @@ -4328,12 +4328,14 @@ spec:
spec:
type: object
required:
- pingInterval
- pingIntervalSeconds
properties:
pingInterval:
pingIntervalSeconds:
type: integer
format: int32
minimum: 1
# Explanation: At least one second ("1") or higher in seconds.
description: "Ping interval in seconds, must be at least 1."
default: 10
metadata:
type: object
properties:
Expand All @@ -4342,8 +4344,8 @@ spec:
pattern: '^default$'
additionalPrinterColumns:
- description: Specifies the interval between pings.
jsonPath: .spec.pingInterval
name: PingInterval
jsonPath: .spec.pingIntervalSeconds
name: PingIntervalSeconds
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
Expand Down
2 changes: 1 addition & 1 deletion cmd/antrea-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func run(o *Options) error {
endpointsInformer := informerFactory.Core().V1().Endpoints()
endpointSliceInformer := informerFactory.Discovery().V1().EndpointSlices()
namespaceInformer := informerFactory.Core().V1().Namespaces()
nodeLatencyMonitorInformer := crdInformerFactory.Crd().V1alpha2().NodeLatencyMonitors()
nodeLatencyMonitorInformer := crdInformerFactory.Crd().V1alpha1().NodeLatencyMonitors()

// Create Antrea Clientset for the given config.
antreaClientProvider := agent.NewAntreaClientProvider(o.config.AntreaClientConnection, k8sClient)
Expand Down
16 changes: 10 additions & 6 deletions pkg/agent/monitortool/latency_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ func NewLatencyStore(isNetworkPolicyOnly bool) *LatencyStore {
return store
}

func (l *LatencyStore) GetNodeIPLatencyEntryByKey(key string) (*NodeIPLatencyEntry, bool) {
func (l *LatencyStore) GetNodeIPLatencyEntryByKey(key string) *NodeIPLatencyEntry {
l.mutex.RLock()
defer l.mutex.RUnlock()

entry, found := l.nodeIPLatencyMap[key]

return entry, found
return l.nodeIPLatencyMap[key]
}

func (l *LatencyStore) DeleteNodeIPLatencyEntryByKey(key string) {
Expand Down Expand Up @@ -122,6 +120,7 @@ func (l *LatencyStore) updateNodeMap(node *corev1.Node) {
if l.isNetworkPolicyOnly {
transportIPs, err := getTransportIPs(node)
if err != nil {
klog.Errorf("Failed to get transport IPs for Node %s: %v", node.Name, err)
return
}

Expand All @@ -130,12 +129,15 @@ func (l *LatencyStore) updateNodeMap(node *corev1.Node) {
} else {
gw0IPs, err := getGWIPs(node)
if err != nil {
klog.Errorf("Failed to get gateway IPs for Node %s: %v", node.Name, err)
return
}

// Add the node to the node IP map
l.nodeGatewayMap[node.Name] = gw0IPs
}

klog.Infof("Node %s has gateway IPs %v", node.Name, l.nodeGatewayMap[node.Name])
}

func getTransportIPs(node *corev1.Node) ([]net.IP, error) {
Expand All @@ -161,21 +163,23 @@ func getGWIPs(node *corev1.Node) ([]net.IP, error) {
podCIDRStrs := getPodCIDRsOnNode(node)
if len(podCIDRStrs) == 0 {
// Skip the node if it does not have a PodCIDR.
klog.Warningf("Node %s does not have a PodCIDR", node.Name)
klog.Errorf("Node %s does not have a PodCIDR", node.Name)
return gwIPs, errors.New("node does not have a PodCIDR")
}

// the 0th entry must match the podCIDR field. It may contain at most 1 value for
// each of IPv4 and IPv6.
// Both podCIDRStrs need to be parsed to get the gateway IP.
for _, podCIDR := range podCIDRStrs {
if podCIDR == "" {
klog.Errorf("PodCIDR is empty for Node %s", node.Name)
return gwIPs, errors.New("PodCIDR is empty")
}

peerPodCIDRAddr, _, err := net.ParseCIDR(podCIDR)
if err != nil {
klog.Errorf("Failed to parse PodCIDR %s for Node %s", podCIDR, node.Name)
continue
return gwIPs, err
}

// Add first ip in CIDR to the map
Expand Down
Loading

0 comments on commit 6915393

Please sign in to comment.