diff --git a/cmd/antrea-agent/agent.go b/cmd/antrea-agent/agent.go index 755215ecd9f..b55a0612a3a 100644 --- a/cmd/antrea-agent/agent.go +++ b/cmd/antrea-agent/agent.go @@ -750,7 +750,9 @@ func run(o *Options) error { ovsBridgeClient, proxier, networkPolicyController, - o.config.APIPort) + o.config.APIPort, + o.config.NodePortLocal.PortRange, + ) agentMonitor := monitor.NewAgentMonitor(crdClient, agentQuerier) diff --git a/pkg/agent/querier/querier.go b/pkg/agent/querier/querier.go index 9ad97ca6b02..219438d2e54 100644 --- a/pkg/agent/querier/querier.go +++ b/pkg/agent/querier/querier.go @@ -54,6 +54,7 @@ type agentQuerier struct { proxier proxy.Proxier networkPolicyInfoQuerier querier.AgentNetworkPolicyInfoQuerier apiPort int + nplRange string } func NewAgentQuerier( @@ -66,6 +67,7 @@ func NewAgentQuerier( proxier proxy.Proxier, networkPolicyInfoQuerier querier.AgentNetworkPolicyInfoQuerier, apiPort int, + nplRange string, ) *agentQuerier { return &agentQuerier{ nodeConfig: nodeConfig, @@ -76,7 +78,9 @@ func NewAgentQuerier( ovsBridgeClient: ovsBridgeClient, proxier: proxier, networkPolicyInfoQuerier: networkPolicyInfoQuerier, - apiPort: apiPort} + apiPort: apiPort, + nplRange: nplRange, + } } // GetNodeConfig returns NodeConfig. @@ -205,7 +209,7 @@ func (aq agentQuerier) GetAgentInfo(agentInfo *v1beta1.AntreaAgentInfo, partial } agentInfo.AgentConditions = aq.getAgentConditions(ovsConnected) - // Some other fields are needed when partial if false. + // Some other fields are needed when partial is false. if !partial { agentInfo.Version = querier.GetVersion() agentInfo.PodRef = querier.GetSelfPod() @@ -221,5 +225,6 @@ func (aq agentQuerier) GetAgentInfo(agentInfo *v1beta1.AntreaAgentInfo, partial agentInfo.NodeSubnets = nodeSubnets agentInfo.OVSInfo.BridgeName = aq.nodeConfig.OVSBridge agentInfo.APIPort = aq.apiPort + agentInfo.NodePortLocalPortRange = aq.nplRange } } diff --git a/pkg/agent/querier/querier_test.go b/pkg/agent/querier/querier_test.go index fa17f9c5ec8..bd4fffc0955 100644 --- a/pkg/agent/querier/querier_test.go +++ b/pkg/agent/querier/querier_test.go @@ -32,7 +32,10 @@ import ( queriertest "antrea.io/antrea/pkg/querier/testing" ) -const ovsVersion = "2.10.0" +const ( + ovsVersion = "2.10.0" + defaultNPLPortRange = "61000-62001" +) func getIPNet(ip string) *net.IPNet { _, ipNet, _ := net.ParseCIDR(ip) @@ -114,8 +117,9 @@ func TestAgentQuerierGetAgentInfo(t *testing.T) { Status: corev1.ConditionTrue, }, }, - APIPort: 10350, - Version: "UNKNOWN", + APIPort: 10350, + NodePortLocalPortRange: defaultNPLPortRange, + Version: "UNKNOWN", }, }, { @@ -162,8 +166,9 @@ func TestAgentQuerierGetAgentInfo(t *testing.T) { Status: corev1.ConditionTrue, }, }, - APIPort: 10350, - Version: "UNKNOWN", + APIPort: 10350, + NodePortLocalPortRange: defaultNPLPortRange, + Version: "UNKNOWN", }, }, } @@ -176,6 +181,7 @@ func TestAgentQuerierGetAgentInfo(t *testing.T) { ovsBridgeClient: ovsBridgeClient, networkPolicyInfoQuerier: networkPolicyInfoQuerier, apiPort: tt.apiPort, + nplRange: defaultNPLPortRange, } agentInfo := &v1beta1.AntreaAgentInfo{} aq.GetAgentInfo(agentInfo, tt.partial) diff --git a/pkg/apis/crd/v1beta1/types.go b/pkg/apis/crd/v1beta1/types.go index 6c4250f8a2b..abec401fbc1 100644 --- a/pkg/apis/crd/v1beta1/types.go +++ b/pkg/apis/crd/v1beta1/types.go @@ -44,6 +44,8 @@ type AntreaAgentInfo struct { AgentConditions []AgentCondition `json:"agentConditions,omitempty"` // The port of antrea agent API Server APIPort int `json:"apiPort,omitempty"` + // The port range used by NodePortLocal + NodePortLocalPortRange string `json:"nodePortLocalPortRange,omitempty"` } type OVSInfo struct { diff --git a/pkg/apiserver/openapi/zz_generated.openapi.go b/pkg/apiserver/openapi/zz_generated.openapi.go index c39bd1b942b..2661ea4ba76 100644 --- a/pkg/apiserver/openapi/zz_generated.openapi.go +++ b/pkg/apiserver/openapi/zz_generated.openapi.go @@ -2479,6 +2479,13 @@ func schema_pkg_apis_crd_v1beta1_AntreaAgentInfo(ref common.ReferenceCallback) c Format: "int32", }, }, + "nodePortLocalPortRange": { + SchemaProps: spec.SchemaProps{ + Description: "The port range used by NodePortLocal", + Type: []string{"string"}, + Format: "", + }, + }, }, }, },