Merge pull request #5002 from crosbymichael/anno-image-name
[cri] add image-name annotation
This commit is contained in:
commit
b3f2402062
@ -53,4 +53,6 @@ const (
|
|||||||
|
|
||||||
// ContainerName is the name of the container in the pod
|
// ContainerName is the name of the container in the pod
|
||||||
ContainerName = "io.kubernetes.cri.container-name"
|
ContainerName = "io.kubernetes.cri.container-name"
|
||||||
|
// ImageName is the name of the image used to create the container
|
||||||
|
ImageName = "io.kubernetes.cri.image-name"
|
||||||
)
|
)
|
||||||
|
@ -155,7 +155,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
|||||||
}
|
}
|
||||||
log.G(ctx).Debugf("Use OCI runtime %+v for sandbox %q and container %q", ociRuntime, sandboxID, id)
|
log.G(ctx).Debugf("Use OCI runtime %+v for sandbox %q and container %q", ociRuntime, sandboxID, id)
|
||||||
|
|
||||||
spec, err := c.containerSpec(id, sandboxID, sandboxPid, sandbox.NetNSPath, containerName, config, sandboxConfig,
|
spec, err := c.containerSpec(id, sandboxID, sandboxPid, sandbox.NetNSPath, containerName, containerdImage.Name(), config, sandboxConfig,
|
||||||
&image.ImageSpec.Config, append(mounts, volumeMounts...), ociRuntime)
|
&image.ImageSpec.Config, append(mounts, volumeMounts...), ociRuntime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to generate container %q spec", id)
|
return nil, errors.Wrapf(err, "failed to generate container %q spec", id)
|
||||||
|
@ -108,10 +108,19 @@ func (c *criService) containerMounts(sandboxID string, config *runtime.Container
|
|||||||
return mounts
|
return mounts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *criService) containerSpec(id string, sandboxID string, sandboxPid uint32, netNSPath string, containerName string,
|
func (c *criService) containerSpec(
|
||||||
config *runtime.ContainerConfig, sandboxConfig *runtime.PodSandboxConfig, imageConfig *imagespec.ImageConfig,
|
id string,
|
||||||
extraMounts []*runtime.Mount, ociRuntime config.Runtime) (_ *runtimespec.Spec, retErr error) {
|
sandboxID string,
|
||||||
|
sandboxPid uint32,
|
||||||
|
netNSPath string,
|
||||||
|
containerName string,
|
||||||
|
imageName string,
|
||||||
|
config *runtime.ContainerConfig,
|
||||||
|
sandboxConfig *runtime.PodSandboxConfig,
|
||||||
|
imageConfig *imagespec.ImageConfig,
|
||||||
|
extraMounts []*runtime.Mount,
|
||||||
|
ociRuntime config.Runtime,
|
||||||
|
) (_ *runtimespec.Spec, retErr error) {
|
||||||
specOpts := []oci.SpecOpts{
|
specOpts := []oci.SpecOpts{
|
||||||
customopts.WithoutRunMount,
|
customopts.WithoutRunMount,
|
||||||
}
|
}
|
||||||
@ -263,6 +272,7 @@ func (c *criService) containerSpec(id string, sandboxID string, sandboxPid uint3
|
|||||||
customopts.WithAnnotation(annotations.SandboxNamespace, sandboxConfig.GetMetadata().GetNamespace()),
|
customopts.WithAnnotation(annotations.SandboxNamespace, sandboxConfig.GetMetadata().GetNamespace()),
|
||||||
customopts.WithAnnotation(annotations.SandboxName, sandboxConfig.GetMetadata().GetName()),
|
customopts.WithAnnotation(annotations.SandboxName, sandboxConfig.GetMetadata().GetName()),
|
||||||
customopts.WithAnnotation(annotations.ContainerName, containerName),
|
customopts.WithAnnotation(annotations.ContainerName, containerName),
|
||||||
|
customopts.WithAnnotation(annotations.ImageName, imageName),
|
||||||
)
|
)
|
||||||
// cgroupns is used for hiding /sys/fs/cgroup from containers.
|
// cgroupns is used for hiding /sys/fs/cgroup from containers.
|
||||||
// For compatibility, cgroupns is not used when running in cgroup v1 mode or in privileged.
|
// For compatibility, cgroupns is not used when running in cgroup v1 mode or in privileged.
|
||||||
|
@ -179,6 +179,9 @@ func getCreateContainerTestData() (*runtime.ContainerConfig, *runtime.PodSandbox
|
|||||||
|
|
||||||
assert.Contains(t, spec.Annotations, annotations.SandboxName)
|
assert.Contains(t, spec.Annotations, annotations.SandboxName)
|
||||||
assert.EqualValues(t, spec.Annotations[annotations.SandboxName], "test-sandbox-name")
|
assert.EqualValues(t, spec.Annotations[annotations.SandboxName], "test-sandbox-name")
|
||||||
|
|
||||||
|
assert.Contains(t, spec.Annotations, annotations.ImageName)
|
||||||
|
assert.EqualValues(t, spec.Annotations[annotations.ImageName], testImageName)
|
||||||
}
|
}
|
||||||
return config, sandboxConfig, imageConfig, specCheck
|
return config, sandboxConfig, imageConfig, specCheck
|
||||||
}
|
}
|
||||||
@ -236,7 +239,7 @@ func TestContainerCapabilities(t *testing.T) {
|
|||||||
c := newTestCRIService()
|
c := newTestCRIService()
|
||||||
|
|
||||||
containerConfig.Linux.SecurityContext.Capabilities = test.capability
|
containerConfig.Linux.SecurityContext.Capabilities = test.capability
|
||||||
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if selinux.GetEnabled() {
|
if selinux.GetEnabled() {
|
||||||
@ -271,7 +274,7 @@ func TestContainerSpecTty(t *testing.T) {
|
|||||||
c := newTestCRIService()
|
c := newTestCRIService()
|
||||||
for _, tty := range []bool{true, false} {
|
for _, tty := range []bool{true, false} {
|
||||||
containerConfig.Tty = tty
|
containerConfig.Tty = tty
|
||||||
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
specCheck(t, testID, testSandboxID, testPid, spec)
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
||||||
assert.Equal(t, tty, spec.Process.Terminal)
|
assert.Equal(t, tty, spec.Process.Terminal)
|
||||||
@ -298,7 +301,7 @@ func TestContainerSpecDefaultPath(t *testing.T) {
|
|||||||
imageConfig.Env = append(imageConfig.Env, pathenv)
|
imageConfig.Env = append(imageConfig.Env, pathenv)
|
||||||
expected = pathenv
|
expected = pathenv
|
||||||
}
|
}
|
||||||
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
specCheck(t, testID, testSandboxID, testPid, spec)
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
||||||
assert.Contains(t, spec.Process.Env, expected)
|
assert.Contains(t, spec.Process.Env, expected)
|
||||||
@ -315,7 +318,7 @@ func TestContainerSpecReadonlyRootfs(t *testing.T) {
|
|||||||
c := newTestCRIService()
|
c := newTestCRIService()
|
||||||
for _, readonly := range []bool{true, false} {
|
for _, readonly := range []bool{true, false} {
|
||||||
containerConfig.Linux.SecurityContext.ReadonlyRootfs = readonly
|
containerConfig.Linux.SecurityContext.ReadonlyRootfs = readonly
|
||||||
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
specCheck(t, testID, testSandboxID, testPid, spec)
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
||||||
assert.Equal(t, readonly, spec.Root.Readonly)
|
assert.Equal(t, readonly, spec.Root.Readonly)
|
||||||
@ -354,7 +357,7 @@ func TestContainerSpecWithExtraMounts(t *testing.T) {
|
|||||||
Readonly: false,
|
Readonly: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, extraMounts, ociRuntime)
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, extraMounts, ociRuntime)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
specCheck(t, testID, testSandboxID, testPid, spec)
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
||||||
var mounts, sysMounts, devMounts []runtimespec.Mount
|
var mounts, sysMounts, devMounts []runtimespec.Mount
|
||||||
@ -422,7 +425,7 @@ func TestContainerAndSandboxPrivileged(t *testing.T) {
|
|||||||
sandboxConfig.Linux.SecurityContext = &runtime.LinuxSandboxSecurityContext{
|
sandboxConfig.Linux.SecurityContext = &runtime.LinuxSandboxSecurityContext{
|
||||||
Privileged: test.sandboxPrivileged,
|
Privileged: test.sandboxPrivileged,
|
||||||
}
|
}
|
||||||
_, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
_, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
||||||
if test.expectError {
|
if test.expectError {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
} else {
|
} else {
|
||||||
@ -613,7 +616,7 @@ func TestPrivilegedBindMount(t *testing.T) {
|
|||||||
containerConfig.Linux.SecurityContext.Privileged = test.privileged
|
containerConfig.Linux.SecurityContext.Privileged = test.privileged
|
||||||
sandboxConfig.Linux.SecurityContext.Privileged = test.privileged
|
sandboxConfig.Linux.SecurityContext.Privileged = test.privileged
|
||||||
|
|
||||||
spec, err := c.containerSpec(t.Name(), testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
spec, err := c.containerSpec(t.Name(), testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
if test.expectedSysFSRO {
|
if test.expectedSysFSRO {
|
||||||
@ -770,7 +773,7 @@ func TestPidNamespace(t *testing.T) {
|
|||||||
} {
|
} {
|
||||||
t.Logf("TestCase %q", desc)
|
t.Logf("TestCase %q", desc)
|
||||||
containerConfig.Linux.SecurityContext.NamespaceOptions = &runtime.NamespaceOption{Pid: test.pidNS}
|
containerConfig.Linux.SecurityContext.NamespaceOptions = &runtime.NamespaceOption{Pid: test.pidNS}
|
||||||
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Contains(t, spec.Linux.Namespaces, test.expected)
|
assert.Contains(t, spec.Linux.Namespaces, test.expected)
|
||||||
}
|
}
|
||||||
@ -785,7 +788,7 @@ func TestNoDefaultRunMount(t *testing.T) {
|
|||||||
ociRuntime := config.Runtime{}
|
ociRuntime := config.Runtime{}
|
||||||
c := newTestCRIService()
|
c := newTestCRIService()
|
||||||
|
|
||||||
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
for _, mount := range spec.Mounts {
|
for _, mount := range spec.Mounts {
|
||||||
assert.NotEqual(t, "/run", mount.Destination)
|
assert.NotEqual(t, "/run", mount.Destination)
|
||||||
@ -1158,7 +1161,7 @@ func TestMaskedAndReadonlyPaths(t *testing.T) {
|
|||||||
sandboxConfig.Linux.SecurityContext = &runtime.LinuxSandboxSecurityContext{
|
sandboxConfig.Linux.SecurityContext = &runtime.LinuxSandboxSecurityContext{
|
||||||
Privileged: test.privileged,
|
Privileged: test.privileged,
|
||||||
}
|
}
|
||||||
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
if !test.privileged { // specCheck presumes an unprivileged container
|
if !test.privileged { // specCheck presumes an unprivileged container
|
||||||
specCheck(t, testID, testSandboxID, testPid, spec)
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
||||||
@ -1205,7 +1208,7 @@ func TestHostname(t *testing.T) {
|
|||||||
sandboxConfig.Linux.SecurityContext = &runtime.LinuxSandboxSecurityContext{
|
sandboxConfig.Linux.SecurityContext = &runtime.LinuxSandboxSecurityContext{
|
||||||
NamespaceOptions: &runtime.NamespaceOption{Network: test.networkNs},
|
NamespaceOptions: &runtime.NamespaceOption{Network: test.networkNs},
|
||||||
}
|
}
|
||||||
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
specCheck(t, testID, testSandboxID, testPid, spec)
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
||||||
assert.Contains(t, spec.Process.Env, test.expectedEnv)
|
assert.Contains(t, spec.Process.Env, test.expectedEnv)
|
||||||
@ -1217,7 +1220,7 @@ func TestDisableCgroup(t *testing.T) {
|
|||||||
ociRuntime := config.Runtime{}
|
ociRuntime := config.Runtime{}
|
||||||
c := newTestCRIService()
|
c := newTestCRIService()
|
||||||
c.config.DisableCgroup = true
|
c.config.DisableCgroup = true
|
||||||
spec, err := c.containerSpec("test-id", "sandbox-id", 1234, "", "container-name", containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
spec, err := c.containerSpec("test-id", "sandbox-id", 1234, "", "container-name", testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Log("resource limit should not be set")
|
t.Log("resource limit should not be set")
|
||||||
@ -1340,7 +1343,7 @@ func TestPrivilegedDevices(t *testing.T) {
|
|||||||
ociRuntime := config.Runtime{
|
ociRuntime := config.Runtime{
|
||||||
PrivilegedWithoutHostDevices: test.privilegedWithoutHostDevices,
|
PrivilegedWithoutHostDevices: test.privilegedWithoutHostDevices,
|
||||||
}
|
}
|
||||||
spec, err := c.containerSpec(t.Name(), testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
spec, err := c.containerSpec(t.Name(), testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
hostDevicesRaw, err := devices.HostDevices()
|
hostDevicesRaw, err := devices.HostDevices()
|
||||||
@ -1389,7 +1392,7 @@ func TestBaseOCISpec(t *testing.T) {
|
|||||||
testPid := uint32(1234)
|
testPid := uint32(1234)
|
||||||
containerConfig, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
containerConfig, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
||||||
|
|
||||||
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
specCheck(t, testID, testSandboxID, testPid, spec)
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
||||||
|
@ -33,9 +33,19 @@ func (c *criService) containerMounts(sandboxID string, config *runtime.Container
|
|||||||
return []*runtime.Mount{}
|
return []*runtime.Mount{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *criService) containerSpec(id string, sandboxID string, sandboxPid uint32, netNSPath string, containerName string,
|
func (c *criService) containerSpec(
|
||||||
config *runtime.ContainerConfig, sandboxConfig *runtime.PodSandboxConfig, imageConfig *imagespec.ImageConfig,
|
id string,
|
||||||
extraMounts []*runtime.Mount, ociRuntime config.Runtime) (_ *runtimespec.Spec, retErr error) {
|
sandboxID string,
|
||||||
|
sandboxPid uint32,
|
||||||
|
netNSPath string,
|
||||||
|
containerName string,
|
||||||
|
imageName string,
|
||||||
|
config *runtime.ContainerConfig,
|
||||||
|
sandboxConfig *runtime.PodSandboxConfig,
|
||||||
|
imageConfig *imagespec.ImageConfig,
|
||||||
|
extraMounts []*runtime.Mount,
|
||||||
|
ociRuntime config.Runtime,
|
||||||
|
) (_ *runtimespec.Spec, retErr error) {
|
||||||
return c.runtimeSpec(id, ociRuntime.BaseRuntimeSpec)
|
return c.runtimeSpec(id, ociRuntime.BaseRuntimeSpec)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +52,8 @@ func checkMount(t *testing.T, mounts []runtimespec.Mount, src, dest, typ string,
|
|||||||
assert.True(t, found, "mount from %q to %q not found", src, dest)
|
assert.True(t, found, "mount from %q to %q not found", src, dest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const testImageName = "container-image-name"
|
||||||
|
|
||||||
func TestGeneralContainerSpec(t *testing.T) {
|
func TestGeneralContainerSpec(t *testing.T) {
|
||||||
testID := "test-id"
|
testID := "test-id"
|
||||||
testPid := uint32(1234)
|
testPid := uint32(1234)
|
||||||
@ -60,7 +62,7 @@ func TestGeneralContainerSpec(t *testing.T) {
|
|||||||
c := newTestCRIService()
|
c := newTestCRIService()
|
||||||
testSandboxID := "sandbox-id"
|
testSandboxID := "sandbox-id"
|
||||||
testContainerName := "container-name"
|
testContainerName := "container-name"
|
||||||
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
specCheck(t, testID, testSandboxID, testPid, spec)
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
||||||
}
|
}
|
||||||
@ -124,7 +126,7 @@ func TestPodAnnotationPassthroughContainerSpec(t *testing.T) {
|
|||||||
ociRuntime := config.Runtime{
|
ociRuntime := config.Runtime{
|
||||||
PodAnnotations: test.podAnnotations,
|
PodAnnotations: test.podAnnotations,
|
||||||
}
|
}
|
||||||
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName,
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName,
|
||||||
containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, spec)
|
assert.NotNil(t, spec)
|
||||||
@ -372,7 +374,7 @@ func TestContainerAnnotationPassthroughContainerSpec(t *testing.T) {
|
|||||||
PodAnnotations: test.podAnnotations,
|
PodAnnotations: test.podAnnotations,
|
||||||
ContainerAnnotations: test.containerAnnotations,
|
ContainerAnnotations: test.containerAnnotations,
|
||||||
}
|
}
|
||||||
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName,
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName,
|
||||||
containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, spec)
|
assert.NotNil(t, spec)
|
||||||
|
@ -34,9 +34,19 @@ func (c *criService) containerMounts(sandboxID string, config *runtime.Container
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *criService) containerSpec(id string, sandboxID string, sandboxPid uint32, netNSPath string, containerName string,
|
func (c *criService) containerSpec(
|
||||||
config *runtime.ContainerConfig, sandboxConfig *runtime.PodSandboxConfig, imageConfig *imagespec.ImageConfig,
|
id string,
|
||||||
extraMounts []*runtime.Mount, ociRuntime config.Runtime) (*runtimespec.Spec, error) {
|
sandboxID string,
|
||||||
|
sandboxPid uint32,
|
||||||
|
netNSPath string,
|
||||||
|
containerName string,
|
||||||
|
imageName string,
|
||||||
|
config *runtime.ContainerConfig,
|
||||||
|
sandboxConfig *runtime.PodSandboxConfig,
|
||||||
|
imageConfig *imagespec.ImageConfig,
|
||||||
|
extraMounts []*runtime.Mount,
|
||||||
|
ociRuntime config.Runtime,
|
||||||
|
) (*runtimespec.Spec, error) {
|
||||||
specOpts := []oci.SpecOpts{
|
specOpts := []oci.SpecOpts{
|
||||||
customopts.WithProcessArgs(config, imageConfig),
|
customopts.WithProcessArgs(config, imageConfig),
|
||||||
}
|
}
|
||||||
@ -109,6 +119,7 @@ func (c *criService) containerSpec(id string, sandboxID string, sandboxPid uint3
|
|||||||
customopts.WithAnnotation(annotations.SandboxNamespace, sandboxConfig.GetMetadata().GetNamespace()),
|
customopts.WithAnnotation(annotations.SandboxNamespace, sandboxConfig.GetMetadata().GetNamespace()),
|
||||||
customopts.WithAnnotation(annotations.SandboxName, sandboxConfig.GetMetadata().GetName()),
|
customopts.WithAnnotation(annotations.SandboxName, sandboxConfig.GetMetadata().GetName()),
|
||||||
customopts.WithAnnotation(annotations.ContainerName, containerName),
|
customopts.WithAnnotation(annotations.ContainerName, containerName),
|
||||||
|
customopts.WithAnnotation(annotations.ImageName, imageName),
|
||||||
)
|
)
|
||||||
return c.runtimeSpec(id, ociRuntime.BaseRuntimeSpec, specOpts...)
|
return c.runtimeSpec(id, ociRuntime.BaseRuntimeSpec, specOpts...)
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ func TestContainerWindowsNetworkNamespace(t *testing.T) {
|
|||||||
c := newTestCRIService()
|
c := newTestCRIService()
|
||||||
|
|
||||||
containerConfig, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
containerConfig, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
||||||
spec, err := c.containerSpec(testID, testSandboxID, testPid, nsPath, testContainerName, containerConfig, sandboxConfig, imageConfig, nil, config.Runtime{})
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, nsPath, testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, config.Runtime{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, spec)
|
assert.NotNil(t, spec)
|
||||||
specCheck(t, testID, testSandboxID, testPid, spec)
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
||||||
@ -167,7 +167,7 @@ func TestMountCleanPath(t *testing.T) {
|
|||||||
ContainerPath: "c:/test/container-path",
|
ContainerPath: "c:/test/container-path",
|
||||||
HostPath: "c:/test/host-path",
|
HostPath: "c:/test/host-path",
|
||||||
})
|
})
|
||||||
spec, err := c.containerSpec(testID, testSandboxID, testPid, nsPath, testContainerName, containerConfig, sandboxConfig, imageConfig, nil, config.Runtime{})
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, nsPath, testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, config.Runtime{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, spec)
|
assert.NotNil(t, spec)
|
||||||
specCheck(t, testID, testSandboxID, testPid, spec)
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
||||||
@ -187,7 +187,7 @@ func TestMountNamedPipe(t *testing.T) {
|
|||||||
ContainerPath: `\\.\pipe\foo`,
|
ContainerPath: `\\.\pipe\foo`,
|
||||||
HostPath: `\\.\pipe\foo`,
|
HostPath: `\\.\pipe\foo`,
|
||||||
})
|
})
|
||||||
spec, err := c.containerSpec(testID, testSandboxID, testPid, nsPath, testContainerName, containerConfig, sandboxConfig, imageConfig, nil, config.Runtime{})
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, nsPath, testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, config.Runtime{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, spec)
|
assert.NotNil(t, spec)
|
||||||
specCheck(t, testID, testSandboxID, testPid, spec)
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
||||||
|
Loading…
Reference in New Issue
Block a user