hashicorp/nomad · error
cni not initialized: %w
Error message
cni not initialized: %w
What it means
cniNetworkConfigurator.Setup lazily initializes the CNI library handle (go-cni). ensureCNIInitialized returns an error if the CNI instance was never initialized (or init failed), and Setup wraps it with 'cni not initialized'. This guards against calling CNI add on an unusable configurator.
Source
Thrown at client/allocrunner/networking_cni.go:154
}
}
}
var supportsCNICheck = mustCNICheckConstraint()
func mustCNICheckConstraint() version.Constraints {
v, err := version.NewConstraint(">= 1.3.0")
if err != nil {
panic(err)
}
return v
}
// Setup calls the CNI plugins with the add action
func (c *cniNetworkConfigurator) Setup(ctx context.Context, alloc *structs.Allocation, spec *drivers.NetworkIsolationSpec, created bool) (*structs.AllocNetworkStatus, error) {
if err := c.ensureCNIInitialized(); err != nil {
return nil, fmt.Errorf("cni not initialized: %w", err)
}
cniArgs := map[string]string{
// CNI plugins are called one after the other with the same set of
// arguments. Passing IgnoreUnknown=true signals to plugins that they
// should ignore any arguments they don't understand
"IgnoreUnknown": "true",
}
tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
addCustomCNIArgs(tg.Networks, cniArgs)
// Add NOMAD_* after custom args so it cannot be overridden.
addNomadWorkloadCNIArgs(c.logger, alloc, cniArgs)
portMaps := getPortMapping(alloc, c.ignorePortMappingHostIP)
tproxyArgs, err := c.setupTransparentProxyArgs(alloc, spec, portMaps)View on GitHub (pinned to 482b49bf1a)
Solutions
- Install the required CNI plugin binaries into the configured cni_plugin_dir (default /opt/cni/bin).
- Ensure a valid CNI config exists (see 'failed to load CNI config') so lazy init can build the plugin chain.
- Check the wrapped cause in the log to distinguish init-not-called vs init-failed.
- Restart the client after fixing plugin path/config so the configurator re-initializes.
Example fix
# before $ ls /opt/cni/bin ls: cannot access '/opt/cni/bin': No such file or directory # after $ sudo wget -qO- https://github.com/containernetworking/plugins/releases/download/v1.3.0/cni-plugins-linux-amd64-v1.3.0.tgz | sudo tar -C /opt/cni/bin -xz
Defensive patterns
Strategy: fallback
Validate before calling
// verify plugins before client start for p in bridge loopback firewall portmap; do [ -x "/opt/cni/bin/$p" ] || echo "missing CNI plugin: $p" done
Try / catch
status, err := cfg.Setup(ctx, alloc, spec, created)
if err != nil {
var sentinel *cniNotInitialized
if errors.As(err, &sentinel) {
// reinstall CNI plugins, then retry setup once
}
} Prevention
- Install the CNI plugin tarball as part of node provisioning.
- Include CNI binaries in the client AMI/image.
- Monitor /opt/cni/bin contents in node health checks.
When it happens
Trigger: c.ensureCNIInitialized() fails in Setup (and its anonymous retry caller): CNI init was skipped because no CNI config was loaded, the CNI plugin path doesn't contain required binaries, or lazy Init() errored (e.g. missing loopback/bridge plugin binaries).
Common situations: cni_plugin_dir missing the CNI binaries (bridge, loopback, firewall, portmap); CNI conf failed to load earlier leaving c *goCni nil; node configured for bridge networking but CNI plugin tarball never installed.
Related errors
- network namespace already exists but was misconfigured
- no CNI network config found
- failed to configure network manager: %v
- failed to initialize network configurator: %v
- failed to create network for alloc: %v
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/a9cf045b9f17fd7a.
Report an issue: GitHub.