From 229779a4e5c49c9f8a0c7b15d75f392cd733f713 Mon Sep 17 00:00:00 2001 From: Danny Canter Date: Mon, 26 Dec 2022 03:17:41 -0500 Subject: [PATCH] oci: Add WithDomainname A domainname field was recently added to the OCI spec. Prior to this folks would need to set this with a sysctl, but now runtimes should be able to setdomainname(2). There's an open change to runc at the moment to add support for this so I've just left testing as a couple spec validations in CRI until that's in and usable. Signed-off-by: Danny Canter --- oci/spec_opts.go | 8 ++++++++ pkg/cri/sbserver/container_create_test.go | 10 ++++++++-- pkg/cri/server/container_create_test.go | 10 ++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/oci/spec_opts.go b/oci/spec_opts.go index 2d7ba0a3c..5394feeba 100644 --- a/oci/spec_opts.go +++ b/oci/spec_opts.go @@ -274,6 +274,14 @@ func WithHostname(name string) SpecOpts { } } +// WithDomainname sets the container's NIS domain name +func WithDomainname(name string) SpecOpts { + return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error { + s.Domainname = name + return nil + } +} + // WithMounts appends mounts func WithMounts(mounts []specs.Mount) SpecOpts { return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error { diff --git a/pkg/cri/sbserver/container_create_test.go b/pkg/cri/sbserver/container_create_test.go index 65e42b34d..1019fb601 100644 --- a/pkg/cri/sbserver/container_create_test.go +++ b/pkg/cri/sbserver/container_create_test.go @@ -412,11 +412,17 @@ func TestBaseRuntimeSpec(t *testing.T) { }, } - out, err := c.runtimeSpec("id1", "/etc/containerd/cri-base.json", oci.WithHostname("new")) + out, err := c.runtimeSpec( + "id1", + "/etc/containerd/cri-base.json", + oci.WithHostname("new-host"), + oci.WithDomainname("new-domain"), + ) assert.NoError(t, err) assert.Equal(t, "1.0.2", out.Version) - assert.Equal(t, "new", out.Hostname) + assert.Equal(t, "new-host", out.Hostname) + assert.Equal(t, "new-domain", out.Domainname) // Make sure original base spec not changed assert.NotEqual(t, out, c.baseOCISpecs["/etc/containerd/cri-base.json"]) diff --git a/pkg/cri/server/container_create_test.go b/pkg/cri/server/container_create_test.go index 151751b5f..0bec679e3 100644 --- a/pkg/cri/server/container_create_test.go +++ b/pkg/cri/server/container_create_test.go @@ -412,11 +412,17 @@ func TestBaseRuntimeSpec(t *testing.T) { }, } - out, err := c.runtimeSpec("id1", "/etc/containerd/cri-base.json", oci.WithHostname("new")) + out, err := c.runtimeSpec( + "id1", + "/etc/containerd/cri-base.json", + oci.WithHostname("new-host"), + oci.WithDomainname("new-domain"), + ) assert.NoError(t, err) assert.Equal(t, "1.0.2", out.Version) - assert.Equal(t, "new", out.Hostname) + assert.Equal(t, "new-host", out.Hostname) + assert.Equal(t, "new-domain", out.Domainname) // Make sure original base spec not changed assert.NotEqual(t, out, c.baseOCISpecs["/etc/containerd/cri-base.json"])