-
Notifications
You must be signed in to change notification settings - Fork 367
/
querier.go
128 lines (114 loc) · 4.91 KB
/
querier.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2020 Antrea Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package querier
import (
v1 "k8s.io/api/core/v1"
apitypes "k8s.io/apimachinery/pkg/types"
"antrea.io/antrea/pkg/agent/interfacestore"
"antrea.io/antrea/pkg/agent/multicast"
"antrea.io/antrea/pkg/agent/types"
cpv1beta "antrea.io/antrea/pkg/apis/controlplane/v1beta2"
"antrea.io/antrea/pkg/util/env"
"antrea.io/antrea/pkg/version"
)
type NetworkPolicyInfoQuerier interface {
GetNetworkPolicyNum() int
GetAddressGroupNum() int
GetAppliedToGroupNum() int
}
type AgentNetworkPolicyInfoQuerier interface {
NetworkPolicyInfoQuerier
GetControllerConnectionStatus() bool
GetNetworkPolicies(npFilter *NetworkPolicyQueryFilter) []cpv1beta.NetworkPolicy
GetAddressGroups() []cpv1beta.AddressGroup
GetAppliedToGroups() []cpv1beta.AppliedToGroup
GetAppliedNetworkPolicies(pod, namespace string, npFilter *NetworkPolicyQueryFilter) []cpv1beta.NetworkPolicy
GetNetworkPolicyByRuleFlowID(ruleFlowID uint32) *cpv1beta.NetworkPolicyReference
GetRuleByFlowID(ruleFlowID uint32) *types.PolicyRule
}
type AgentMulticastInfoQuerier interface {
// CollectIGMPReportNPStats gets statistics generated by NetworkPolicies that block or allow
// IGMP reports message. The statistics returned are incremental and will be reset after each call.
CollectIGMPReportNPStats() (annpStats, acnpStats map[apitypes.UID]map[string]*types.RuleMetric)
// GetGroupPods gets a map that saves the local Pod members of multicast groups on the Node.
GetGroupPods() map[string][]cpv1beta.PodReference
// GetAllPodsStats gets multicast traffic statistics of all local Pods.
GetAllPodsStats() map[*interfacestore.InterfaceConfig]*multicast.PodTrafficStats
// GetPodStats gets multicast traffic statistics of a local Pod, specified by podName and podNamespace.
GetPodStats(podName string, podNamespace string) *multicast.PodTrafficStats
}
type ControllerNetworkPolicyInfoQuerier interface {
NetworkPolicyInfoQuerier
GetConnectedAgentNum() int
}
type EgressQuerier interface {
GetEgressIPByMark(mark uint32) (string, error)
GetEgress(podNamespace, podName string) (string, string, error)
}
// GetSelfPod gets current pod.
func GetSelfPod() v1.ObjectReference {
podName := env.GetPodName()
podNamespace := env.GetPodNamespace()
if podName == "" || podNamespace == "" {
return v1.ObjectReference{}
}
return v1.ObjectReference{Kind: "Pod", Name: podName, Namespace: podNamespace}
}
// GetSelfNode gets current node.
func GetSelfNode(isAgent bool, node string) v1.ObjectReference {
if isAgent {
if node == "" {
return v1.ObjectReference{}
}
return v1.ObjectReference{Kind: "Node", Name: node}
}
nodeName, _ := env.GetNodeName()
if nodeName == "" {
return v1.ObjectReference{}
}
return v1.ObjectReference{Kind: "Node", Name: nodeName}
}
// GetVersion gets current version.
func GetVersion() string {
return version.GetFullVersion()
}
// NetworkPolicyQueryFilter is used to filter the result while retrieve network policy
// An empty attribute, which won't be used as a condition, means match all.
// e.g SourceType = "" means all type network policy will be retrieved
// Can have more attributes in future if more args are required
type NetworkPolicyQueryFilter struct {
// The Name of the controlplane network policy. If this field is set then
// none of the other fields can be.
Name string
// The Name of the original network policy.
SourceName string
// The namespace of the original Namespace that the internal NetworkPolicy is created for.
Namespace string
// The type of the original NetworkPolicy that the internal NetworkPolicy is created for.(K8sNP, ACNP, ANNP)
SourceType cpv1beta.NetworkPolicyType
}
// ServiceExternalIPStatusQuerier queries the Service external IP status for debugging purposes.
// Ideally, every Node should have consistent results eventually. This should only be used when
// ServiceExternalIP feature is enabled.
type ServiceExternalIPStatusQuerier interface {
GetServiceExternalIPStatus() []ServiceExternalIPInfo
}
// ServiceExternalIPInfo contains the essential information for Services with type of Loadbalancer managed by Antrea.
type ServiceExternalIPInfo struct {
ServiceName string `json:"serviceName,omitempty" antctl:"name,Name of the Service"`
Namespace string `json:"namespace,omitempty"`
ExternalIP string `json:"externalIP,omitempty"`
ExternalIPPool string `json:"externalIPPool,omitempty"`
AssignedNode string `json:"assignedNode,omitempty"`
}