integration: enable CNI slow test for sbserver
Signed-off-by: Samuel Karp <samuelkarp@google.com>
This commit is contained in:
parent
a74f7e902b
commit
ac4af4df89
@ -20,6 +20,7 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@ -36,6 +37,7 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
criapiv1 "k8s.io/cri-api/pkg/apis/runtime/v1"
|
criapiv1 "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/pkg/cri/sbserver"
|
||||||
"github.com/containerd/containerd/pkg/cri/store/sandbox"
|
"github.com/containerd/containerd/pkg/cri/store/sandbox"
|
||||||
"github.com/containerd/containerd/pkg/failpoint"
|
"github.com/containerd/containerd/pkg/failpoint"
|
||||||
"github.com/containerd/typeurl"
|
"github.com/containerd/typeurl"
|
||||||
@ -237,9 +239,6 @@ func TestRunPodSandboxAndTeardownCNISlow(t *testing.T) {
|
|||||||
if runtime.GOOS != "linux" {
|
if runtime.GOOS != "linux" {
|
||||||
t.Skip()
|
t.Skip()
|
||||||
}
|
}
|
||||||
if os.Getenv("ENABLE_CRI_SANDBOXES") != "" {
|
|
||||||
t.Skip()
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Log("Init PodSandboxConfig with specific key")
|
t.Log("Init PodSandboxConfig with specific key")
|
||||||
sbName := t.Name()
|
sbName := t.Name()
|
||||||
@ -295,31 +294,63 @@ func TestRunPodSandboxAndTeardownCNISlow(t *testing.T) {
|
|||||||
assert.Equal(t, sb.Metadata.Uid, sbConfig.Metadata.Uid)
|
assert.Equal(t, sb.Metadata.Uid, sbConfig.Metadata.Uid)
|
||||||
assert.Equal(t, sb.Metadata.Attempt, sbConfig.Metadata.Attempt)
|
assert.Equal(t, sb.Metadata.Attempt, sbConfig.Metadata.Attempt)
|
||||||
|
|
||||||
t.Log("Get sandbox info")
|
switch os.Getenv("ENABLE_CRI_SANDBOXES") {
|
||||||
_, info, err := SandboxInfo(sb.Id)
|
case "":
|
||||||
require.NoError(t, err)
|
// non-sbserver
|
||||||
require.False(t, info.NetNSClosed)
|
t.Log("Get sandbox info (non-sbserver)")
|
||||||
|
_, info, err := SandboxInfo(sb.Id)
|
||||||
var netNS string
|
require.NoError(t, err)
|
||||||
for _, n := range info.RuntimeSpec.Linux.Namespaces {
|
require.False(t, info.NetNSClosed)
|
||||||
if n.Type == runtimespec.NetworkNamespace {
|
var netNS string
|
||||||
netNS = n.Path
|
for _, n := range info.RuntimeSpec.Linux.Namespaces {
|
||||||
|
if n.Type == runtimespec.NetworkNamespace {
|
||||||
|
netNS = n.Path
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
assert.NotEmpty(t, netNS, "network namespace should be set")
|
||||||
assert.NotEmpty(t, netNS, "network namespace should be set")
|
|
||||||
|
|
||||||
t.Log("Get sandbox container")
|
t.Log("Get sandbox container")
|
||||||
c, err := GetContainer(sb.Id)
|
c, err := GetContainer(sb.Id)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
any, ok := c.Extensions["io.cri-containerd.sandbox.metadata"]
|
any, ok := c.Extensions["io.cri-containerd.sandbox.metadata"]
|
||||||
require.True(t, ok, "sandbox metadata should exist in extension")
|
require.True(t, ok, "sandbox metadata should exist in extension")
|
||||||
i, err := typeurl.UnmarshalAny(any)
|
i, err := typeurl.UnmarshalAny(any)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.IsType(t, &sandbox.Metadata{}, i)
|
require.IsType(t, &sandbox.Metadata{}, i)
|
||||||
metadata, ok := i.(*sandbox.Metadata)
|
metadata, ok := i.(*sandbox.Metadata)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
assert.NotEmpty(t, metadata.NetNSPath)
|
assert.Equal(t, netNS, metadata.NetNSPath, "network namespace path should be the same in runtime spec and sandbox metadata")
|
||||||
assert.Equal(t, netNS, metadata.NetNSPath, "network namespace path should be the same in runtime spec and sandbox metadata")
|
default:
|
||||||
|
// sbserver
|
||||||
|
t.Log("Get sandbox info (sbserver)")
|
||||||
|
_, info, err := sbserverSandboxInfo(sb.Id)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.False(t, info.NetNSClosed)
|
||||||
|
|
||||||
|
assert.NotEmpty(t, info.Metadata.NetNSPath, "network namespace should be set")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// sbserverSandboxInfo gets sandbox info.
|
||||||
|
func sbserverSandboxInfo(id string) (*criapiv1.PodSandboxStatus, *sbserver.SandboxInfo, error) {
|
||||||
|
client, err := RawRuntimeClient()
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, fmt.Errorf("failed to get raw runtime client: %w", err)
|
||||||
|
}
|
||||||
|
resp, err := client.PodSandboxStatus(context.Background(), &criapiv1.PodSandboxStatusRequest{
|
||||||
|
PodSandboxId: id,
|
||||||
|
Verbose: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, fmt.Errorf("failed to get sandbox status: %w", err)
|
||||||
|
}
|
||||||
|
status := resp.GetStatus()
|
||||||
|
var info sbserver.SandboxInfo
|
||||||
|
if err := json.Unmarshal([]byte(resp.GetInfo()["info"]), &info); err != nil {
|
||||||
|
return nil, nil, fmt.Errorf("failed to unmarshal sandbox info: %w", err)
|
||||||
|
}
|
||||||
|
return status, &info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ensureCNIAddRunning(t *testing.T, sbName string) error {
|
func ensureCNIAddRunning(t *testing.T, sbName string) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user