agentleFS
Microsoft AzureKnown publisherAzure/azure-container-networking/cns/agents.md

azure-container-networking / cns

AGENTS.md433 starsChanged 59 days agoMITView on GitHub

This brief is for code contributors working on Container Networking Service (CNS) in this repo. In Azure CNI modes where pods receive routable VNET IPs, CNS tracks the goal state from the NodeNetworkConfig (NNC) CRD and only exposes IPs to pods once the Network Container (NC) is programmed by NMAgent. Legacy fallbacks (used when RequestIPConfigs/ReleaseIPConfigs are unsupported): - POST /network/requestipconfig — allocate a single IP. - POST /network/releaseipconfig — release a single IP.

The file

We split this agents.md into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Before changing CNS code, review and apply the relevant repo skills in .github/skills/.

    line 52

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
agents.md

CNS Agent Brief (AKS/Azure CNI)

This brief is for code contributors working on Container Networking Service (CNS) in this repo.

What CNS is

CNS is the container networking daemon running on every AKS node for Azure CNI. It bridges the AKS control plane and node dataplane by managing pod IP allocation state and coordinating with the Azure networking control plane for routable VNET IPs.

In Azure CNI modes where pods receive routable VNET IPs, CNS tracks the goal state from the NodeNetworkConfig (NNC) CRD and only exposes IPs to pods once the Network Container (NC) is programmed by NMAgent.

Core architecture (high level)

  • HTTP REST API used by CNI/azure-ipam for IP assignment and release.
  • Controller-runtime reconcilers that watch NNCs (and SwiftV2 CRDs) and reconcile desired NC/IP state.
  • IPAM pool monitor (dynamic IP scenarios) to resize IP pools on demand. Not used in fixed-prefix modes (e.g., overlay).
  • IMDS/wireserver integration to query NMAgent NC status.

Core flow (node → pod IP assignment)

  1. DNC/RC creates a NodeNetworkConfig (NNC) for the node.
  2. DNC allocates IPs as Network Containers (NCs) and publishes them to the fabric.
  3. NMAgent programs the NC; CNS watches for NC version readiness via IMDS/wireserver.
  4. CNS ingests NNC as goal state; once NC is ready, IPs become Available.
  5. CNI/azure-ipam calls CNS to RequestIPConfigs/ReleaseIPConfigs during pod lifecycle.
  6. CNS acts as the IPAM store for pod IP allocation and release.

Primary CNS APIs used by AKS

Primary (current) IPAM APIs:

  • POST /network/requestipconfigs — allocate one or more IPs for a pod.
  • POST /network/releaseipconfigs — release IPs for a pod.

Legacy fallbacks (used when RequestIPConfigs/ReleaseIPConfigs are unsupported):

  • POST /network/requestipconfig — allocate a single IP.
  • POST /network/releaseipconfig — release a single IP.

Configuration inputs

  • CNS is configured via JSON config file (cns_config.json) provided via ConfigMap in AKS.
  • Config file path can be set by CNS_CONFIGURATION_PATH env var or command-line flag.
  • Environment variables used by CNS (examples): NODENAME, NODE_IP, POD_CIDRs, SERVICE_CIDRs, INFRA_VNET_CIDRs.
  • There are legacy flags and env vars in main; treat configuration as scenario-specific and static.

State persistence

CNS writes persistent state to disk:

  • Main CNS state: /var/lib/azure-network/azure-cns.json (Linux default). Stores NCs, networks, orchestrator data, timestamps, etc.
  • Endpoint state (ManageEndpointState=true): /var/run/azure-cns/azure-endpoints.json on Linux, /k/azurecns/azure-endpoints.json on Windows. Stores containerID → endpoint IP mappings. Critical state for IPAM - any issues can leak IPs.
  • CNI state file used for migration: /var/run/azure-vnet.json (Linux default).

Code entry points (start here)

  • Service entry: cns/service/main.go
  • REST API handlers: cns/restserver/
  • Reconcilers: cns/kubecontroller/
  • IPAM pool monitor: cns/ipampool/

Required repo skills

Before changing CNS code, review and apply the relevant repo skills in .github/skills/; this is required for CNS work, not optional. Choose by surface area and combine them when a change crosses concerns:

  • REST/IPAM handlers in cns/restserver/: acn-go-http-api-contracts; also apply acn-go-types-parsing for IP/prefix payloads and other network-typed inputs.
  • Reconcilers, NNC/SwiftV2 flows, response codes, or persisted/observed state: acn-go-control-plane-contracts, with acn-go-design-boundaries and acn-go-interfaces-dependencies when shaping behavior or dependency seams.
  • main, startup, pool monitors, background goroutines, long-lived loops, or shutdown: acn-go-context-lifecycle.
  • Linux/Windows divergence, build tags, or OS-specific paths/state: acn-go-platform-abstraction.
  • Any change to error strings, zap logs, or operational observability: acn-go-errors-logging.

Tests to run for CNS changes

  • Tests in the packages above (restserver, kubecontroller, ipampool, service) are the first-line regression checks.

Critical caution areas

CNS initialization and state management are high-risk code paths. Behavioral changes can cause large-scale impact. Keep changes minimal and validate thoroughly.

SwiftV2 note

SwiftV2 adds multitenancy and multi-NIC behaviors. Treat SwiftV2-only APIs/CRDs as specialized paths; verify scenario-specific behavior when touching related code.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.