Debian Codegraph @

script/setup/install-cni

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/usr/bin/env bash
2
3 # Copyright The containerd Authors.
4
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8
9 # http://www.apache.org/licenses/LICENSE-2.0
10
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 #
18 # Builds and installs cni plugins to /opt/cni/bin,
19 # and create basic cni config in /etc/cni/net.d.
20 # The commit defined in go.mod
21 #
22 set -eu -o pipefail
23
24 CNI_COMMIT=${1:-$(go list -f "{{.Version}}" -m github.com/containernetworking/plugins)}
25 CNI_DIR=${DESTDIR:=''}/opt/cni
26 CNI_CONFIG_DIR=${DESTDIR}/etc/cni/net.d
27 : "${CNI_REPO:=https://github.com/containernetworking/plugins.git}"
28
29 # e2e and Cirrus will fail with "sudo: command not found"
30 SUDO=''
31 if (( $EUID != 0 )); then
32 SUDO='sudo'
33 fi
34
35 TMPROOT=$(mktemp -d)
36 git clone "${CNI_REPO}" "${TMPROOT}"/plugins
37 pushd "${TMPROOT}"/plugins
38 git checkout "$CNI_COMMIT"
39 ./build_linux.sh
40 $SUDO mkdir -p $CNI_DIR
41 $SUDO cp -r ./bin $CNI_DIR
42 $SUDO mkdir -p $CNI_CONFIG_DIR
43 $SUDO cat << EOF | $SUDO tee $CNI_CONFIG_DIR/10-containerd-net.conflist
44 {
45 "cniVersion": "1.0.0",
46 "name": "containerd-net",
47 "plugins": [
48 {
49 "type": "bridge",
50 "bridge": "cni0",
51 "isGateway": true,
52 "ipMasq": true,
53 "promiscMode": true,
54 "ipam": {
55 "type": "host-local",
56 "ranges": [
57 [{
58 "subnet": "10.88.0.0/16"
59 }],
60 [{
61 "subnet": "2001:4860:4860::/64"
62 }]
63 ],
64 "routes": [
65 { "dst": "0.0.0.0/0" },
66 { "dst": "::/0" }
67 ]
68 }
69 },
70 {
71 "type": "portmap",
72 "capabilities": {"portMappings": true}
73 }
74 ]
75 }
76 EOF
77
78 popd
79 rm -fR "${TMPROOT}"