@@ -23,16 +23,219 @@ import (
2323 "path/filepath"
2424 "strings"
2525
26+ "github.com/containerd/containerd/v2/defaults"
2627 "github.com/containerd/containerd/v2/pkg/atomicfile"
2728
2829 "github.com/urfave/cli/v2"
2930)
3031
32+ var (
33+ // SnapshotterFlags are cli flags specifying snapshotter names
34+ SnapshotterFlags = []cli.Flag {
35+ & cli.StringFlag {
36+ Name : "snapshotter" ,
37+ Usage : "Snapshotter name. Empty value stands for the default value." ,
38+ EnvVars : []string {"CONTAINERD_SNAPSHOTTER" },
39+ },
40+ }
41+
42+ // SnapshotterLabels are cli flags specifying labels which will be added to the new snapshot for container.
43+ SnapshotterLabels = & cli.StringSliceFlag {
44+ Name : "snapshotter-label" ,
45+ Usage : "Labels added to the new snapshot for this container." ,
46+ }
47+
48+ // LabelFlag is a cli flag specifying labels
49+ LabelFlag = & cli.StringSliceFlag {
50+ Name : "label" ,
51+ Usage : "Labels to attach to the image" ,
52+ }
53+
54+ // RegistryFlags are cli flags specifying registry options
55+ RegistryFlags = []cli.Flag {
56+ & cli.BoolFlag {
57+ Name : "skip-verify" ,
58+ Aliases : []string {"k" },
59+ Usage : "Skip SSL certificate validation" ,
60+ },
61+ & cli.BoolFlag {
62+ Name : "plain-http" ,
63+ Usage : "Allow connections using plain HTTP" ,
64+ },
65+ & cli.StringFlag {
66+ Name : "user" ,
67+ Aliases : []string {"u" },
68+ Usage : "User[:password] Registry user and password" ,
69+ },
70+ & cli.StringFlag {
71+ Name : "refresh" ,
72+ Usage : "Refresh token for authorization server" ,
73+ },
74+ & cli.StringFlag {
75+ Name : "hosts-dir" ,
76+ // compatible with "/etc/docker/certs.d"
77+ Usage : "Custom hosts configuration directory" ,
78+ },
79+ & cli.StringFlag {
80+ Name : "tlscacert" ,
81+ Usage : "Path to TLS root CA" ,
82+ },
83+ & cli.StringFlag {
84+ Name : "tlscert" ,
85+ Usage : "Path to TLS client certificate" ,
86+ },
87+ & cli.StringFlag {
88+ Name : "tlskey" ,
89+ Usage : "Path to TLS client key" ,
90+ },
91+ & cli.BoolFlag {
92+ Name : "http-dump" ,
93+ Usage : "Dump all HTTP request/responses when interacting with container registry" ,
94+ },
95+ & cli.BoolFlag {
96+ Name : "http-trace" ,
97+ Usage : "Enable HTTP tracing for registry interactions" ,
98+ },
99+ }
100+
101+ // RuntimeFlags are cli flags specifying runtime
102+ RuntimeFlags = []cli.Flag {
103+ & cli.StringFlag {
104+ Name : "runtime" ,
105+ Usage : "Runtime name or absolute path to runtime binary" ,
106+ Value : defaults .DefaultRuntime ,
107+ },
108+ & cli.StringFlag {
109+ Name : "runtime-config-path" ,
110+ Usage : "Optional runtime config path" ,
111+ },
112+ }
113+
114+ // ContainerFlags are cli flags specifying container options
115+ ContainerFlags = []cli.Flag {
116+ & cli.StringFlag {
117+ Name : "config" ,
118+ Aliases : []string {"c" },
119+ Usage : "Path to the runtime-specific spec config file" ,
120+ },
121+ & cli.StringFlag {
122+ Name : "cwd" ,
123+ Usage : "Specify the working directory of the process" ,
124+ },
125+ & cli.StringSliceFlag {
126+ Name : "env" ,
127+ Usage : "Specify additional container environment variables (e.g. FOO=bar)" ,
128+ },
129+ & cli.StringFlag {
130+ Name : "env-file" ,
131+ Usage : "Specify additional container environment variables in a file(e.g. FOO=bar, one per line)" ,
132+ },
133+ & cli.StringSliceFlag {
134+ Name : "label" ,
135+ Usage : "Specify additional labels (e.g. foo=bar)" ,
136+ },
137+ & cli.StringSliceFlag {
138+ Name : "annotation" ,
139+ Usage : "Specify additional OCI annotations (e.g. foo=bar)" ,
140+ },
141+ & cli.StringSliceFlag {
142+ Name : "mount" ,
143+ Usage : "Specify additional container mount (e.g. type=bind,src=/tmp,dst=/host,options=rbind:ro)" ,
144+ },
145+ & cli.BoolFlag {
146+ Name : "net-host" ,
147+ Usage : "Enable host networking for the container" ,
148+ },
149+ & cli.BoolFlag {
150+ Name : "privileged" ,
151+ Usage : "Run privileged container" ,
152+ },
153+ & cli.BoolFlag {
154+ Name : "read-only" ,
155+ Usage : "Set the containers filesystem as readonly" ,
156+ },
157+ & cli.StringFlag {
158+ Name : "sandbox" ,
159+ Usage : "Create the container in the given sandbox" ,
160+ },
161+ & cli.BoolFlag {
162+ Name : "tty" ,
163+ Aliases : []string {"t" },
164+ Usage : "Allocate a TTY for the container" ,
165+ },
166+ & cli.StringSliceFlag {
167+ Name : "with-ns" ,
168+ Usage : "Specify existing Linux namespaces to join at container runtime (format '<nstype>:<path>')" ,
169+ },
170+ & cli.StringFlag {
171+ Name : "pid-file" ,
172+ Usage : "File path to write the task's pid" ,
173+ },
174+ & cli.IntSliceFlag {
175+ Name : "gpus" ,
176+ Usage : "Add gpus to the container" ,
177+ },
178+ & cli.BoolFlag {
179+ Name : "allow-new-privs" ,
180+ Usage : "Turn off OCI spec's NoNewPrivileges feature flag" ,
181+ },
182+ & cli.Uint64Flag {
183+ Name : "memory-limit" ,
184+ Usage : "Memory limit (in bytes) for the container" ,
185+ },
186+ & cli.StringSliceFlag {
187+ Name : "cap-add" ,
188+ Usage : "Add Linux capabilities (Set capabilities with 'CAP_' prefix)" ,
189+ },
190+ & cli.StringSliceFlag {
191+ Name : "cap-drop" ,
192+ Usage : "Drop Linux capabilities (Set capabilities with 'CAP_' prefix)" ,
193+ },
194+ & cli.BoolFlag {
195+ Name : "seccomp" ,
196+ Usage : "Enable the default seccomp profile" ,
197+ },
198+ & cli.StringFlag {
199+ Name : "seccomp-profile" ,
200+ Usage : "File path to custom seccomp profile. seccomp must be set to true, before using seccomp-profile" ,
201+ },
202+ & cli.StringFlag {
203+ Name : "apparmor-default-profile" ,
204+ Usage : "Enable AppArmor with the default profile with the specified name, e.g. \" cri-containerd.apparmor.d\" " ,
205+ },
206+ & cli.StringFlag {
207+ Name : "apparmor-profile" ,
208+ Usage : "Enable AppArmor with an existing custom profile" ,
209+ },
210+ & cli.StringFlag {
211+ Name : "blockio-config-file" ,
212+ Usage : "File path to blockio class definitions. By default class definitions are not loaded." ,
213+ },
214+ & cli.StringFlag {
215+ Name : "blockio-class" ,
216+ Usage : "Name of the blockio class to associate the container with" ,
217+ },
218+ & cli.StringFlag {
219+ Name : "rdt-class" ,
220+ Usage : "Name of the RDT class to associate the container with. Specifies a Class of Service (CLOS) for cache and memory bandwidth management." ,
221+ },
222+ & cli.StringFlag {
223+ Name : "hostname" ,
224+ Usage : "Set the container's host name" ,
225+ },
226+ & cli.StringFlag {
227+ Name : "user" ,
228+ Aliases : []string {"u" },
229+ Usage : "Username or user id, group optional (format: <name|uid>[:<group|gid>])" ,
230+ },
231+ }
232+ )
233+
31234// ObjectWithLabelArgs returns the first arg and a LabelArgs object
32- func ObjectWithLabelArgs (clicontext * cli.Context ) (string , map [string ]string ) {
235+ func ObjectWithLabelArgs (cliContext * cli.Context ) (string , map [string ]string ) {
33236 var (
34- first = clicontext .Args ().First ()
35- labelStrings = clicontext .Args ().Tail ()
237+ first = cliContext .Args ().First ()
238+ labelStrings = cliContext .Args ().Tail ()
36239 )
37240
38241 return first , LabelArgs (labelStrings )
@@ -42,13 +245,10 @@ func ObjectWithLabelArgs(clicontext *cli.Context) (string, map[string]string) {
42245func LabelArgs (labelStrings []string ) map [string ]string {
43246 labels := make (map [string ]string , len (labelStrings ))
44247 for _ , label := range labelStrings {
45- parts := strings .SplitN (label , "=" , 2 )
46- key := parts [0 ]
47- value := "true"
48- if len (parts ) > 1 {
49- value = parts [1 ]
248+ key , value , ok := strings .Cut (label , "=" )
249+ if ! ok {
250+ value = "true"
50251 }
51-
52252 labels [key ] = value
53253 }
54254
@@ -59,17 +259,17 @@ func LabelArgs(labelStrings []string) map[string]string {
59259func AnnotationArgs (annoStrings []string ) (map [string ]string , error ) {
60260 annotations := make (map [string ]string , len (annoStrings ))
61261 for _ , anno := range annoStrings {
62- parts := strings .SplitN (anno , "=" , 2 )
63- if len ( parts ) != 2 {
262+ key , value , ok := strings .Cut (anno , "=" )
263+ if ! ok {
64264 return nil , fmt .Errorf ("invalid key=value format annotation: %v" , anno )
65265 }
66- annotations [parts [ 0 ]] = parts [ 1 ]
266+ annotations [key ] = value
67267 }
68268 return annotations , nil
69269}
70270
71271// PrintAsJSON prints input in JSON format
72- func PrintAsJSON (x interface {} ) {
272+ func PrintAsJSON (x any ) {
73273 b , err := json .MarshalIndent (x , "" , " " )
74274 if err != nil {
75275 fmt .Fprintf (os .Stderr , "can't marshal %+v as a JSON string: %v\n " , x , err )
0 commit comments