{"id":28486139,"url":"https://github.com/containerd/go-cni","last_synced_at":"2025-07-02T12:32:33.761Z","repository":{"id":30444278,"uuid":"121671786","full_name":"containerd/go-cni","owner":"containerd","description":"A generic CNI library to provide APIs for CNI plugin interactions","archived":false,"fork":false,"pushed_at":"2025-07-01T22:01:58.000Z","size":423,"stargazers_count":155,"open_issues_count":14,"forks_count":63,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-07-01T23:19:18.040Z","etag":null,"topics":["cni","containerd"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/containerd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-02-15T19:24:06.000Z","updated_at":"2025-07-01T22:02:03.000Z","dependencies_parsed_at":"2024-05-19T19:42:49.186Z","dependency_job_id":"3a89873c-01f0-403b-bae3-8ef94e7f7936","html_url":"https://github.com/containerd/go-cni","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/containerd/go-cni","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/containerd%2Fgo-cni","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/containerd%2Fgo-cni/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/containerd%2Fgo-cni/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/containerd%2Fgo-cni/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/containerd","download_url":"https://codeload.github.com/containerd/go-cni/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/containerd%2Fgo-cni/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263140549,"owners_count":23419905,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cni","containerd"],"created_at":"2025-06-08T01:10:21.893Z","updated_at":"2025-07-02T12:32:33.733Z","avatar_url":"https://github.com/containerd.png","language":"Go","readme":"# go-cni\n\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/containerd/go-cni)](https://pkg.go.dev/github.com/containerd/go-cni)\n[![Build Status](https://github.com/containerd/go-cni/workflows/CI/badge.svg)](https://github.com/containerd/go-cni/actions?query=workflow%3ACI)\n[![codecov](https://codecov.io/gh/containerd/go-cni/branch/main/graph/badge.svg)](https://codecov.io/gh/containerd/go-cni)\n[![Go Report Card](https://goreportcard.com/badge/github.com/containerd/go-cni)](https://goreportcard.com/report/github.com/containerd/go-cni)\n\nA generic CNI library to provide APIs for CNI plugin interactions. The library provides APIs to:\n\n- Load CNI network config from different sources  \n- Setup networks for container namespace\n- Remove networks from container namespace\n- Query status of CNI network plugin initialization\n- Check verifies the network is still in desired state\n\ngo-cni aims to support plugins that implement the [Container Network Interface](https://github.com/containernetworking/cni).\n\n## Usage\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\n\tgocni \"github.com/containerd/go-cni\"\n)\n\nfunc main() {\n\tid := \"example\"\n\tnetns := \"/var/run/netns/example-ns-1\"\n\n\t// CNI allows multiple CNI configurations and the network interface\n\t// will be named by eth0, eth1, ..., ethN.\n\tifPrefixName := \"eth\"\n\tdefaultIfName := \"eth0\"\n\n\t// Initializes library\n\tl, err := gocni.New(\n\t\t// one for loopback network interface\n\t\tgocni.WithMinNetworkCount(2),\n\t\tgocni.WithPluginConfDir(\"/etc/cni/net.d\"),\n\t\tgocni.WithPluginDir([]string{\"/opt/cni/bin\"}),\n\t\t// Sets the prefix for network interfaces, eth by default\n\t\tgocni.WithInterfacePrefix(ifPrefixName))\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to initialize cni library: %v\", err)\n\t}\n\n\t// Load the cni configuration\n\tif err := l.Load(gocni.WithLoNetwork, gocni.WithDefaultConf); err != nil {\n\t\tlog.Fatalf(\"failed to load cni configuration: %v\", err)\n\t}\n\n\t// Setup network for namespace.\n\tlabels := map[string]string{\n\t\t\"K8S_POD_NAMESPACE\":          \"namespace1\",\n\t\t\"K8S_POD_NAME\":               \"pod1\",\n\t\t\"K8S_POD_INFRA_CONTAINER_ID\": id,\n\t\t// Plugin tolerates all Args embedded by unknown labels, like\n\t\t// K8S_POD_NAMESPACE/NAME/INFRA_CONTAINER_ID...\n\t\t\"IgnoreUnknown\": \"1\",\n\t}\n\n\tctx := context.Background()\n\n\t// Teardown network\n\tdefer func() {\n\t\tif err := l.Remove(ctx, id, netns, gocni.WithLabels(labels)); err != nil {\n\t\t\tlog.Fatalf(\"failed to teardown network: %v\", err)\n\t\t}\n\t}()\n\n\t// Setup network\n\tresult, err := l.Setup(ctx, id, netns, gocni.WithLabels(labels))\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to setup network for namespace: %v\", err)\n\t}\n\n\t// Get IP of the default interface\n\tIP := result.Interfaces[defaultIfName].IPConfigs[0].IP.String()\n\tfmt.Printf(\"IP of the default interface %s:%s\", defaultIfName, IP)\n}\n```\n\n## Project details\n\nThe go-cni is a containerd sub-project, licensed under the [Apache 2.0 license](./LICENSE).\nAs a containerd sub-project, you will find the:\n\n * [Project governance](https://github.com/containerd/project/blob/main/GOVERNANCE.md),\n * [Maintainers](https://github.com/containerd/project/blob/main/MAINTAINERS),\n * and [Contributing guidelines](https://github.com/containerd/project/blob/main/CONTRIBUTING.md)\n\ninformation in our [`containerd/project`](https://github.com/containerd/project) repository.\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcontainerd%2Fgo-cni","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcontainerd%2Fgo-cni","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcontainerd%2Fgo-cni/lists"}