Skip to content

Commit

Permalink
[IPv6] Handle dual stack NodeSubnet for monitoring CRD (#1182)
Browse files Browse the repository at this point in the history
1. Rename NodeSubnet to NodeSubnets for AntreaAgentInfo.

2. Make a new string slice for dual stack node subnet instead of
appending agentInfo.NodeSubnets directly to avoid duplicate CIDRs.
  • Loading branch information
mengdie-song authored and wenyingd committed Sep 25, 2020
1 parent 73394b3 commit 3a2ceca
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 23 deletions.
6 changes: 3 additions & 3 deletions pkg/agent/apiserver/handlers/agentinfo/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type AntreaAgentInfoResponse struct {
Version string `json:"version,omitempty"` // Antrea binary version
PodRef corev1.ObjectReference `json:"podRef,omitempty"` // The Pod that Antrea Agent is running in
NodeRef corev1.ObjectReference `json:"nodeRef,omitempty"` // The Node that Antrea Agent is running in
NodeSubnet []string `json:"nodeSubnet,omitempty"` // Node subnet
NodeSubnets []string `json:"nodeSubnets,omitempty"` // Node subnets
OVSInfo v1beta1.OVSInfo `json:"ovsInfo,omitempty"` // OVS Information
NetworkPolicyControllerInfo v1beta1.NetworkPolicyControllerInfo `json:"networkPolicyControllerInfo,omitempty"` // Antrea Agent NetworkPolicy information
LocalPodNum int32 `json:"localPodNum,omitempty"` // The number of Pods which the agent is in charge of
Expand All @@ -53,7 +53,7 @@ func HandleFunc(aq querier.AgentQuerier) http.HandlerFunc {
NetworkPolicyControllerInfo: agentInfo.NetworkPolicyControllerInfo,
LocalPodNum: agentInfo.LocalPodNum,
AgentConditions: agentInfo.AgentConditions,
NodeSubnet: agentInfo.NodeSubnet,
NodeSubnets: agentInfo.NodeSubnets,
}
err := json.NewEncoder(w).Encode(info)
if err != nil {
Expand Down Expand Up @@ -89,7 +89,7 @@ func (r AntreaAgentInfoResponse) GetTableRow(maxColumnLength int) []string {
return []string{r.PodRef.Namespace + "/" + r.PodRef.Name,
r.NodeRef.Name,
r.GetAgentConditionStr(),
common.GenerateTableElementWithSummary(r.NodeSubnet, maxColumnLength),
common.GenerateTableElementWithSummary(r.NodeSubnets, maxColumnLength),
common.Int32ToString(r.NetworkPolicyControllerInfo.NetworkPolicyNum),
common.Int32ToString(r.NetworkPolicyControllerInfo.AddressGroupNum),
common.Int32ToString(r.NetworkPolicyControllerInfo.AppliedToGroupNum),
Expand Down
7 changes: 5 additions & 2 deletions pkg/agent/querier/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,15 @@ func (aq agentQuerier) GetAgentInfo(agentInfo *v1beta1.AntreaAgentInfo, partial
agentInfo.Version = querier.GetVersion()
agentInfo.PodRef = querier.GetSelfPod()
agentInfo.NodeRef = querier.GetSelfNode(true, aq.nodeConfig.Name)
// Make a new string slice instead of appending agentInfo.NodeSubnets directly to avoid duplicate CIDRs.
nodeSubnets := make([]string, 0)
if aq.nodeConfig.PodIPv4CIDR != nil {
agentInfo.NodeSubnet = append(agentInfo.NodeSubnet, aq.nodeConfig.PodIPv4CIDR.String())
nodeSubnets = append(nodeSubnets, aq.nodeConfig.PodIPv4CIDR.String())
}
if aq.nodeConfig.PodIPv6CIDR != nil {
agentInfo.NodeSubnet = append(agentInfo.NodeSubnet, aq.nodeConfig.PodIPv6CIDR.String())
nodeSubnets = append(nodeSubnets, aq.nodeConfig.PodIPv6CIDR.String())
}
agentInfo.NodeSubnets = nodeSubnets
agentInfo.OVSInfo.BridgeName = aq.nodeConfig.OVSBridge
agentInfo.APIPort = aq.apiPort
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/agent/querier/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func TestAgentQuerierGetAgentInfo(t *testing.T) {
apiPort: 10350,
partial: false,
expectedAgentInfo: &v1beta1.AntreaAgentInfo{
ObjectMeta: v1.ObjectMeta{Name: "foo"},
NodeRef: corev1.ObjectReference{Kind: "Node", Name: "foo"},
NodeSubnet: nil,
ObjectMeta: v1.ObjectMeta{Name: "foo"},
NodeRef: corev1.ObjectReference{Kind: "Node", Name: "foo"},
NodeSubnets: []string{},
OVSInfo: v1beta1.OVSInfo{
Version: ovsVersion,
BridgeName: "br-int",
Expand Down Expand Up @@ -129,9 +129,9 @@ func TestAgentQuerierGetAgentInfo(t *testing.T) {
apiPort: 10350,
partial: false,
expectedAgentInfo: &v1beta1.AntreaAgentInfo{
ObjectMeta: v1.ObjectMeta{Name: "foo"},
NodeRef: corev1.ObjectReference{Kind: "Node", Name: "foo"},
NodeSubnet: []string{"20.20.20.0/24", "2001:ab03:cd04:55ef::/64"},
ObjectMeta: v1.ObjectMeta{Name: "foo"},
NodeRef: corev1.ObjectReference{Kind: "Node", Name: "foo"},
NodeSubnets: []string{"20.20.20.0/24", "2001:ab03:cd04:55ef::/64"},
OVSInfo: v1beta1.OVSInfo{
Version: ovsVersion,
BridgeName: "br-int",
Expand Down
2 changes: 1 addition & 1 deletion pkg/antctl/command_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ kube-system/antrea-controller-55b9bcd59f-h9ll4 node-master Healthy 1
Kind: "Node",
Name: "node-worker",
},
NodeSubnet: []string{"192.168.1.0/24", "192.168.1.1/24"},
NodeSubnets: []string{"192.168.1.0/24", "192.168.1.1/24"},
OVSInfo: v1beta1.OVSInfo{
Version: "1.0",
BridgeName: "br-int",
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/clusterinformation/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type AntreaAgentInfo struct {
Version string `json:"version,omitempty"` // Antrea binary version
PodRef corev1.ObjectReference `json:"podRef,omitempty"` // The Pod that Antrea Agent is running in
NodeRef corev1.ObjectReference `json:"nodeRef,omitempty"` // The Node that Antrea Agent is running in
NodeSubnet []string `json:"nodeSubnet,omitempty"` // Node subnet
NodeSubnets []string `json:"nodeSubnets,omitempty"` // Node subnets
OVSInfo OVSInfo `json:"ovsInfo,omitempty"` // OVS Information
NetworkPolicyControllerInfo NetworkPolicyControllerInfo `json:"networkPolicyControllerInfo,omitempty"` // Antrea Agent NetworkPolicy information
LocalPodNum int32 `json:"localPodNum,omitempty"` // The number of Pods which the agent is in charge of
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/clusterinformation/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/apiserver/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/controller/querier/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewControllerQuerier(networkPolicyInfoQuerier querier.ControllerNetworkPoli
return &controllerQuerier{networkPolicyInfoQuerier: networkPolicyInfoQuerier, apiPort: apiPort}
}

// GetNodeSubnet gets current network policy info querier.
// getNetworkPolicyInfoQuerier gets current network policy info querier.
func (cq controllerQuerier) getNetworkPolicyInfoQuerier() querier.ControllerNetworkPolicyInfoQuerier {
return cq.networkPolicyInfoQuerier
}
Expand Down
10 changes: 5 additions & 5 deletions plugins/octant/cmd/antrea-octant-plugin/antrea_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (
nodeCol = "Node"
serviceCol = "Service"
clusterInfoCrdCol = "Monitoring CRD"
subnetCol = "NodeSubnet"
subnetsCol = "NodeSubnets"
bridgeCol = "OVS Bridge"
podNumCol = "Local Pod Num"
heartbeatCol = "Last Heartbeat Time"
Expand Down Expand Up @@ -101,14 +101,14 @@ func (p *antreaOctantPlugin) getAgentTable(request service.Request) *component.T
"/overview/namespace/"+agent.PodRef.Namespace+"/workloads/pods/"+agent.PodRef.Name),
nodeCol: component.NewLink(agent.NodeRef.Name, agent.NodeRef.Name,
"/cluster-overview/nodes/"+agent.NodeRef.Name),
subnetCol: component.NewText(strings.Join(agent.NodeSubnet, ", ")),
bridgeCol: component.NewText(agent.OVSInfo.BridgeName),
podNumCol: component.NewText(strconv.Itoa(int(agent.LocalPodNum))),
subnetsCol: component.NewText(strings.Join(agent.NodeSubnets, ", ")),
bridgeCol: component.NewText(agent.OVSInfo.BridgeName),
podNumCol: component.NewText(strconv.Itoa(int(agent.LocalPodNum))),
clusterInfoCrdCol: component.NewLink(agent.Name, agent.Name,
"/cluster-overview/custom-resources/antreaagentinfos.clusterinformation.antrea.tanzu.vmware.com/v1beta1/"+agent.Name),
heartbeatCol: component.NewText(agent.AgentConditions[0].LastHeartbeatTime.String()),
})
}
agentCols := component.NewTableCols(versionCol, podCol, nodeCol, subnetCol, bridgeCol, podNumCol, clusterInfoCrdCol, heartbeatCol)
agentCols := component.NewTableCols(versionCol, podCol, nodeCol, subnetsCol, bridgeCol, podNumCol, clusterInfoCrdCol, heartbeatCol)
return component.NewTableWithRows(agentTitle, "We couldn't find any Antrea agents!", agentCols, agentRows)
}

0 comments on commit 3a2ceca

Please sign in to comment.