Skip to content

Commit

Permalink
NPL code tidy-up for Antrea v2.0
Browse files Browse the repository at this point in the history
Signed-off-by: Lan Luo <luola@vmware.com>
  • Loading branch information
luolanzone committed Jan 30, 2024
1 parent 5135e06 commit 6aa01a2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 29 deletions.
7 changes: 1 addition & 6 deletions cmd/antrea-agent/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,7 @@ func (o *Options) setK8sNodeDefaultOptions() {
}

if o.config.NodePortLocal.Enable {
switch {
case o.config.NodePortLocal.PortRange != "":
case o.config.NPLPortRange != "":
klog.InfoS("The nplPortRange option is deprecated, please use nodePortLocal.portRange instead")
o.config.NodePortLocal.PortRange = o.config.NPLPortRange
default:
if o.config.NodePortLocal.PortRange == "" {
o.config.NodePortLocal.PortRange = defaultNPLPortRange
}
}
Expand Down
12 changes: 7 additions & 5 deletions docs/node-port-local.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ From Antrea v1.14, NPL is GA.
In addition to enabling the NodePortLocal feature gate (if needed), you need to
ensure that the `nodePortLocal.enable` flag is set to true in the Antrea Agent
configuration. The `nodePortLocal.portRange` parameter can also be set to change
the range from which Node ports will be allocated. Otherwise, the default range
of `61000-62000` will be used by default. When using the NodePortLocal feature,
your `antrea-agent` ConfigMap should look like this:
the range from which Node ports will be allocated. Otherwise, the range
of `61000-62000` will be used by default on Linux, and the range `40000-41000` will
be used on Windows. When using the NodePortLocal feature, your `antrea-agent` ConfigMap
should look like this:

```yaml
kind: ConfigMap
Expand Down Expand Up @@ -116,7 +117,7 @@ metadata:
labels:
app: nginx
annotations:
nodeportlocal.antrea.io: '[{"podPort":8080,"nodeIP":"10.10.10.10","nodePort":61002,"protocol":"tcp","protocols":["tcp"]}]'
nodeportlocal.antrea.io: '[{"podPort":8080,"nodeIP":"10.10.10.10","nodePort":61002,"protocol":"tcp"}]'
```

This annotation indicates that port 8080 of the Pod can be reached through port
Expand All @@ -137,6 +138,7 @@ annotation is deprecated. The array contains a single member, equal to the
`protocol` field.
The `protocols` field will be removed from Antrea for minor releases post March 2023,
as per our deprecation policy.
Starting from Antrea v2.0, the `protocols` field is removed.

### Usage pre Antrea v1.7

Expand Down Expand Up @@ -168,7 +170,7 @@ for a given podPort, and the allocated nodePort may be different for each one.
Prior to the Antrea v1.4 minor release, the `nodePortLocal` option group in the
Antrea Agent configuration did not exist. To enable the NodePortLocal feature,
one simply needed to enable the feature gate, and the port range could be
configured using the (now deprecated) `nplPortRange` parameter.
configured using the (now removed) `nplPortRange` parameter.

### Usage pre Antrea v1.2

Expand Down
18 changes: 8 additions & 10 deletions pkg/agent/nodeportlocal/k8s/npl_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,10 @@ func (c *NPLController) handleAddUpdatePod(key string, obj interface{}) error {
}
if _, ok := nplAnnotationsRequiredMap[portcache.NodePortProtoFormat(nodePort, protocol)]; !ok {
nplAnnotationsRequiredMap[portcache.NodePortProtoFormat(nodePort, protocol)] = types.NPLAnnotation{
PodPort: port,
NodeIP: pod.Status.HostIP,
NodePort: nodePort,
Protocol: protocol,
Protocols: []string{protocol},
PodPort: port,
NodeIP: pod.Status.HostIP,
NodePort: nodePort,
Protocol: protocol,
}
}
}
Expand Down Expand Up @@ -598,11 +597,10 @@ func (c *NPLController) waitForRulesInitialization() {
continue
}
allNPLPorts = append(allNPLPorts, rules.PodNodePort{
NodePort: npl.NodePort,
PodPort: npl.PodPort,
PodIP: pod.Status.PodIP,
Protocol: npl.Protocol,
Protocols: npl.Protocols,
NodePort: npl.NodePort,
PodPort: npl.PodPort,
PodIP: pod.Status.PodIP,
Protocol: npl.Protocol,
})
}
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/agent/nodeportlocal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ const (

// NPLAnnotation is the structure used for setting NodePortLocal annotation on the Pods.
type NPLAnnotation struct {
PodPort int `json:"podPort"`
NodeIP string `json:"nodeIP"`
NodePort int `json:"nodePort"`
Protocol string `json:"protocol"`
Protocols []string `json:"protocols"` // deprecated, array with a single member which is equal to the Protocol field
PodPort int `json:"podPort"`
NodeIP string `json:"nodeIP"`
NodePort int `json:"nodePort"`
Protocol string `json:"protocol"`
}
2 changes: 0 additions & 2 deletions pkg/config/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ type AgentConfig struct {
ActiveFlowExportTimeout string `yaml:"activeFlowExportTimeout,omitempty"`
// Deprecated. Use the FlowExporter config options instead.
IdleFlowExportTimeout string `yaml:"idleFlowExportTimeout,omitempty"`
// Deprecated. Use the NodePortLocal config options instead.
NPLPortRange string `yaml:"nplPortRange,omitempty"`
// NodePortLocal (NPL) configuration options.
NodePortLocal NodePortLocalConfig `yaml:"nodePortLocal,omitempty"`
// FlowExporter configuration options.
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/nodeportlocal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ func testNPLMultiplePodsAgentRestart(t *testing.T, data *TestData) {

// testNPLChangePortRangeAgentRestart tests NodePortLocal functionalities after changing port range.
// - Create multiple Nginx Pods.
// - Change nplPortRange.
// - Change the PortRange.
// - Restart Antrea Agent Pods.
// - Verify that updated port range is being used for NPL.
func testNPLChangePortRangeAgentRestart(t *testing.T, data *TestData) {
Expand Down

0 comments on commit 6aa01a2

Please sign in to comment.