From 6e53ffb105e19c49bf67fe5fd5622619cd3c82cf Mon Sep 17 00:00:00 2001 From: Samuel Karp Date: Mon, 20 Jun 2022 15:11:28 -0700 Subject: [PATCH] ctr: add --hostname flag to create, run Signed-off-by: Samuel Karp --- cmd/ctr/commands/commands.go | 4 ++++ cmd/ctr/commands/run/run_unix.go | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/ctr/commands/commands.go b/cmd/ctr/commands/commands.go index 372f7cbc2..faa9fcd51 100644 --- a/cmd/ctr/commands/commands.go +++ b/cmd/ctr/commands/commands.go @@ -201,6 +201,10 @@ var ( Name: "rdt-class", Usage: "name of the RDT class to associate the container with. Specifies a Class of Service (CLOS) for cache and memory bandwidth management.", }, + cli.StringFlag{ + Name: "hostname", + Usage: "set the container's host name", + }, } ) diff --git a/cmd/ctr/commands/run/run_unix.go b/cmd/ctr/commands/run/run_unix.go index d9c892ec1..12b467b7c 100644 --- a/cmd/ctr/commands/run/run_unix.go +++ b/cmd/ctr/commands/run/run_unix.go @@ -106,7 +106,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli } else { var ( ref = context.Args().First() - //for container's id is Args[1] + // for container's id is Args[1] args = context.Args()[2:] ) opts = append(opts, oci.WithDefaultSpec(), oci.WithDefaultUnixDevices) @@ -346,6 +346,9 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli if c := context.String("rdt-class"); c != "" { opts = append(opts, oci.WithRdt(c, "", "")) } + if hostname := context.String("hostname"); hostname != "" { + opts = append(opts, oci.WithHostname(hostname)) + } } runtimeOpts, err := getRuntimeOptions(context)