-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize package organization to reduce antctl binary size (#6037)
As a client, antctl needs to know some well-known resource names and the structs of the API responses. However, the code placement makes antctl import a lot of packages which are supposed to be consumed by server side code, e.g. antrea-controller, antrea-agent. This patch refactors relevant packages, extracts well-known resources names and API structs to separate common packages, mostly apis packages. It reduces antctl binary size by 10MB, from 55MB to 45MB. The placement also makes it more explicit that these constants and structs are API related and should be changed more carefully. The major changes are as follows: 1. Move well-known CRD resource names to types.go files which declare these CRD structs. 2. Move other well-known resource names to package pkg/apis. 3. Move structs of API responses to package apis of components which provide the corresponding APIs. Signed-off-by: Quan Tian <[email protected]>
- Loading branch information
Showing
83 changed files
with
864 additions
and
721 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2024 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 apis contains API definitions used to interface with antrea-agent. | ||
package apis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
// Copyright 2024 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 apis | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
|
||
"antrea.io/antrea/pkg/apis/crd/v1beta1" | ||
"antrea.io/antrea/pkg/util/printers" | ||
) | ||
|
||
// AntreaAgentInfoResponse is the struct for the response of agentinfo command. | ||
// It includes all fields except meta info from v1beta1.AntreaAgentInfo struct. | ||
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 | ||
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 | ||
AgentConditions []v1beta1.AgentCondition `json:"agentConditions,omitempty"` // Agent condition contains types like AgentHealthy | ||
} | ||
|
||
func (r AntreaAgentInfoResponse) GetTableHeader() []string { | ||
return []string{"POD", "NODE", "STATUS", "NODE-SUBNET", "NETWORK-POLICIES", "ADDRESS-GROUPS", "APPLIED-TO-GROUPS", "LOCAL-PODS"} | ||
} | ||
|
||
func (r AntreaAgentInfoResponse) getAgentConditionStr() string { | ||
if r.AgentConditions == nil { | ||
return "" | ||
} | ||
agentCondition := "Healthy" | ||
for _, cond := range r.AgentConditions { | ||
if cond.Status == corev1.ConditionUnknown { | ||
agentCondition = "Unknown" | ||
} | ||
if cond.Status == corev1.ConditionFalse { | ||
return "Unhealthy" | ||
} | ||
} | ||
return agentCondition | ||
} | ||
|
||
func (r AntreaAgentInfoResponse) GetTableRow(maxColumnLength int) []string { | ||
return []string{r.PodRef.Namespace + "/" + r.PodRef.Name, | ||
r.NodeRef.Name, | ||
r.getAgentConditionStr(), | ||
printers.GenerateTableElementWithSummary(r.NodeSubnets, maxColumnLength), | ||
strconv.Itoa(int(r.NetworkPolicyControllerInfo.NetworkPolicyNum)), | ||
strconv.Itoa(int(r.NetworkPolicyControllerInfo.AddressGroupNum)), | ||
strconv.Itoa(int(r.NetworkPolicyControllerInfo.AppliedToGroupNum)), | ||
strconv.Itoa(int(r.LocalPodNum))} | ||
} | ||
|
||
func (r AntreaAgentInfoResponse) SortRows() bool { | ||
return true | ||
} | ||
|
||
type FeatureGateResponse struct { | ||
Component string `json:"component,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
Status string `json:"status,omitempty"` | ||
Version string `json:"version,omitempty"` | ||
} | ||
|
||
// MemberlistResponse describes the response struct of memberlist command. | ||
type MemberlistResponse struct { | ||
NodeName string `json:"nodeName,omitempty"` | ||
IP string `json:"ip,omitempty"` | ||
Status string `json:"status,omitempty"` | ||
} | ||
|
||
func (r MemberlistResponse) GetTableHeader() []string { | ||
return []string{"NODE", "IP", "STATUS"} | ||
} | ||
|
||
func (r MemberlistResponse) GetTableRow(_ int) []string { | ||
return []string{r.NodeName, r.IP, r.Status} | ||
} | ||
|
||
func (r MemberlistResponse) SortRows() bool { | ||
return true | ||
} | ||
|
||
type MulticastResponse struct { | ||
PodName string `json:"name,omitempty" antctl:"name,Name of the Pod"` | ||
PodNamespace string `json:"podNamespace,omitempty"` | ||
Inbound string `json:"inbound,omitempty"` | ||
Outbound string `json:"outbound,omitempty"` | ||
} | ||
|
||
func (r MulticastResponse) GetTableHeader() []string { | ||
return []string{"NAMESPACE", "NAME", "INBOUND", "OUTBOUND"} | ||
} | ||
|
||
func (r MulticastResponse) GetTableRow(_ int) []string { | ||
return []string{r.PodNamespace, r.PodName, r.Inbound, r.Outbound} | ||
} | ||
|
||
func (r MulticastResponse) SortRows() bool { | ||
return true | ||
} | ||
|
||
// OVSFlowResponse is the response struct of ovsflows command. | ||
type OVSFlowResponse struct { | ||
Flow string `json:"flow,omitempty"` | ||
} | ||
|
||
func (r OVSFlowResponse) GetTableHeader() []string { | ||
return []string{""} | ||
} | ||
|
||
func (r OVSFlowResponse) GetTableRow(maxColumnLength int) []string { | ||
return []string{r.Flow} | ||
} | ||
|
||
func (r OVSFlowResponse) SortRows() bool { | ||
return false | ||
} | ||
|
||
// OVSTracingResponse is the response struct of ovstracing command. | ||
type OVSTracingResponse struct { | ||
Result string `json:"result,omitempty"` | ||
} | ||
|
||
// PodInterfaceResponse describes the response struct of pod-interface command. | ||
type PodInterfaceResponse struct { | ||
PodName string `json:"name,omitempty" antctl:"name,Name of the Pod"` | ||
PodNamespace string `json:"podNamespace,omitempty"` | ||
InterfaceName string `json:"interfaceName,omitempty"` | ||
IPs []string `json:"ips,omitempty"` | ||
MAC string `json:"mac,omitempty"` | ||
PortUUID string `json:"portUUID,omitempty"` | ||
OFPort int32 `json:"ofPort,omitempty"` | ||
ContainerID string `json:"containerID,omitempty"` | ||
} | ||
|
||
func (r PodInterfaceResponse) GetTableHeader() []string { | ||
return []string{"NAMESPACE", "NAME", "INTERFACE-NAME", "IP", "MAC", "PORT-UUID", "OF-PORT", "CONTAINER-ID"} | ||
} | ||
|
||
func (r PodInterfaceResponse) getContainerIDStr() string { | ||
if len(r.ContainerID) > 12 { | ||
return r.ContainerID[0:11] | ||
} | ||
return r.ContainerID | ||
} | ||
|
||
func (r PodInterfaceResponse) GetTableRow(_ int) []string { | ||
return []string{r.PodNamespace, r.PodName, r.InterfaceName, strings.Join(r.IPs, ", "), r.MAC, r.PortUUID, strconv.Itoa(int(r.OFPort)), r.getContainerIDStr()} | ||
} | ||
|
||
func (r PodInterfaceResponse) SortRows() bool { | ||
return true | ||
} | ||
|
||
// 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"` | ||
} | ||
|
||
func (r ServiceExternalIPInfo) GetTableHeader() []string { | ||
return []string{"NAMESPACE", "NAME", "EXTERNAL-IP-POOL", "EXTERNAL-IP", "ASSIGNED-NODE"} | ||
} | ||
|
||
func (r ServiceExternalIPInfo) GetTableRow(_ int) []string { | ||
return []string{r.Namespace, r.ServiceName, r.ExternalIPPool, r.ExternalIP, r.AssignedNode} | ||
} | ||
|
||
func (r ServiceExternalIPInfo) SortRows() bool { | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.