Add ArgsEscaped support for CRI

This commit adds supports for the ArgsEscaped
value for the image got from the dockerfile.
It is used to evaluate and process the image
entrypoint/cmd and container entrypoint/cmd
options got from the podspec.

Signed-off-by: Kirtana Ashok <Kirtana.Ashok@microsoft.com>
This commit is contained in:
Kirtana Ashok
2022-07-05 17:35:48 -07:00
parent 97480afdac
commit 8137e41c48
11 changed files with 363 additions and 20 deletions

View File

@@ -21,12 +21,15 @@ package integration
import (
"fmt"
"os"
"strconv"
"testing"
"time"
"github.com/Microsoft/hcsshim/osversion"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/sys/windows/registry"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
v1 "k8s.io/cri-api/pkg/apis/runtime/v1"
)
@@ -123,3 +126,65 @@ func runHostProcess(t *testing.T, expectErr bool, image string, action hpcAction
action(t, cn, containerConfig)
}
func startAndTestContainer(t *testing.T, sb string, sbConfig *runtime.PodSandboxConfig, cnConfig *runtime.ContainerConfig) {
t.Log("Create the container")
cn, err := runtimeService.CreateContainer(sb, cnConfig, sbConfig)
require.NoError(t, err)
t.Log("Start the container")
require.NoError(t, runtimeService.StartContainer(cn))
t.Log("Stop the container")
require.NoError(t, runtimeService.StopContainer(cn, 0))
t.Log("Remove the container")
require.NoError(t, runtimeService.RemoveContainer(cn))
}
func TestArgsEscapedImagesOnWindows(t *testing.T) {
// the ArgsEscaped test image is based on nanoserver:ltsc2022, so ensure we run on the correct OS version
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
if err != nil {
t.Skip("Error in getting OS version")
}
defer k.Close()
b, _, _ := k.GetStringValue("CurrentBuild")
buildNum, _ := strconv.Atoi(b)
if buildNum < osversion.V21H2Server {
t.Skip()
}
containerName := "test-container"
testImage := images.Get(images.ArgsEscaped)
sbConfig := &runtime.PodSandboxConfig{
Metadata: &runtime.PodSandboxMetadata{
Name: "sandbox",
Namespace: testImage,
},
Windows: &runtime.WindowsPodSandboxConfig{},
}
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
require.NoError(t, err)
t.Cleanup(func() {
assert.NoError(t, runtimeService.StopPodSandbox(sb))
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
})
EnsureImageExists(t, testImage)
cnConfigWithCtrCmd := ContainerConfig(
containerName,
testImage,
WithCommand("ping", "-t", "127.0.0.1"),
localSystemUsername,
)
cnConfigNoCtrCmd := ContainerConfig(
containerName,
testImage,
localSystemUsername,
)
startAndTestContainer(t, sb, sbConfig, cnConfigWithCtrCmd)
startAndTestContainer(t, sb, sbConfig, cnConfigNoCtrCmd)
}