Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit 35eb96d

Browse files
committed
Update deployment and integration test
Signed-off-by: Lantao Liu <[email protected]>
1 parent 5a68bd7 commit 35eb96d

7 files changed

Lines changed: 152 additions & 11 deletions

File tree

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ before_install:
2424
# libseccomp in trusty is not new enough, need backports version.
2525
- sudo sh -c "echo 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse' > /etc/apt/sources.list.d/backports.list"
2626
- sudo apt-get update
27+
# Enable ipv6 for dualstack integration test.
28+
- sudo sysctl net.ipv6.conf.all.disable_ipv6=0
2729

2830
install:
2931
- sudo apt-get install btrfs-tools

cluster/gce/cni.template

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@
77
"mtu": 1460,
88
"ipam": {
99
"type": "host-local",
10-
"subnet": "{{.PodCIDR}}",
11-
"routes": [
12-
{
13-
"dst": "0.0.0.0/0"
14-
}
15-
]
10+
"ranges": [{{range $i, $range := .PodCIDRRanges}}{{if $i}}, {{end}}[{"subnet": "{{$range}}"}]{{end}}],
11+
"routes": [{{range $i, $route := .Routes}}{{if $i}}, {{end}}{"dst": "{{$route}}"}{{end}}]
1612
}
1713
},
1814
{

docs/config.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ version = 2
172172
# file will be loaded. If you want to load multiple CNI plugin config files
173173
# set max_conf_num to the number desired. Setting max_config_num to 0 is
174174
# interpreted as no limit is desired and will result in all CNI plugin
175-
# config files being loaded from the CNI config directory.
175+
# config files being loaded from the CNI config directory.
176176
max_conf_num = 1
177177

178178
# conf_template is the file path of golang template used to generate
@@ -183,6 +183,7 @@ version = 2
183183
# This is a temporary backward-compatible solution for kubenet users
184184
# who don't have a cni daemonset in production yet.
185185
# This will be deprecated when kubenet is deprecated.
186+
# See the "CNI Config Template" section for more details.
186187
conf_template = ""
187188

188189
# 'plugins."io.containerd.grpc.v1.cri".registry' contains config related to the registry
@@ -208,6 +209,35 @@ When the annotation `io.kubernetes.cri.untrusted-workload` is set to `true` the
208209
runtime will be used. For example, see
209210
[Create an untrusted pod using Kata Containers](https://github.com/kata-containers/documentation/blob/master/how-to/how-to-use-k8s-with-cri-containerd-and-kata.md#create-an-untrusted-pod-using-kata-containers).
210211

212+
## CNI Config Template
213+
214+
Ideally the cni config should be placed by system admin or cni daemon like calico,
215+
weaveworks etc. However, there are still users using [kubenet](https://kubernetes.io/docs/concepts/cluster-administration/network-plugins/#kubenet)
216+
today, who don't have a cni daemonset in production. The cni config template is
217+
a temporary backward-compatible solution for them. This is expected to be
218+
deprecated when kubenet is deprecated.
219+
220+
The cni config template uses the [golang
221+
template](https://golang.org/pkg/text/template/) format. Currently supported
222+
values are:
223+
* `.PodCIDR` is a string of the first CIDR assigned to the node.
224+
* `.PodCIDRRanges` is a string array of all CIDRs assigned to the node. It is
225+
usually used for
226+
[dualstack](https://github.com/kubernetes/enhancements/blob/master/keps/sig-network/20180612-ipv4-ipv6-dual-stack.md) support.
227+
* `.Routes` is a string array of all routes needed. It is usually used for
228+
dualstack support or single stack but IPv4 or IPv6 is decided at runtime.
229+
230+
The [golang template actions](https://golang.org/pkg/text/template/#hdr-Actions)
231+
can be used to render the cni config. For example, you can use the following
232+
template to add CIDRs and routes for dualstack in the CNI config:
233+
```
234+
"ipam": {
235+
"type": "host-local",
236+
"ranges": [{{range $i, $range := .PodCIDRRanges}}{{if $i}}, {{end}}[{"subnet": "{{$range}}"}]{{end}}],
237+
"routes": [{{range $i, $route := .Routes}}{{if $i}}, {{end}}{"dst": "{{$route}}"}{{end}}]
238+
}
239+
```
240+
211241
## Deprecation
212242
The config options of the CRI plugin follow the [Kubernetes deprecation
213243
policy of "admin-facing CLI components"](https://kubernetes.io/docs/reference/using-api/deprecation-policy/#deprecating-a-flag-or-cli).

hack/install/install-cni-config.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,17 @@ ${SUDO} bash -c 'cat >'${CNI_CONFIG_DIR}'/10-containerd-net.conflist <<EOF
3434
"promiscMode": true,
3535
"ipam": {
3636
"type": "host-local",
37-
"subnet": "10.88.0.0/16",
37+
"ranges": [
38+
[{
39+
"subnet": "10.88.0.0/16"
40+
}],
41+
[{
42+
"subnet": "2001:4860:4860::8888/32"
43+
}]
44+
],
3845
"routes": [
39-
{ "dst": "0.0.0.0/0" }
46+
{ "dst": "0.0.0.0/0" },
47+
{ "dst": "::/0" }
4048
]
4149
}
4250
},

integration/pod_dualstack_test.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package integration
18+
19+
import (
20+
"io/ioutil"
21+
"net"
22+
"os"
23+
"path/filepath"
24+
"regexp"
25+
"testing"
26+
"time"
27+
28+
"github.com/stretchr/testify/assert"
29+
"github.com/stretchr/testify/require"
30+
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
31+
)
32+
33+
func TestPodDualStack(t *testing.T) {
34+
testPodLogDir, err := ioutil.TempDir("/tmp", "dualstack")
35+
require.NoError(t, err)
36+
defer os.RemoveAll(testPodLogDir)
37+
38+
t.Log("Create a sandbox")
39+
sbConfig := PodSandboxConfig("sandbox", "dualstack", WithPodLogDirectory(testPodLogDir))
40+
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
41+
require.NoError(t, err)
42+
defer func() {
43+
assert.NoError(t, runtimeService.StopPodSandbox(sb))
44+
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
45+
}()
46+
47+
const (
48+
testImage = "busybox"
49+
containerName = "test-container"
50+
)
51+
t.Logf("Pull test image %q", testImage)
52+
img, err := imageService.PullImage(&runtime.ImageSpec{Image: testImage}, nil, sbConfig)
53+
require.NoError(t, err)
54+
defer func() {
55+
assert.NoError(t, imageService.RemoveImage(&runtime.ImageSpec{Image: img}))
56+
}()
57+
58+
t.Log("Create a container to print env")
59+
cnConfig := ContainerConfig(
60+
containerName,
61+
testImage,
62+
WithCommand("ip", "address", "show", "dev", "eth0"),
63+
WithLogPath(containerName),
64+
)
65+
cn, err := runtimeService.CreateContainer(sb, cnConfig, sbConfig)
66+
require.NoError(t, err)
67+
68+
t.Log("Start the container")
69+
require.NoError(t, runtimeService.StartContainer(cn))
70+
71+
t.Log("Wait for container to finish running")
72+
require.NoError(t, Eventually(func() (bool, error) {
73+
s, err := runtimeService.ContainerStatus(cn)
74+
if err != nil {
75+
return false, err
76+
}
77+
if s.GetState() == runtime.ContainerState_CONTAINER_EXITED {
78+
return true, nil
79+
}
80+
return false, nil
81+
}, time.Second, 30*time.Second))
82+
83+
content, err := ioutil.ReadFile(filepath.Join(testPodLogDir, containerName))
84+
assert.NoError(t, err)
85+
status, err := runtimeService.PodSandboxStatus(sb)
86+
require.NoError(t, err)
87+
ip := status.GetNetwork().GetIp()
88+
additionalIps := status.GetNetwork().GetAdditionalIps()
89+
90+
ipv4Enabled, err := regexp.MatchString("inet .* scope global", string(content))
91+
assert.NoError(t, err)
92+
ipv6Enabled, err := regexp.MatchString("inet6 .* scope global", string(content))
93+
assert.NoError(t, err)
94+
95+
if ipv4Enabled && ipv6Enabled {
96+
t.Log("Dualstack should be enabled")
97+
require.Len(t, additionalIps, 1)
98+
assert.NotNil(t, net.ParseIP(ip).To4())
99+
assert.Nil(t, net.ParseIP(additionalIps[0].GetIp()).To4())
100+
} else {
101+
t.Log("Dualstack should not be enabled")
102+
assert.Len(t, additionalIps, 0)
103+
assert.NotEmpty(t, ip)
104+
}
105+
}

integration/restart_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func TestContainerdRestart(t *testing.T) {
133133

134134
t.Logf("Pull test images")
135135
for _, image := range []string{"busybox", "alpine"} {
136-
img, err := imageService.PullImage(&runtime.ImageSpec{image}, nil, nil)
136+
img, err := imageService.PullImage(&runtime.ImageSpec{Image: image}, nil, nil)
137137
require.NoError(t, err)
138138
defer func() {
139139
assert.NoError(t, imageService.RemoveImage(&runtime.ImageSpec{Image: img}))

integration/truncindex_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestTruncIndex(t *testing.T) {
7474
assert.Equal(t, sb, sbStatus.Id)
7575

7676
t.Logf("Forward port for sandbox by truncindex")
77-
_, err = runtimeService.PortForward(&runtimeapi.PortForwardRequest{sbTruncIndex, []int32{80}})
77+
_, err = runtimeService.PortForward(&runtimeapi.PortForwardRequest{PodSandboxId: sbTruncIndex, Port: []int32{80}})
7878
assert.NoError(t, err)
7979

8080
// TODO(yanxuean): add test case for ListPodSandbox

0 commit comments

Comments
 (0)