forked from containerd/cri
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lantao Liu <[email protected]>
- Loading branch information
1 parent
dc964de
commit 7e96aaa
Showing
16 changed files
with
440 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/bin/bash | ||
|
||
# Copyright The containerd Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
CNI_CONFIG_DIR="${CNI_CONFIG_DIR:-"C:\\Program Files\\containerd\\cni\\conf"}" | ||
mkdir -p "${CNI_CONFIG_DIR}" | ||
|
||
# split_ip splits ip into a 4-element array. | ||
split_ip() { | ||
local -r varname="$1" | ||
local -r ip="$2" | ||
for i in {0..3}; do | ||
eval "$varname"[$i]=$( echo "$ip" | cut -d '.' -f $((i + 1)) ) | ||
done | ||
} | ||
|
||
# subnet gets subnet for a gateway, e.g. 192.168.100.0/24. | ||
calculate_subnet() { | ||
local -r gateway="$1" | ||
local -r prefix_len="$2" | ||
split_ip gateway_array "$gateway" | ||
local len=$prefix_len | ||
for i in {0..3}; do | ||
if (( len >= 8 )); then | ||
mask=255 | ||
elif (( len > 0 )); then | ||
mask=$(( 256 - 2 ** ( 8 - len ) )) | ||
else | ||
mask=0 | ||
fi | ||
(( len -= 8 )) | ||
result_array[i]=$(( gateway_array[i] & mask )) | ||
done | ||
result="$(printf ".%s" "${result_array[@]}")" | ||
result="${result:1}" | ||
echo "$result/$((32 - prefix_len))" | ||
} | ||
|
||
# nat already exists on the Windows VM, the subnet and gateway | ||
# we specify should match that. | ||
gateway="$(powershell -c "(Get-NetIPAddress -InterfaceAlias 'vEthernet (nat)' -AddressFamily IPv4).IPAddress")" | ||
prefix_len="$(powershell -c "(Get-NetIPAddress -InterfaceAlias 'vEthernet (nat)' -AddressFamily IPv4).PrefixLength")" | ||
|
||
subnet="$(calculate_subnet "$gateway" "$prefix_len")" | ||
|
||
# The "name" field in the config is used as the underlying | ||
# network type right now (see | ||
# https://github.com/microsoft/windows-container-networking/pull/45), | ||
# so it must match a network type in: | ||
# https://docs.microsoft.com/en-us/windows-server/networking/technologies/hcn/hcn-json-document-schemas | ||
bash -c 'cat >"'"${CNI_CONFIG_DIR}"'"/0-containerd-nat.conf <<EOF | ||
{ | ||
"cniVersion": "0.2.0", | ||
"name": "nat", | ||
"type": "nat", | ||
"master": "Ethernet", | ||
"ipam": { | ||
"subnet": "'$subnet'", | ||
"routes": [ | ||
{ | ||
"gateway": "'$gateway'" | ||
} | ||
] | ||
}, | ||
"capabilities": { | ||
"portMappings": true, | ||
"dns": true | ||
} | ||
} | ||
EOF' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
# Copyright The containerd Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
source $(dirname "${BASH_SOURCE[0]}")/../utils.sh | ||
# WINCNI_BIN_DIR is the cni plugin directory | ||
WINCNI_BIN_DIR="${WINCNI_BIN_DIR:-"C:\\Program Files\\containerd\\cni\\bin"}" | ||
WINCNI_PKG=github.com/Microsoft/windows-container-networking | ||
WINCNI_VERSION=33bc4764ea3ad7c6ec58c5716370d329f5eb1266 | ||
|
||
# Create a temporary GOPATH for cni installation. | ||
GOPATH="$(mktemp -d /tmp/cri-install-cni.XXXX)" | ||
|
||
# Install cni | ||
checkout_repo "${WINCNI_PKG}" "${WINCNI_VERSION}" "${WINCNI_PKG}" | ||
cd "${GOPATH}/src/${WINCNI_PKG}" | ||
go build "${WINCNI_PKG}/plugins/nat" | ||
install -D -m 755 "nat.exe" "${WINCNI_BIN_DIR}/nat.exe" | ||
|
||
# Clean the tmp GOPATH dir. | ||
rm -rf "${GOPATH}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/bin/bash | ||
|
||
# Copyright The containerd Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
cd $(dirname "${BASH_SOURCE[0]}") | ||
|
||
# Install hcsshim | ||
./install-hcsshim.sh | ||
|
||
# Install cni | ||
./install-cni.sh | ||
|
||
# Install cni config | ||
./install-cni-config.sh | ||
|
||
# Install containerd | ||
NOSUDO=true \ | ||
BUILDTAGS="" \ | ||
CONTAINERD_DIR='C:\Program Files\Containerd' \ | ||
../install-containerd.sh | ||
# Containerd makefile always installs into a "bin" directory. | ||
# Use slash instead of bach slash so that `*` can work. | ||
mv C:/'Program Files'/Containerd/bin/* 'C:\Program Files\Containerd\' | ||
rm -rf 'C:\Program Files\Containerd\bin' | ||
|
||
#Install critools | ||
NOSUDO=true \ | ||
CRITOOL_DIR='C:\Program Files\Containerd' \ | ||
CRICTL_RUNTIME_ENDPOINT="npipe:////./pipe/containerd-containerd" \ | ||
CRICTL_CONFIG_DIR="C:\\Users\\$(id -u -n)\\.crictl" \ | ||
../install-critools.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2018 The containerd Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
source $(dirname "${BASH_SOURCE[0]}")/../utils.sh | ||
HCSSHIM_DIR="${HCSSHIM_DIR:-"C:\\Program Files\\Containerd"}" | ||
HCSSHIM_PKG=github.com/Microsoft/hcsshim | ||
|
||
# Create a temporary GOPATH for hcsshim installation. | ||
GOPATH="$(mktemp -d /tmp/cri-install-hcsshim.XXXX)" | ||
|
||
# Install hcsshim | ||
from-vendor HCSSHIM "${HCSSHIM_PKG}" | ||
checkout_repo "${HCSSHIM_PKG}" "${HCSSHIM_VERSION}" "${HCSSHIM_REPO}" | ||
cd "${GOPATH}/src/${HCSSHIM_PKG}" | ||
go build "${HCSSHIM_PKG}/cmd/containerd-shim-runhcs-v1" | ||
install -D -m 755 containerd-shim-runhcs-v1 "${HCSSHIM_DIR}"/containerd-shim-runhcs-v1 | ||
|
||
# Clean the tmp GOPATH dir. Use sudo because runc build generates | ||
# some privileged files. | ||
rm -rf ${GOPATH} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.