Skip to content

Conversation

@hongliangl
Copy link
Contributor

@hongliangl hongliangl commented Dec 26, 2025

Introduce a new antrea-sysctl-init command to run as an init container
before Antrea components start. The command creates a dedicated sysctl.d
configuration file containing Antrea-specific sysctl settings required
by features that rely on policy routing (e.g. Egress).

The sysctl configuration applies only to the interfaces managed by
Antrea. A relatively high filename prefix is used so that the Antrea-
specific sysctl configuration is applied after most default distribution-
or administrator-provided sysctl configuration files, while still allowing
explicit higher-priority overrides when desired.

This logic is intentionally implemented as an init container rather than
as part of antrea-agent, to avoid modifying node-wide sysctl state during
normal agent operation.

@hongliangl hongliangl force-pushed the 20251224-add-sysctl-init-container branch from 7297d7b to b3c26f0 Compare December 26, 2025 04:48
@hongliangl hongliangl force-pushed the 20251224-add-sysctl-init-container branch 4 times, most recently from 123ed07 to 2326ffd Compare December 29, 2025 03:16
@hongliangl hongliangl marked this pull request as ready for review December 29, 2025 03:29
@hongliangl hongliangl force-pushed the 20251224-add-sysctl-init-container branch 2 times, most recently from 6377498 to e89dd82 Compare December 29, 2025 06:27
# -- Resource requests and limits for the antrea-sysctl-init init container.
resources:
requests:
cpu: "100m"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too much for placing a file in the folder. Maybe 20m is enough if we'd like to define it. Or just remove this from the manifest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think removing this is just okay.

Copy link
Contributor Author

@hongliangl hongliangl Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe 100m is harmless. It seems that 100m is a convention.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even it's harmless, it would make more sense to give it a reasonable value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

50m seems to be a good choice for future using.

@hongliangl hongliangl force-pushed the 20251224-add-sysctl-init-container branch from e89dd82 to adaadf7 Compare December 29, 2025 11:06

func run(opts *options) error {
filePath := path.Join(opts.sysctlDir, opts.overwriteFile)
sysctlConfig := buildAntreaSysctlConfig(opts.hostGatewayName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some OS releases, restart is not required. For Ubuntu, we need a test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cases are:

  • On some OS distributions, adding a new file under /etc/sysctl.d is sufficient to ensure that sysctl settings are automatically re-applied to existing network interfaces when an interface is added or updated. In these environments, the newly added interface also receives theenforced settings.
  • On Ubuntu, sysctl configuration files under /etc/sysctl.d are not automatically re-applied when network interfaces are added or updated. New interfaces inherit values from net.ipv4.conf.default, while existing interfaces retain their current settings unless sysctl is explicitly reloaded.
  • Executing the command sysctl --system on all tested OS distributions explicitly applies sysctl configuration files under /etc/sysctl.d to all existing network interfaces, regardless of distribution-specific behavior.

# The filename is chosen to sort last in lexicographic order within the sysctl
# configuration directory, so that the settings in this file are applied after other
# distribution- or administrator- provided sysctl configuration files.
overwriteFile: "99-zzzz-antrea.conf"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not seeing there is any need to let user to define this. Better to keep the name as a constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd better keep the parameter. A corner case is that there is an existing file named 99-zzzzzzzz-xxxx.conf. If that really happens, at least we have a chance to modify our file name so that it can be last in lexicographical order.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not modifying sysctl settings for interfaces that are not managed by Antrea, correct? If so, it should be fine that this configuration file is not applied last.

If there is another sysctl configuration overriding Antrea’s settings with 99-zzzzzzz.conf, that is presumably intentional. In that case, rather than continually increasing the filename priority by appending more “z”s, it would make more sense to first understand the purpose of the overriding configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not modifying sysctl settings for interfaces that are not managed by Antrea, correct? If so, it should be fine that this configuration file is not applied last.

Will update the comment to state that a relatively high filename prefix is used to ensure the file will be applied after most default distribution- or administrator-provided sysctl configuration files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment already explains it. My point is that it seems unnecessary to make it configurable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the parameter.

# -- Resource requests and limits for the antrea-sysctl-init init container.
resources:
requests:
cpu: "100m"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even it's harmless, it would make more sense to give it a reasonable value.

# The filename is chosen to sort last in lexicographic order within the sysctl
# configuration directory, so that the settings in this file are applied after other
# distribution- or administrator- provided sysctl configuration files.
overwriteFile: "99-zzzz-antrea.conf"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not modifying sysctl settings for interfaces that are not managed by Antrea, correct? If so, it should be fine that this configuration file is not applied last.

If there is another sysctl configuration overriding Antrea’s settings with 99-zzzzzzz.conf, that is presumably intentional. In that case, rather than continually increasing the filename priority by appending more “z”s, it would make more sense to first understand the purpose of the overriding configuration.

@hongliangl hongliangl force-pushed the 20251224-add-sysctl-init-container branch 2 times, most recently from 857ea44 to 61ce01c Compare December 30, 2025 14:47
@hongliangl hongliangl changed the title Add init container to create sysctl rp_filter overwrite config on Node Add init container to apply Antrea-specific sysctl configuration Dec 30, 2025
@hongliangl hongliangl force-pushed the 20251224-add-sysctl-init-container branch 2 times, most recently from 0ff3bd6 to a64f469 Compare December 30, 2025 15:04
kubeletRootDir: "/var/lib/kubelet"
antreaSysctlInit:
# -- Enable the sysctl override. When enabled, the init container will do the process.
enable: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it enabled by default intentionally? I thought it's only needed on some platforms?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's indeed only needed on some OS releases, and is redundant for others. I thought it is generally harmless to enable it by default. An alternative is to keep it disabled by default and clearly document when and why it should be enabled. Any ideas where should we document that?

@hongliangl hongliangl force-pushed the 20251224-add-sysctl-init-container branch from a64f469 to 33a45ce Compare December 30, 2025 23:11
@luolanzone
Copy link
Contributor

cc @hangyan @xliuxu for awareness of manifest changes and the new binary

@hongliangl hongliangl force-pushed the 20251224-add-sysctl-init-container branch from 33a45ce to 256e051 Compare December 31, 2025 03:18
@hongliangl
Copy link
Contributor Author

/test-all

@hongliangl
Copy link
Contributor Author

/scale-agent

@hongliangl hongliangl force-pushed the 20251224-add-sysctl-init-container branch from 256e051 to d1c4207 Compare December 31, 2025 05:05
@hongliangl
Copy link
Contributor Author

/test-all
/scale-agent

Introduce a new antrea-sysctl-init command to run as an init container
before Antrea components start. The command creates a dedicated sysctl.d
configuration file containing Antrea-specific sysctl settings required
by features that rely on policy routing (e.g. Egress).

The sysctl configuration applies only to the interfaces managed by
Antrea. A relatively high filename prefix is used so that the Antrea-
specific sysctl configuration is applied after most default distribution-
or administrator-provided sysctl configuration files, while still allowing
explicit higher-priority overrides when desired.

This logic is intentionally implemented as an init container rather than
as part of antrea-agent, to avoid modifying node-wide sysctl state during
normal agent operation.

Signed-off-by: Hongliang Liu <[email protected]>
Signed-off-by: Hongliang Liu <[email protected]>
@hongliangl hongliangl force-pushed the 20251224-add-sysctl-init-container branch from d1c4207 to 7933864 Compare December 31, 2025 06:14
@hongliangl
Copy link
Contributor Author

/test-all
/scale-agent

@hongliangl
Copy link
Contributor Author

/test-all

@hongliangl
Copy link
Contributor Author

/test-e2e

1 similar comment
@hongliangl
Copy link
Contributor Author

/test-e2e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants