CCv0: Merge main into CCv0 branch

Merge remote-tracking branch 'upstream/main' into CCv0

Fixes: #3295

Signed-off-by: stevenhorsman <steven@uk.ibm.com>
This commit is contained in:
stevenhorsman
2021-12-17 10:33:30 +00:00
123 changed files with 1656 additions and 640 deletions

View File

@@ -70,7 +70,7 @@ func create(ctx context.Context, s *service, r *taskAPI.CreateTaskRequest) (*con
rootfs := filepath.Join(r.Bundle, "rootfs")
switch containerType {
case vc.PodSandbox:
case vc.PodSandbox, vc.SingleContainer:
if s.sandbox != nil {
return nil, fmt.Errorf("cannot create another sandbox in sandbox: %s", s.sandbox.ID())
}

View File

@@ -9,7 +9,6 @@ package containerdshim
import (
"context"
"fmt"
"io/ioutil"
"os"
"path"
"testing"
@@ -362,7 +361,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config string, err err
runtimeConfigFileData := ktu.MakeRuntimeConfigFileData(configFileOptions)
configPath := path.Join(dir, "runtime.toml")
err = ioutil.WriteFile(configPath, []byte(runtimeConfigFileData), os.FileMode(0640))
err = os.WriteFile(configPath, []byte(runtimeConfigFileData), os.FileMode(0640))
if err != nil {
return "", err
}
@@ -371,7 +370,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config string, err err
for _, file := range files {
// create the resource (which must be >0 bytes)
err := ioutil.WriteFile(file, []byte("foo"), os.FileMode(0640))
err := os.WriteFile(file, []byte("foo"), os.FileMode(0640))
if err != nil {
return "", err
}
@@ -383,7 +382,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config string, err err
func TestCreateLoadRuntimeConfig(t *testing.T) {
assert := assert.New(t)
tmpdir, err := ioutil.TempDir("", "")
tmpdir, err := os.MkdirTemp("", "")
assert.NoError(err)
defer os.RemoveAll(tmpdir)

View File

@@ -7,7 +7,7 @@ package containerdshim
import (
"context"
"io/ioutil"
"io"
"os"
sysexec "os/exec"
"sync"
@@ -80,7 +80,7 @@ func New(ctx context.Context, id string, publisher cdshim.Publisher, shutdown fu
// Discard the log before shim init its log output. Otherwise
// it will output into stdio, from which containerd would like
// to get the shim's socket address.
logrus.SetOutput(ioutil.Discard)
logrus.SetOutput(io.Discard)
opts := ctx.Value(cdshim.OptsKey{}).(cdshim.Opts)
if !opts.Debug {
logrus.SetLevel(logrus.WarnLevel)
@@ -345,7 +345,7 @@ func (s *service) Cleanup(ctx context.Context) (_ *taskAPI.DeleteResponse, err e
}
switch containerType {
case vc.PodSandbox:
case vc.PodSandbox, vc.SingleContainer:
err = cleanupContainer(spanCtx, s.id, s.id, path)
if err != nil {
return nil, err

View File

@@ -8,7 +8,6 @@ package containerdshim
import (
"context"
"io"
"io/ioutil"
"os"
"path/filepath"
"syscall"
@@ -26,11 +25,11 @@ func TestNewTtyIOFifoReopen(t *testing.T) {
assert := assert.New(t)
ctx := context.TODO()
testDir, err := ioutil.TempDir("", "kata-")
testDir, err := os.MkdirTemp("", "kata-")
assert.NoError(err)
defer os.RemoveAll(testDir)
fifoPath, err := ioutil.TempDir(testDir, "fifo-path-")
fifoPath, err := os.MkdirTemp(testDir, "fifo-path-")
assert.NoError(err)
stdout := filepath.Join(fifoPath, "stdout")
stderr := filepath.Join(fifoPath, "stderr")
@@ -104,11 +103,11 @@ func TestIoCopy(t *testing.T) {
testBytes2 := []byte("Test2")
testBytes3 := []byte("Test3")
testDir, err := ioutil.TempDir("", "kata-")
testDir, err := os.MkdirTemp("", "kata-")
assert.NoError(err)
defer os.RemoveAll(testDir)
fifoPath, err := ioutil.TempDir(testDir, "fifo-path-")
fifoPath, err := os.MkdirTemp(testDir, "fifo-path-")
assert.NoError(err)
dstStdoutPath := filepath.Join(fifoPath, "dststdout")
dstStderrPath := filepath.Join(fifoPath, "dststderr")

View File

@@ -8,7 +8,6 @@ package containerdshim
import (
"fmt"
"io/ioutil"
"os"
"path"
"testing"
@@ -60,7 +59,7 @@ func init() {
}
func createEmptyFile(path string) (err error) {
return ioutil.WriteFile(path, []byte(""), testFileMode)
return os.WriteFile(path, []byte(""), testFileMode)
}
// newTestHypervisorConfig creaets a new virtcontainers

View File

@@ -7,7 +7,7 @@ package katamonitor
import (
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"os"
@@ -90,7 +90,7 @@ func doGet(sandboxID string, timeoutInSeconds time.Duration, urlPath string) ([]
resp.Body.Close()
}()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

View File

@@ -8,7 +8,6 @@ package katatestutils
import (
"errors"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
@@ -63,7 +62,7 @@ type Result struct {
// GetFileContents return the file contents as a string.
func getFileContents(file string) (string, error) {
bytes, err := ioutil.ReadFile(file)
bytes, err := os.ReadFile(file)
if err != nil {
return "", err
}

View File

@@ -8,7 +8,6 @@ package katatestutils
import (
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -316,7 +315,7 @@ func testGetDistro() (name, version string, err error) {
func testGetKernelVersion() (version string, err error) {
const file = "/proc/version"
bytes, err := ioutil.ReadFile(file)
bytes, err := os.ReadFile(file)
if err != nil {
return "", err
}
@@ -416,7 +415,7 @@ func TestGetFileContents(t *testing.T) {
{"foo\nbar"},
}
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
assert.NoError(err)
defer os.RemoveAll(dir)
@@ -428,7 +427,7 @@ func TestGetFileContents(t *testing.T) {
for _, d := range data {
// create the file
err = ioutil.WriteFile(file, []byte(d.contents), testFileMode)
err = os.WriteFile(file, []byte(d.contents), testFileMode)
assert.NoError(err)
defer os.Remove(file)

View File

@@ -9,7 +9,6 @@ package katatestutils
import (
"encoding/json"
"errors"
"io/ioutil"
"os"
"path/filepath"
"strconv"
@@ -347,7 +346,7 @@ func IsInGitHubActions() bool {
func SetupOCIConfigFile(t *testing.T) (rootPath string, bundlePath, ociConfigFile string) {
assert := assert.New(t)
tmpdir, err := ioutil.TempDir("", "katatest-")
tmpdir, err := os.MkdirTemp("", "katatest-")
assert.NoError(err)
bundlePath = filepath.Join(tmpdir, "bundle")
@@ -355,7 +354,7 @@ func SetupOCIConfigFile(t *testing.T) (rootPath string, bundlePath, ociConfigFil
assert.NoError(err)
ociConfigFile = filepath.Join(bundlePath, "config.json")
err = ioutil.WriteFile(ociConfigFile, []byte(busyboxConfigJson), testFileMode)
err = os.WriteFile(ociConfigFile, []byte(busyboxConfigJson), testFileMode)
assert.NoError(err)
return tmpdir, bundlePath, ociConfigFile
@@ -372,5 +371,5 @@ func WriteOCIConfigFile(spec specs.Spec, configPath string) error {
return err
}
return ioutil.WriteFile(configPath, bytes, testFileMode)
return os.WriteFile(configPath, bytes, testFileMode)
}

View File

@@ -9,7 +9,7 @@ package katautils
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
goruntime "runtime"
"strings"
@@ -1200,7 +1200,7 @@ func decodeConfig(configPath string) (tomlConfig, string, error) {
return tomlConf, "", fmt.Errorf("Cannot find usable config file (%v)", err)
}
configData, err := ioutil.ReadFile(resolved)
configData, err := os.ReadFile(resolved)
if err != nil {
return tomlConf, resolved, err
}

View File

@@ -9,7 +9,6 @@ package katautils
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
@@ -49,7 +48,7 @@ type testRuntimeConfig struct {
func createConfig(configPath string, fileData string) error {
err := ioutil.WriteFile(configPath, []byte(fileData), testFileMode)
err := os.WriteFile(configPath, []byte(fileData), testFileMode)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to create config file %s %v\n", configPath, err)
return err
@@ -280,7 +279,7 @@ func testLoadConfiguration(t *testing.T, dir string,
}
func TestConfigLoadConfiguration(t *testing.T) {
tmpdir, err := ioutil.TempDir(testDir, "load-config-")
tmpdir, err := os.MkdirTemp(testDir, "load-config-")
assert.NoError(t, err)
defer os.RemoveAll(tmpdir)
@@ -288,7 +287,7 @@ func TestConfigLoadConfiguration(t *testing.T) {
}
func TestConfigLoadConfigurationFailBrokenSymLink(t *testing.T) {
tmpdir, err := ioutil.TempDir(testDir, "runtime-config-")
tmpdir, err := os.MkdirTemp(testDir, "runtime-config-")
assert.NoError(t, err)
defer os.RemoveAll(tmpdir)
@@ -311,7 +310,7 @@ func TestConfigLoadConfigurationFailBrokenSymLink(t *testing.T) {
}
func TestConfigLoadConfigurationFailSymLinkLoop(t *testing.T) {
tmpdir, err := ioutil.TempDir(testDir, "runtime-config-")
tmpdir, err := os.MkdirTemp(testDir, "runtime-config-")
assert.NoError(t, err)
defer os.RemoveAll(tmpdir)
@@ -340,7 +339,7 @@ func TestConfigLoadConfigurationFailSymLinkLoop(t *testing.T) {
}
func TestConfigLoadConfigurationFailMissingHypervisor(t *testing.T) {
tmpdir, err := ioutil.TempDir(testDir, "runtime-config-")
tmpdir, err := os.MkdirTemp(testDir, "runtime-config-")
assert.NoError(t, err)
defer os.RemoveAll(tmpdir)
@@ -358,7 +357,7 @@ func TestConfigLoadConfigurationFailMissingHypervisor(t *testing.T) {
}
func TestConfigLoadConfigurationFailMissingImage(t *testing.T) {
tmpdir, err := ioutil.TempDir(testDir, "runtime-config-")
tmpdir, err := os.MkdirTemp(testDir, "runtime-config-")
assert.NoError(t, err)
defer os.RemoveAll(tmpdir)
@@ -376,7 +375,7 @@ func TestConfigLoadConfigurationFailMissingImage(t *testing.T) {
}
func TestConfigLoadConfigurationFailMissingKernel(t *testing.T) {
tmpdir, err := ioutil.TempDir(testDir, "runtime-config-")
tmpdir, err := os.MkdirTemp(testDir, "runtime-config-")
assert.NoError(t, err)
defer os.RemoveAll(tmpdir)
@@ -398,7 +397,7 @@ func TestConfigLoadConfigurationFailUnreadableConfig(t *testing.T) {
t.Skip(ktu.TestDisabledNeedNonRoot)
}
tmpdir, err := ioutil.TempDir(testDir, "runtime-config-")
tmpdir, err := os.MkdirTemp(testDir, "runtime-config-")
assert.NoError(t, err)
defer os.RemoveAll(tmpdir)
@@ -421,7 +420,7 @@ func TestConfigLoadConfigurationFailTOMLConfigFileInvalidContents(t *testing.T)
t.Skip(ktu.TestDisabledNeedNonRoot)
}
tmpdir, err := ioutil.TempDir(testDir, "runtime-config-")
tmpdir, err := os.MkdirTemp(testDir, "runtime-config-")
assert.NoError(t, err)
defer os.RemoveAll(tmpdir)
@@ -447,7 +446,7 @@ func TestConfigLoadConfigurationFailTOMLConfigFileDuplicatedData(t *testing.T) {
t.Skip(ktu.TestDisabledNeedNonRoot)
}
tmpdir, err := ioutil.TempDir(testDir, "runtime-config-")
tmpdir, err := os.MkdirTemp(testDir, "runtime-config-")
assert.NoError(t, err)
defer os.RemoveAll(tmpdir)
@@ -472,7 +471,7 @@ func TestConfigLoadConfigurationFailTOMLConfigFileDuplicatedData(t *testing.T) {
}
func TestMinimalRuntimeConfig(t *testing.T) {
dir, err := ioutil.TempDir(testDir, "minimal-runtime-config-")
dir, err := os.MkdirTemp(testDir, "minimal-runtime-config-")
if err != nil {
t.Fatal(err)
}
@@ -602,7 +601,7 @@ func TestMinimalRuntimeConfig(t *testing.T) {
}
func TestNewQemuHypervisorConfig(t *testing.T) {
dir, err := ioutil.TempDir(testDir, "hypervisor-config-")
dir, err := os.MkdirTemp(testDir, "hypervisor-config-")
if err != nil {
t.Fatal(err)
}
@@ -699,7 +698,7 @@ func TestNewQemuHypervisorConfig(t *testing.T) {
}
func TestNewFirecrackerHypervisorConfig(t *testing.T) {
dir, err := ioutil.TempDir(testDir, "hypervisor-config-")
dir, err := os.MkdirTemp(testDir, "hypervisor-config-")
if err != nil {
t.Fatal(err)
}
@@ -794,7 +793,7 @@ func TestNewFirecrackerHypervisorConfig(t *testing.T) {
func TestNewQemuHypervisorConfigImageAndInitrd(t *testing.T) {
assert := assert.New(t)
tmpdir, err := ioutil.TempDir(testDir, "")
tmpdir, err := os.MkdirTemp(testDir, "")
assert.NoError(err)
defer os.RemoveAll(tmpdir)
@@ -836,7 +835,7 @@ func TestNewClhHypervisorConfig(t *testing.T) {
assert := assert.New(t)
tmpdir, err := ioutil.TempDir(testDir, "")
tmpdir, err := os.MkdirTemp(testDir, "")
assert.NoError(err)
defer os.RemoveAll(tmpdir)
@@ -931,7 +930,7 @@ func TestHypervisorDefaults(t *testing.T) {
func TestHypervisorDefaultsHypervisor(t *testing.T) {
assert := assert.New(t)
tmpdir, err := ioutil.TempDir(testDir, "")
tmpdir, err := os.MkdirTemp(testDir, "")
assert.NoError(err)
defer os.RemoveAll(tmpdir)
@@ -967,7 +966,7 @@ func TestHypervisorDefaultsHypervisor(t *testing.T) {
func TestHypervisorDefaultsKernel(t *testing.T) {
assert := assert.New(t)
tmpdir, err := ioutil.TempDir(testDir, "")
tmpdir, err := os.MkdirTemp(testDir, "")
assert.NoError(err)
defer os.RemoveAll(tmpdir)
@@ -1010,7 +1009,7 @@ func TestHypervisorDefaultsKernel(t *testing.T) {
func TestHypervisorDefaultsInitrd(t *testing.T) {
assert := assert.New(t)
tmpdir, err := ioutil.TempDir(testDir, "")
tmpdir, err := os.MkdirTemp(testDir, "")
assert.NoError(err)
defer os.RemoveAll(tmpdir)
@@ -1047,7 +1046,7 @@ func TestHypervisorDefaultsInitrd(t *testing.T) {
func TestHypervisorDefaultsImage(t *testing.T) {
assert := assert.New(t)
tmpdir, err := ioutil.TempDir(testDir, "")
tmpdir, err := os.MkdirTemp(testDir, "")
assert.NoError(err)
defer os.RemoveAll(tmpdir)
@@ -1142,7 +1141,7 @@ func TestGetDefaultConfigFilePaths(t *testing.T) {
func TestGetDefaultConfigFile(t *testing.T) {
assert := assert.New(t)
tmpdir, err := ioutil.TempDir(testDir, "")
tmpdir, err := os.MkdirTemp(testDir, "")
assert.NoError(err)
defer os.RemoveAll(tmpdir)
@@ -1232,7 +1231,7 @@ func TestDefaultFirmware(t *testing.T) {
// save default firmware path
oldDefaultFirmwarePath := defaultFirmwarePath
f, err := ioutil.TempFile(os.TempDir(), "qboot.bin")
f, err := os.CreateTemp(os.TempDir(), "qboot.bin")
assert.NoError(err)
assert.NoError(f.Close())
defer os.RemoveAll(f.Name())
@@ -1420,7 +1419,7 @@ func TestUpdateRuntimeConfigurationInvalidKernelParams(t *testing.T) {
func TestCheckHypervisorConfig(t *testing.T) {
assert := assert.New(t)
dir, err := ioutil.TempDir(testDir, "")
dir, err := os.MkdirTemp(testDir, "")
if err != nil {
t.Fatal(err)
}
@@ -1583,11 +1582,11 @@ func TestCheckFactoryConfig(t *testing.T) {
func TestValidateBindMounts(t *testing.T) {
assert := assert.New(t)
tmpdir1, err := ioutil.TempDir(testDir, "tmp1-")
tmpdir1, err := os.MkdirTemp(testDir, "tmp1-")
assert.NoError(err)
defer os.RemoveAll(tmpdir1)
tmpdir2, err := ioutil.TempDir(testDir, "tmp2-")
tmpdir2, err := os.MkdirTemp(testDir, "tmp2-")
assert.NoError(err)
defer os.RemoveAll(tmpdir2)
@@ -1595,13 +1594,13 @@ func TestValidateBindMounts(t *testing.T) {
duplicate2 := filepath.Join(tmpdir2, "cat.txt")
unique := filepath.Join(tmpdir1, "foobar.txt")
err = ioutil.WriteFile(duplicate1, []byte("kibble-monster"), 0644)
err = os.WriteFile(duplicate1, []byte("kibble-monster"), 0644)
assert.NoError(err)
err = ioutil.WriteFile(duplicate2, []byte("furbag"), 0644)
err = os.WriteFile(duplicate2, []byte("furbag"), 0644)
assert.NoError(err)
err = ioutil.WriteFile(unique, []byte("fuzzball"), 0644)
err = os.WriteFile(unique, []byte("fuzzball"), 0644)
assert.NoError(err)
type testData struct {

View File

@@ -9,7 +9,7 @@ package katautils
import (
"context"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
@@ -183,7 +183,7 @@ func CreateSandbox(ctx context.Context, vci vc.VC, ociSpec specs.Spec, runtimeCo
var procFIPS = "/proc/sys/crypto/fips_enabled"
func checkForFIPS(sandboxConfig *vc.SandboxConfig) error {
content, err := ioutil.ReadFile(procFIPS)
content, err := os.ReadFile(procFIPS)
if err != nil {
// In case file cannot be found or read, simply return
return nil

View File

@@ -10,7 +10,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
@@ -124,7 +123,7 @@ func TestSetEphemeralStorageType(t *testing.T) {
assert := assert.New(t)
dir, err := ioutil.TempDir(testDir, "foo")
dir, err := os.MkdirTemp(testDir, "foo")
if err != nil {
t.Fatal(err)
}
@@ -268,7 +267,7 @@ func TestCreateSandboxFail(t *testing.T) {
func TestCheckForFips(t *testing.T) {
assert := assert.New(t)
path, err := ioutil.TempDir("", "")
path, err := os.MkdirTemp("", "")
assert.NoError(err)
defer os.RemoveAll(path)
@@ -278,7 +277,7 @@ func TestCheckForFips(t *testing.T) {
procFIPS = val
}()
err = ioutil.WriteFile(procFIPS, []byte("1"), 0644)
err = os.WriteFile(procFIPS, []byte("1"), 0644)
assert.NoError(err)
hconfig := vc.HypervisorConfig{
@@ -297,7 +296,7 @@ func TestCheckForFips(t *testing.T) {
assert.Equal(params[1].Value, "1")
config.HypervisorConfig = hconfig
err = ioutil.WriteFile(procFIPS, []byte("unexpected contents"), 0644)
err = os.WriteFile(procFIPS, []byte("unexpected contents"), 0644)
assert.NoError(err)
assert.NoError(checkForFIPS(&config))
assert.Equal(config.HypervisorConfig, hconfig)

View File

@@ -8,7 +8,7 @@ package katautils
import (
"fmt"
"io/ioutil"
"io"
"regexp"
"strings"
"testing"
@@ -29,7 +29,7 @@ func init() {
kataUtilsLogger.Logger.Level = logrus.DebugLevel
// Discard log output
kataUtilsLogger.Logger.Out = ioutil.Discard
kataUtilsLogger.Logger.Out = io.Discard
}
func TestHandleSystemLog(t *testing.T) {
@@ -71,7 +71,7 @@ func TestNewSystemLogHook(t *testing.T) {
// throw away all stdout so that the Format() call
// below returns the data in structured form.
logger.Out = ioutil.Discard
logger.Out = io.Discard
entry := &logrus.Entry{
Logger: logger,

View File

@@ -7,7 +7,6 @@ package katautils
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"syscall"
@@ -24,7 +23,7 @@ import (
func TestGetNetNsFromBindMount(t *testing.T) {
assert := assert.New(t)
tmpdir, err := ioutil.TempDir("", "")
tmpdir, err := os.MkdirTemp("", "")
assert.NoError(err)
defer os.RemoveAll(tmpdir)
@@ -53,7 +52,7 @@ func TestGetNetNsFromBindMount(t *testing.T) {
}
for i, d := range data {
err := ioutil.WriteFile(mountFile, []byte(d.contents), 0640)
err := os.WriteFile(mountFile, []byte(d.contents), 0640)
assert.NoError(err)
path, err := getNetNsFromBindMount(tmpNSPath, mountFile)
@@ -86,7 +85,7 @@ func TestHostNetworkingRequested(t *testing.T) {
assert.Error(err)
// Bind-mounted Netns
tmpdir, err := ioutil.TempDir("", "")
tmpdir, err := os.MkdirTemp("", "")
assert.NoError(err)
defer os.RemoveAll(tmpdir)

View File

@@ -9,7 +9,6 @@ package katautils
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
@@ -99,7 +98,7 @@ func WriteFile(filePath string, data string, fileMode os.FileMode) error {
return fmt.Errorf("no such file for %s", filePath)
}
if err := ioutil.WriteFile(filePath, []byte(data), fileMode); err != nil {
if err := os.WriteFile(filePath, []byte(data), fileMode); err != nil {
return fmt.Errorf("failed to write %v to %v: %v", data, filePath, err)
}
@@ -108,7 +107,7 @@ func WriteFile(filePath string, data string, fileMode os.FileMode) error {
// GetFileContents return the file contents as a string.
func GetFileContents(file string) (string, error) {
bytes, err := ioutil.ReadFile(file)
bytes, err := os.ReadFile(file)
if err != nil {
return "", err
}

View File

@@ -8,7 +8,6 @@ package katautils
import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
@@ -32,11 +31,11 @@ var (
)
func createFile(file, contents string) error {
return ioutil.WriteFile(file, []byte(contents), testFileMode)
return os.WriteFile(file, []byte(contents), testFileMode)
}
func createEmptyFile(path string) (err error) {
return ioutil.WriteFile(path, []byte(""), testFileMode)
return os.WriteFile(path, []byte(""), testFileMode)
}
func TestUtilsResolvePathEmptyPath(t *testing.T) {
@@ -45,7 +44,7 @@ func TestUtilsResolvePathEmptyPath(t *testing.T) {
}
func TestUtilsResolvePathValidPath(t *testing.T) {
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
@@ -77,7 +76,7 @@ func TestUtilsResolvePathValidPath(t *testing.T) {
}
func TestUtilsResolvePathENOENT(t *testing.T) {
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
@@ -112,7 +111,7 @@ func TestUtilsResolvePathENOENT(t *testing.T) {
func TestFileSize(t *testing.T) {
assert := assert.New(t)
dir, err := ioutil.TempDir(testDir, "")
dir, err := os.MkdirTemp(testDir, "")
if err != nil {
t.Fatal(err)
}
@@ -153,7 +152,7 @@ func TestWriteFileErrWriteFail(t *testing.T) {
func TestWriteFileErrNoPath(t *testing.T) {
assert := assert.New(t)
dir, err := ioutil.TempDir(testDir, "")
dir, err := os.MkdirTemp(testDir, "")
assert.NoError(err)
defer os.RemoveAll(dir)
@@ -178,7 +177,7 @@ func TestGetFileContents(t *testing.T) {
{"processor : 0\nvendor_id : GenuineIntel\n"},
}
dir, err := ioutil.TempDir(testDir, "")
dir, err := os.MkdirTemp(testDir, "")
if err != nil {
t.Fatal(err)
}
@@ -192,7 +191,7 @@ func TestGetFileContents(t *testing.T) {
for _, d := range data {
// create the file
err = ioutil.WriteFile(file, []byte(d.contents), testFileMode)
err = os.WriteFile(file, []byte(d.contents), testFileMode)
if err != nil {
t.Fatal(err)
}

View File

@@ -17,7 +17,7 @@ import (
"strings"
"syscall"
criContainerdAnnotations "github.com/containerd/cri-containerd/pkg/annotations"
ctrAnnotations "github.com/containerd/containerd/pkg/cri/annotations"
crioAnnotations "github.com/cri-o/cri-o/pkg/annotations"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
@@ -42,19 +42,19 @@ var (
// CRIContainerTypeKeyList lists all the CRI keys that could define
// the container type from annotations in the config.json.
CRIContainerTypeKeyList = []string{criContainerdAnnotations.ContainerType, crioAnnotations.ContainerType, dockershimAnnotations.ContainerTypeLabelKey}
CRIContainerTypeKeyList = []string{ctrAnnotations.ContainerType, crioAnnotations.ContainerType, dockershimAnnotations.ContainerTypeLabelKey}
// CRISandboxNameKeyList lists all the CRI keys that could define
// the sandbox ID (sandbox ID) from annotations in the config.json.
CRISandboxNameKeyList = []string{criContainerdAnnotations.SandboxID, crioAnnotations.SandboxID, dockershimAnnotations.SandboxIDLabelKey}
CRISandboxNameKeyList = []string{ctrAnnotations.SandboxID, crioAnnotations.SandboxID, dockershimAnnotations.SandboxIDLabelKey}
// CRIContainerTypeList lists all the maps from CRI ContainerTypes annotations
// to a virtcontainers ContainerType.
CRIContainerTypeList = []annotationContainerType{
{crioAnnotations.ContainerTypeSandbox, vc.PodSandbox},
{crioAnnotations.ContainerTypeContainer, vc.PodContainer},
{criContainerdAnnotations.ContainerTypeSandbox, vc.PodSandbox},
{criContainerdAnnotations.ContainerTypeContainer, vc.PodContainer},
{ctrAnnotations.ContainerTypeSandbox, vc.PodSandbox},
{ctrAnnotations.ContainerTypeContainer, vc.PodContainer},
{dockershimAnnotations.ContainerTypeLabelSandbox, vc.PodSandbox},
{dockershimAnnotations.ContainerTypeLabelContainer, vc.PodContainer},
}
@@ -320,7 +320,7 @@ func networkConfig(ocispec specs.Spec, config RuntimeConfig) (vc.NetworkConfig,
}
// ContainerType returns the type of container and if the container type was
// found from CRI servers annotations.
// found from CRI server's annotations in the container spec.
func ContainerType(spec specs.Spec) (vc.ContainerType, error) {
for _, key := range CRIContainerTypeKeyList {
containerTypeVal, ok := spec.Annotations[key]
@@ -334,11 +334,10 @@ func ContainerType(spec specs.Spec) (vc.ContainerType, error) {
}
}
return vc.UnknownContainerType, fmt.Errorf("Unknown container type %s", containerTypeVal)
}
return vc.PodSandbox, nil
return vc.SingleContainer, nil
}
func GetSandboxConfigPath(annotations map[string]string) string {

View File

@@ -7,7 +7,6 @@ package oci
import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
@@ -16,7 +15,7 @@ import (
"strings"
"testing"
"github.com/cri-o/cri-o/pkg/annotations"
ctrAnnotations "github.com/containerd/containerd/pkg/cri/annotations"
crioAnnotations "github.com/cri-o/cri-o/pkg/annotations"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
@@ -25,6 +24,7 @@ import (
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
vcAnnotations "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations"
dockerAnnotations "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations/dockershim"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/compatoci"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
)
@@ -44,7 +44,7 @@ var (
func createConfig(fileName string, fileData string) (string, error) {
configPath := path.Join(tempBundlePath, fileName)
err := ioutil.WriteFile(configPath, []byte(fileData), fileMode)
err := os.WriteFile(configPath, []byte(fileData), fileMode)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to create config file %s %v\n", configPath, err)
return "", err
@@ -152,7 +152,7 @@ func TestMinimalSandboxConfig(t *testing.T) {
Cmd: expectedCmd,
Annotations: map[string]string{
vcAnnotations.BundlePathKey: tempBundlePath,
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
vcAnnotations.ContainerTypeKey: string(vc.SingleContainer),
},
Mounts: expectedMounts,
DeviceInfos: expectedDeviceInfo,
@@ -188,51 +188,100 @@ func TestMinimalSandboxConfig(t *testing.T) {
assert.NoError(os.Remove(configPath))
}
func testContainerTypeSuccessful(t *testing.T, ociSpec specs.Spec, expected vc.ContainerType) {
containerType, err := ContainerType(ociSpec)
func TestContainerType(t *testing.T) {
assert := assert.New(t)
assert.NoError(err)
assert.Equal(containerType, expected)
}
func TestContainerTypePodSandbox(t *testing.T) {
var ociSpec specs.Spec
ociSpec.Annotations = map[string]string{
annotations.ContainerType: annotations.ContainerTypeSandbox,
tests := []struct {
description string
annotationKey string
annotationValue string
expectedType vc.ContainerType
expectedErr bool
}{
{
description: "no annotation, expect single container",
annotationKey: "",
annotationValue: "",
expectedType: vc.SingleContainer,
expectedErr: false,
},
{
description: "unexpected annotation, expect error",
annotationKey: ctrAnnotations.ContainerType,
annotationValue: "foo",
expectedType: vc.UnknownContainerType,
expectedErr: true,
},
{
description: "containerd sandbox",
annotationKey: ctrAnnotations.ContainerType,
annotationValue: string(ctrAnnotations.ContainerTypeSandbox),
expectedType: vc.PodSandbox,
expectedErr: false,
},
{
description: "containerd container",
annotationKey: ctrAnnotations.ContainerType,
annotationValue: string(ctrAnnotations.ContainerTypeContainer),
expectedType: vc.PodContainer,
expectedErr: false,
},
{
description: "crio unexpected annotation, expect error",
annotationKey: crioAnnotations.ContainerType,
annotationValue: "foo",
expectedType: vc.UnknownContainerType,
expectedErr: true,
},
{
description: "crio sandbox",
annotationKey: crioAnnotations.ContainerType,
annotationValue: string(crioAnnotations.ContainerTypeSandbox),
expectedType: vc.PodSandbox,
expectedErr: false,
},
{
description: "crio container",
annotationKey: crioAnnotations.ContainerType,
annotationValue: string(crioAnnotations.ContainerTypeContainer),
expectedType: vc.PodContainer,
expectedErr: false,
},
{
description: "dockershim unexpected annotation, expect error",
annotationKey: dockerAnnotations.ContainerTypeLabelKey,
annotationValue: "foo",
expectedType: vc.UnknownContainerType,
expectedErr: true,
},
{
description: "dockershim sandbox",
annotationKey: dockerAnnotations.ContainerTypeLabelKey,
annotationValue: string(dockerAnnotations.ContainerTypeLabelSandbox),
expectedType: vc.PodSandbox,
expectedErr: false,
},
{
description: "dockershim container",
annotationKey: dockerAnnotations.ContainerTypeLabelKey,
annotationValue: string(dockerAnnotations.ContainerTypeLabelContainer),
expectedType: vc.PodContainer,
expectedErr: false,
},
}
testContainerTypeSuccessful(t, ociSpec, vc.PodSandbox)
}
func TestContainerTypePodContainer(t *testing.T) {
var ociSpec specs.Spec
ociSpec.Annotations = map[string]string{
annotations.ContainerType: annotations.ContainerTypeContainer,
for _, tt := range tests {
ociSpec := specs.Spec{
Annotations: map[string]string{
tt.annotationKey: tt.annotationValue,
},
}
containerType, err := ContainerType(ociSpec)
if tt.expectedErr {
assert.Error(err)
} else {
assert.NoError(err)
}
assert.Equal(tt.expectedType, containerType, "test fail: %v", tt.description)
}
testContainerTypeSuccessful(t, ociSpec, vc.PodContainer)
}
func TestContainerTypePodSandboxEmptyAnnotation(t *testing.T) {
testContainerTypeSuccessful(t, specs.Spec{}, vc.PodSandbox)
}
func TestContainerTypeFailure(t *testing.T) {
var ociSpec specs.Spec
expected := vc.UnknownContainerType
unknownType := "unknown_type"
assert := assert.New(t)
ociSpec.Annotations = map[string]string{
annotations.ContainerType: unknownType,
}
containerType, err := ContainerType(ociSpec)
assert.Error(err)
assert.Equal(containerType, expected)
}
func TestSandboxIDSuccessful(t *testing.T) {
@@ -241,7 +290,7 @@ func TestSandboxIDSuccessful(t *testing.T) {
assert := assert.New(t)
ociSpec.Annotations = map[string]string{
annotations.SandboxID: testSandboxID,
crioAnnotations.SandboxID: testSandboxID,
}
sandboxID, err := SandboxID(ociSpec)
@@ -361,7 +410,7 @@ func TestGetShmSizeBindMounted(t *testing.T) {
t.Skip("Test disabled as requires root privileges")
}
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
assert.Nil(t, err)
defer os.RemoveAll(dir)
@@ -399,7 +448,7 @@ func TestGetShmSizeBindMounted(t *testing.T) {
func TestMain(m *testing.M) {
var err error
tempRoot, err = ioutil.TempDir("", "virtc-")
tempRoot, err = os.MkdirTemp("", "virtc-")
if err != nil {
panic(err)
}
@@ -424,7 +473,7 @@ func TestMain(m *testing.M) {
func TestAddAssetAnnotations(t *testing.T) {
assert := assert.New(t)
tmpdir, err := ioutil.TempDir("", "")
tmpdir, err := os.MkdirTemp("", "")
assert.NoError(err)
defer os.RemoveAll(tmpdir)
@@ -432,7 +481,7 @@ func TestAddAssetAnnotations(t *testing.T) {
// (required since the existence of binary asset annotations is verified).
fakeAssetFile := filepath.Join(tmpdir, "fake-binary")
err = ioutil.WriteFile(fakeAssetFile, []byte(""), fileMode)
err = os.WriteFile(fakeAssetFile, []byte(""), fileMode)
assert.NoError(err)
expectedAnnotations := map[string]string{

View File

@@ -7,7 +7,6 @@ package utils
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path"
@@ -52,7 +51,7 @@ func TestGzipAccepted(t *testing.T) {
func TestEnsureDir(t *testing.T) {
const testMode = 0755
tmpdir, err := ioutil.TempDir("", "TestEnsureDir")
tmpdir, err := os.MkdirTemp("", "TestEnsureDir")
assert := assert.New(t)
assert.NoError(err)
@@ -121,7 +120,7 @@ func TestEnsureDir(t *testing.T) {
func TestFirstValidExecutable(t *testing.T) {
assert := assert.New(t)
tmpdir, err := ioutil.TempDir("", "TestFirstValidPath")
tmpdir, err := os.MkdirTemp("", "TestFirstValidPath")
assert.NoError(err)
defer os.RemoveAll(tmpdir)
@@ -145,7 +144,7 @@ func TestFirstValidExecutable(t *testing.T) {
err := os.MkdirAll(path.Join(tmpdir, "a", "b"), 0755)
assert.NoError(err)
// create a non-executable file
err = ioutil.WriteFile(path.Join(tmpdir, "a", "b", "c"), []byte("test\n"), 0644)
err = os.WriteFile(path.Join(tmpdir, "a", "b", "c"), []byte("test\n"), 0644)
assert.NoError(err)
},
paths: []string{path.Join(tmpdir, "a", "b", "c"), "c/d"},
@@ -158,7 +157,7 @@ func TestFirstValidExecutable(t *testing.T) {
err := os.MkdirAll(path.Join(tmpdir, "d", "e"), 0755)
assert.NoError(err)
// create an executable file
err = ioutil.WriteFile(path.Join(tmpdir, "d", "e", "f"), []byte("test\n"), 0755)
err = os.WriteFile(path.Join(tmpdir, "d", "e", "f"), []byte("test\n"), 0755)
assert.NoError(err)
},
paths: []string{path.Join(tmpdir, "d", "e", "f"), "c/d"},
@@ -171,7 +170,7 @@ func TestFirstValidExecutable(t *testing.T) {
err := os.MkdirAll(path.Join(tmpdir, "g", "h"), 0755)
assert.NoError(err)
// create an executable file
err = ioutil.WriteFile(path.Join(tmpdir, "g", "h", "i"), []byte("test\n"), 0755)
err = os.WriteFile(path.Join(tmpdir, "g", "h", "i"), []byte("test\n"), 0755)
assert.NoError(err)
},
paths: []string{"c/d", path.Join(tmpdir, "g", "h", "i")},