Skip to content

Conversation

@aritrbas
Copy link
Collaborator

@aritrbas aritrbas commented Nov 5, 2025


Overview

The network hook system has been refactored from a bash script to a two-tier architecture:

  1. Native Go hooks (primary) - Always run, handle network configuration
  2. Optional user scripts (secondary) - Run after Go hooks, allow custom extensions

Note: Some specialized environments (like EKS and OpenShift) may still need custom scripts for specific network configurations.


Execution Flow

At each hook point:

1. Native Go NetworkManagerHook executes
   ├─ System detection (first time only)
   ├─ DNS configuration (if NetworkManager)
   ├─ Network service restart (if needed)
   └─ AWS network file handling (if AWS)

2. User-provided script executes (if configured)
   └─ Custom logic from CALICOVPP_HOOK_* env var

Hook Points

There are 5 hook points:

Hook Point When Native Go Actions User Script Env Var
BEFORE_IF_READ Early init No-op CALICOVPP_HOOK_BEFORE_IF_READ
BEFORE_VPP_RUN Before VPP starts Fix DNS, save configs CALICOVPP_HOOK_BEFORE_VPP_RUN
VPP_RUNNING After VPP starts Restart network, tweak configs CALICOVPP_HOOK_VPP_RUNNING
VPP_DONE_OK VPP stops (success) Undo DNS, restore configs, restart network CALICOVPP_HOOK_VPP_DONE_OK
VPP_ERRORED VPP stops (error) Undo DNS, restore configs, restart network CALICOVPP_HOOK_VPP_ERRORED

Optional User Hook Scripts

All default to empty (no scripts by default):

CALICOVPP_HOOK_BEFORE_IF_READ=""   # Run before interface read
CALICOVPP_HOOK_BEFORE_VPP_RUN=""   # Run before VPP starts  
CALICOVPP_HOOK_VPP_RUNNING=""      # Run after VPP starts
CALICOVPP_HOOK_VPP_DONE_OK=""      # Run when VPP stops normally
CALICOVPP_HOOK_VPP_ERRORED=""      # Run when VPP errors

To add custom logic, set the env var:

# Example: On OpenShift platform
export CALICOVPP_HOOK_VPP_RUNNING='echo \'systemctl restart NetworkManager; sleep 5; nmcli con mod ens5 ipv4.dhcp-timeout infinity\' | chroot /host'
# Example: On EKS platform
export CALICOVPP_HOOK_VPP_DONE_OK='echo \'sudo rm /etc/systemd/network/ens5.network; systemctl daemon-reload; sudo systemctl restart systemd-networkd\' | chroot /host'

Native Go Hooks

The NetworkManagerHook Go module automatically handles:

1. System Detection

  • Detects: systemd, systemd-networkd, NetworkManager, other network services
  • Detects: AWS EC2 environment (via dmidecode)
  • Runs once on initialization and logs the detected configuration

2. DNS Management (NetworkManager)

  • Adds dns=none to /etc/NetworkManager/NetworkManager.conf before VPP starts in BEFORE_VPP_RUN
  • Removes it when VPP stops in VPP_DONE_OK/VPP_ERRORED
  • Prevents NetworkManager's DNS management from interfering with VPP

3. Network Service Restart

  • Automatically restarts the detected network service after VPP starts (VPP_RUNNING) and after VPP stops (VPP_DONE_OK/VPP_ERRORED)

4. AWS Network File Handling

  • Handles systemd-networkd configuration for dynamic IP interfaces that become unmanaged on AWS EC2 instances
  • Saves original /etc/systemd/network/*.network file before VPP starts in BEFORE_VPP_RUN
  • Fixes interfaces that become unmanaged while VPP runs in VPP_RUNNING
  • Removes tweaked file and restores original configuration when VPP stops in VPP_DONE_OK/VPP_ERRORED

@aritrbas aritrbas self-assigned this Nov 5, 2025
@aritrbas aritrbas marked this pull request as draft November 5, 2025 06:56
@aritrbas aritrbas marked this pull request as ready for review November 5, 2025 17:51
@aritrbas aritrbas requested review from onong and sknat November 5, 2025 17:54
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.

1 participant