-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathgenerate.go
More file actions
1591 lines (1376 loc) · 50.3 KB
/
generate.go
File metadata and controls
1591 lines (1376 loc) · 50.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package main
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"os"
"runtime"
"strconv"
"strings"
"unicode"
"unicode/utf8"
rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/generate"
"github.com/opencontainers/runtime-tools/generate/seccomp"
"github.com/urfave/cli"
)
var generateFlags = []cli.Flag{
cli.StringSliceFlag{Name: "args", Usage: "command to run in the container"},
cli.StringFlag{Name: "domainname", Usage: "domainname value for the container"},
cli.StringSliceFlag{Name: "env", Usage: "add environment variable e.g. key=value"},
cli.StringSliceFlag{Name: "env-file", Usage: "read in a file of environment variables"},
cli.StringSliceFlag{Name: "hooks-poststart-add", Usage: "set command to run in poststart hooks"},
cli.BoolFlag{Name: "hooks-poststart-remove-all", Usage: "remove all poststart hooks"},
cli.StringSliceFlag{Name: "hooks-poststop-add", Usage: "set command to run in poststop hooks"},
cli.BoolFlag{Name: "hooks-poststop-remove-all", Usage: "remove all poststop hooks"},
cli.StringSliceFlag{Name: "hooks-prestart-add", Usage: "set command to run in prestart hooks"},
cli.BoolFlag{Name: "hooks-prestart-remove-all", Usage: "remove all prestart hooks"},
cli.StringFlag{Name: "hostname", Usage: "hostname value for the container"},
cli.StringSliceFlag{Name: "label", Usage: "add annotations to the configuration e.g. key=value"},
cli.StringFlag{Name: "linux-apparmor", Usage: "specifies the the apparmor profile for the container"},
cli.IntFlag{Name: "linux-blkio-leaf-weight", Usage: "Block IO (relative leaf weight), the range is from 10 to 1000"},
cli.StringSliceFlag{Name: "linux-blkio-leaf-weight-device", Usage: "Block IO (relative device leaf weight), e.g. major:minor:leaf-weight"},
cli.StringSliceFlag{Name: "linux-blkio-read-bps-device", Usage: "Limit read rate (bytes per second) from a device"},
cli.StringSliceFlag{Name: "linux-blkio-read-iops-device", Usage: "Limit read rate (IO per second) from a device"},
cli.IntFlag{Name: "linux-blkio-weight", Usage: "Block IO (relative weight), the range is from 10 to 1000"},
cli.StringSliceFlag{Name: "linux-blkio-weight-device", Usage: "Block IO (relative device weight), e.g. major:minor:weight"},
cli.StringSliceFlag{Name: "linux-blkio-write-bps-device", Usage: "Limit write rate (bytes per second) to a device"},
cli.StringSliceFlag{Name: "linux-blkio-write-iops-device", Usage: "Limit write rate (IO per second) to a device"},
cli.StringFlag{Name: "linux-cgroups-path", Usage: "specify the path to the cgroups"},
cli.Uint64Flag{Name: "linux-cpu-period", Usage: "the CPU period to be used for hardcapping (in usecs)"},
cli.Uint64Flag{Name: "linux-cpu-quota", Usage: "the allowed CPU time in a given period (in usecs)"},
cli.StringFlag{Name: "linux-cpus", Usage: "CPUs to use within the cpuset (default is to use any CPU available)"},
cli.Uint64Flag{Name: "linux-cpu-shares", Usage: "the relative share of CPU time available to the tasks in a cgroup"},
cli.StringSliceFlag{Name: "linux-device-add", Usage: "add a device which must be made available in the container"},
cli.StringSliceFlag{Name: "linux-device-remove", Usage: "remove a device which must be made available in the container"},
cli.BoolFlag{Name: "linux-device-remove-all", Usage: "remove all devices which must be made available in the container"},
cli.StringSliceFlag{Name: "linux-device-cgroup-add", Usage: "add a device access rule"},
cli.StringSliceFlag{Name: "linux-device-cgroup-remove", Usage: "remove a device access rule"},
cli.BoolFlag{Name: "linux-disable-oom-kill", Usage: "disable OOM Killer"},
cli.StringSliceFlag{Name: "linux-gidmappings", Usage: "add GIDMappings e.g HostID:ContainerID:Size"},
cli.StringSliceFlag{Name: "linux-hugepage-limits-add", Usage: "add hugepage resource limits"},
cli.StringSliceFlag{Name: "linux-hugepage-limits-drop", Usage: "drop hugepage resource limits"},
cli.StringFlag{Name: "linux-intelRdt-closid", Usage: "RDT Class of Service, i.e. group under the resctrl pseudo-filesystem which to associate the container with"},
cli.StringFlag{Name: "linux-intelRdt-l3CacheSchema", Usage: "specifies the schema for L3 cache id and capacity bitmask"},
cli.StringSliceFlag{Name: "linux-masked-paths", Usage: "specifies paths can not be read inside container"},
cli.Uint64Flag{Name: "linux-mem-kernel-limit", Usage: "kernel memory limit (in bytes)"},
cli.Uint64Flag{Name: "linux-mem-kernel-tcp", Usage: "kernel memory limit for tcp (in bytes)"},
cli.Uint64Flag{Name: "linux-mem-limit", Usage: "memory limit (in bytes)"},
cli.Uint64Flag{Name: "linux-mem-reservation", Usage: "memory reservation or soft limit (in bytes)"},
cli.StringFlag{Name: "linux-mems", Usage: "list of memory nodes in the cpuset (default is to use any available memory node)"},
cli.Uint64Flag{Name: "linux-mem-swap", Usage: "total memory limit (memory + swap) (in bytes)"},
cli.Uint64Flag{Name: "linux-mem-swappiness", Usage: "how aggressive the kernel will swap memory pages (Range from 0 to 100)"},
cli.StringFlag{Name: "linux-memorypolicy-mode", Usage: "mode of the default NUMA memory policy for page allocation, e.g MPOL_INTERLEAVE"},
cli.StringFlag{Name: "linux-memorypolicy-nodes", Usage: "nodes of the default NUMA memory policy, e.g 0-3,7"},
cli.StringSliceFlag{Name: "linux-memorypolicy-flag", Usage: "adds a flag for the default NUMA memory policy, e.g MPOL_F_STATIC_NODES"},
cli.StringFlag{Name: "linux-mount-label", Usage: "selinux mount context label"},
cli.StringSliceFlag{Name: "linux-namespace-add", Usage: "adds a namespace to the set of namespaces to create or join of the form 'ns[:path]'"},
cli.StringSliceFlag{Name: "linux-namespace-remove", Usage: "removes a namespace from the set of namespaces to create or join of the form 'ns'"},
cli.BoolFlag{Name: "linux-namespace-remove-all", Usage: "removes all namespaces from the set of namespaces created or joined"},
cli.IntFlag{Name: "linux-network-classid", Usage: "specifies class identifier tagged by container's network packets"},
cli.StringSliceFlag{Name: "linux-network-priorities", Usage: "specifies priorities of network traffic"},
cli.IntFlag{Name: "linux-oom-score-adj", Usage: "oom_score_adj for the container"},
cli.Int64Flag{Name: "linux-pids-limit", Usage: "maximum number of PIDs"},
cli.StringSliceFlag{Name: "linux-readonly-paths", Usage: "specifies paths readonly inside container"},
cli.Int64Flag{Name: "linux-realtime-period", Usage: "CPU period to be used for realtime scheduling (in usecs)"},
cli.Int64Flag{Name: "linux-realtime-runtime", Usage: "the time realtime scheduling may use (in usecs)"},
cli.StringFlag{Name: "linux-rootfs-propagation", Usage: "mount propagation for rootfs"},
cli.StringFlag{Name: "linux-seccomp-allow", Usage: "specifies syscalls to respond with allow"},
cli.StringFlag{Name: "linux-seccomp-arch", Usage: "specifies additional architectures permitted to be used for system calls"},
cli.StringFlag{Name: "linux-seccomp-default", Usage: "specifies default action to be used for system calls and removes existing rules with specified action"},
cli.StringFlag{Name: "linux-seccomp-default-force", Usage: "same as seccomp-default but does not remove existing rules with specified action"},
cli.StringFlag{Name: "linux-seccomp-errno", Usage: "specifies syscalls to respond with errno"},
cli.StringFlag{Name: "linux-seccomp-kill", Usage: "specifies syscalls to respond with kill"},
cli.BoolFlag{Name: "linux-seccomp-only", Usage: "specifies to export just a seccomp configuration file"},
cli.StringFlag{Name: "linux-seccomp-remove", Usage: "specifies syscalls to remove seccomp rules for"},
cli.BoolFlag{Name: "linux-seccomp-remove-all", Usage: "removes all syscall rules from seccomp configuration"},
cli.StringFlag{Name: "linux-seccomp-trace", Usage: "specifies syscalls to respond with trace"},
cli.StringFlag{Name: "linux-seccomp-trap", Usage: "specifies syscalls to respond with trap"},
cli.StringFlag{Name: "linux-selinux-label", Usage: "process selinux label"},
cli.StringSliceFlag{Name: "linux-sysctl", Usage: "add sysctl settings e.g net.ipv4.forward=1"},
cli.StringSliceFlag{Name: "linux-uidmappings", Usage: "add UIDMappings e.g HostID:ContainerID:Size"},
cli.StringSliceFlag{Name: "mounts-add", Usage: "configures additional mounts inside container"},
cli.StringSliceFlag{Name: "mounts-remove", Usage: "remove destination mountpoints from inside container"},
cli.BoolFlag{Name: "mounts-remove-all", Usage: "remove all mounts inside container"},
cli.StringFlag{Name: "oci-version", Usage: "specify the version of the Open Container Initiative runtime specification"},
cli.StringFlag{Name: "os", Value: runtime.GOOS, Usage: "operating system the container is created for"},
cli.StringFlag{Name: "output", Usage: "output file (defaults to stdout)"},
cli.BoolFlag{Name: "privileged", Usage: "enable privileged container settings"},
cli.StringFlag{Name: "process-cap-add", Usage: "add Linux capabilities to all 5 capability sets"},
cli.StringFlag{Name: "process-cap-add-ambient", Usage: "add Linux ambient capabilities"},
cli.StringFlag{Name: "process-cap-add-bounding", Usage: "add Linux bounding capabilities"},
cli.StringFlag{Name: "process-cap-add-effective", Usage: "add Linux effective capabilities"},
cli.StringFlag{Name: "process-cap-add-inheritable", Usage: "add Linux inheritable capabilities"},
cli.StringFlag{Name: "process-cap-add-permitted", Usage: "add Linux permitted capabilities"},
cli.StringFlag{Name: "process-cap-drop", Usage: "drop Linux capabilities to all 5 capability sets"},
cli.BoolFlag{Name: "process-cap-drop-all", Usage: "drop all Linux capabilities"},
cli.StringFlag{Name: "process-cap-drop-ambient", Usage: "drop Linux ambient capabilities"},
cli.StringFlag{Name: "process-cap-drop-bounding", Usage: "drop Linux bounding capabilities"},
cli.StringFlag{Name: "process-cap-drop-effective", Usage: "drop Linux effective capabilities"},
cli.StringFlag{Name: "process-cap-drop-inheritable", Usage: "drop Linux inheritable capabilities"},
cli.StringFlag{Name: "process-cap-drop-permitted", Usage: "drop Linux permitted capabilities"},
cli.StringFlag{Name: "process-consolesize", Usage: "specifies the console size in characters (width:height)"},
cli.StringFlag{Name: "process-cwd", Value: "/", Usage: "current working directory for the process"},
cli.IntFlag{Name: "process-gid", Usage: "gid for the process"},
cli.StringSliceFlag{Name: "process-groups", Usage: "supplementary groups for the process"},
cli.BoolFlag{Name: "process-no-new-privileges", Usage: "set no new privileges bit for the container process"},
cli.StringSliceFlag{Name: "process-rlimits-add", Usage: "specifies resource limits for processes inside the container. "},
cli.StringSliceFlag{Name: "process-rlimits-remove", Usage: "remove specified resource limits for processes inside the container. "},
cli.BoolFlag{Name: "process-rlimits-remove-all", Usage: "remove all resource limits for processes inside the container. "},
cli.BoolFlag{Name: "process-terminal", Usage: "specifies whether a terminal is attached to the process"},
cli.IntFlag{Name: "process-uid", Usage: "uid for the process"},
cli.StringFlag{Name: "process-umask", Usage: "umask for the process"},
cli.StringFlag{Name: "process-username", Usage: "username for the process"},
cli.StringFlag{Name: "rootfs-path", Value: "rootfs", Usage: "path to the root filesystem"},
cli.BoolFlag{Name: "rootfs-readonly", Usage: "make the container's rootfs readonly"},
cli.StringSliceFlag{Name: "solaris-anet", Usage: "set up networking for Solaris application containers"},
cli.StringFlag{Name: "solaris-capped-cpu-ncpus", Usage: "Specifies the percentage of CPU usage"},
cli.StringFlag{Name: "solaris-capped-memory-physical", Usage: "Specifies the physical caps on the memory"},
cli.StringFlag{Name: "solaris-capped-memory-swap", Usage: "Specifies the swap caps on the memory"},
cli.StringFlag{Name: "solaris-limitpriv", Usage: "privilege limit"},
cli.StringFlag{Name: "solaris-max-shm-memory", Usage: "Specifies the maximum amount of shared memory"},
cli.StringFlag{Name: "solaris-milestone", Usage: "Specifies the SMF FMRI"},
cli.StringFlag{Name: "template", Usage: "base template to use for creating the configuration"},
cli.StringSliceFlag{Name: "vm-hypervisor-parameters", Usage: "specifies an array of parameters to pass to the hypervisor"},
cli.StringFlag{Name: "vm-hypervisor-path", Usage: "specifies the path to the hypervisor binary that manages the container virtual machine"},
cli.StringFlag{Name: "vm-image-format", Usage: "set the format of the container virtual machine root image"},
cli.StringFlag{Name: "vm-image-path", Usage: "set path to the container virtual machine root image"},
cli.StringFlag{Name: "vm-kernel-initrd", Usage: "set path to an initial ramdisk to be used by the container virtual machine"},
cli.StringSliceFlag{Name: "vm-kernel-parameters", Usage: "specifies an array of parameters to pass to the kernel"},
cli.StringFlag{Name: "vm-kernel-path", Usage: "set path to the kernel used to boot the container virtual machine"},
cli.StringSliceFlag{Name: "windows-devices", Usage: "specifies a list of devices to be mapped into the container"},
cli.StringFlag{Name: "windows-hyperv-utilityVMPath", Usage: "specifies the path to the image used for the utility VM"},
cli.BoolFlag{Name: "windows-ignore-flushes-during-boot", Usage: "ignore flushes during boot"},
cli.StringSliceFlag{Name: "windows-layer-folders", Usage: "specifies a list of layer folders the container image relies on"},
cli.StringFlag{Name: "windows-network", Usage: "specifies network for container"},
cli.BoolFlag{Name: "windows-network-allowunqualifieddnsquery", Usage: "specifies networking unqualified DNS query is allowed"},
cli.StringFlag{Name: "windows-network-networkNamespace", Usage: "specifies network namespace for container"},
cli.StringFlag{Name: "windows-resources-cpu", Usage: "specifies CPU for container"},
cli.Uint64Flag{Name: "windows-resources-memory-limit", Usage: "specifies limit of memory"},
cli.StringFlag{Name: "windows-resources-storage", Usage: "specifies storage for container"},
cli.BoolFlag{Name: "windows-servicing", Usage: "servicing operations"},
}
var generateCommand = cli.Command{
Name: "generate",
Usage: "generate an OCI spec file",
Flags: generateFlags,
Before: before,
Action: func(context *cli.Context) error {
// Start from the default template.
specgen, err := generate.New(context.String("os"))
if err != nil {
return err
}
var template string
if context.IsSet("template") {
template = context.String("template")
}
if template != "" {
specgen, err = generate.NewFromFile(template)
if err != nil {
return err
}
}
err = setupSpec(&specgen, context)
if err != nil {
return err
}
var exportOpts generate.ExportOptions
exportOpts.Seccomp = context.Bool("linux-seccomp-only")
if context.IsSet("output") {
err = specgen.SaveToFile(context.String("output"), exportOpts)
} else {
err = specgen.Save(os.Stdout, exportOpts)
}
if err != nil {
return err
}
return nil
},
}
func setupSpec(g *generate.Generator, context *cli.Context) error {
if context.GlobalBool("host-specific") {
g.HostSpecific = true
}
if len(g.Config.Version) == 0 {
g.SetVersion(rspec.Version)
}
if context.IsSet("hostname") {
g.SetHostname(context.String("hostname"))
}
if context.IsSet("domainname") {
g.SetDomainName(context.String("domainname"))
}
if context.IsSet("oci-version") {
g.SetOCIVersion(context.String("oci-version"))
}
if context.IsSet("label") {
annotations := context.StringSlice("label")
for _, s := range annotations {
pair := strings.SplitN(s, "=", 2)
if len(pair) != 2 || pair[0] == "" {
return fmt.Errorf("incorrectly specified annotation: %s", s)
}
g.AddAnnotation(pair[0], pair[1])
}
}
g.SetRootPath(context.String("rootfs-path"))
if context.IsSet("rootfs-readonly") {
g.SetRootReadonly(context.Bool("rootfs-readonly"))
}
if context.IsSet("process-uid") {
g.SetProcessUID(uint32(context.Int("process-uid")))
}
if context.IsSet("process-username") {
g.SetProcessUsername(context.String("process-username"))
}
if context.IsSet("process-umask") {
g.SetProcessUmask(uint32(context.Int("process-umask")))
}
if context.IsSet("process-gid") {
g.SetProcessGID(uint32(context.Int("process-gid")))
}
if context.IsSet("linux-selinux-label") {
g.SetProcessSelinuxLabel(context.String("linux-selinux-label"))
}
g.SetProcessCwd(context.String("process-cwd"))
if context.IsSet("linux-apparmor") {
g.SetProcessApparmorProfile(context.String("linux-apparmor"))
}
if context.IsSet("process-no-new-privileges") {
g.SetProcessNoNewPrivileges(context.Bool("process-no-new-privileges"))
}
if context.IsSet("process-terminal") {
g.SetProcessTerminal(context.Bool("process-terminal"))
}
if context.IsSet("args") {
g.SetProcessArgs(context.StringSlice("args"))
}
{
envs, err := readKVStrings(context.StringSlice("env-file"), context.StringSlice("env"))
if err != nil {
return err
}
for _, env := range envs {
name, value, err := parseEnv(env)
if err != nil {
return err
}
g.AddProcessEnv(name, value)
}
}
if context.IsSet("process-groups") {
groups := context.StringSlice("process-groups")
for _, group := range groups {
groupID, err := strconv.Atoi(group)
if err != nil {
return err
}
g.AddProcessAdditionalGid(uint32(groupID))
}
}
if context.IsSet("linux-cgroups-path") {
g.SetLinuxCgroupsPath(context.String("linux-cgroups-path"))
}
if context.IsSet("linux-masked-paths") {
paths := context.StringSlice("linux-masked-paths")
for _, path := range paths {
g.AddLinuxMaskedPaths(path)
}
}
if context.IsSet("linux-device-cgroup-add") {
devices := context.StringSlice("linux-device-cgroup-add")
for _, device := range devices {
dev, err := parseLinuxResourcesDeviceAccess(device, g)
if err != nil {
return err
}
g.AddLinuxResourcesDevice(dev.Allow, dev.Type, dev.Major, dev.Minor, dev.Access)
}
}
if context.IsSet("linux-device-cgroup-remove") {
devices := context.StringSlice("linux-device-cgroup-remove")
for _, device := range devices {
dev, err := parseLinuxResourcesDeviceAccess(device, g)
if err != nil {
return err
}
g.RemoveLinuxResourcesDevice(dev.Allow, dev.Type, dev.Major, dev.Minor, dev.Access)
}
}
if context.IsSet("linux-readonly-paths") {
paths := context.StringSlice("linux-readonly-paths")
for _, path := range paths {
g.AddLinuxReadonlyPaths(path)
}
}
if context.IsSet("linux-mount-label") {
g.SetLinuxMountLabel(context.String("linux-mount-label"))
}
if context.IsSet("linux-sysctl") {
sysctls := context.StringSlice("linux-sysctl")
for _, s := range sysctls {
pair := strings.Split(s, "=")
if len(pair) != 2 {
return fmt.Errorf("incorrectly specified sysctl: %s", s)
}
g.AddLinuxSysctl(pair[0], pair[1])
}
}
g.SetupPrivileged(context.Bool("privileged"))
if context.Bool("process-cap-drop-all") {
g.ClearProcessCapabilities()
}
if context.IsSet("process-cap-add") {
addCaps := context.String("process-cap-add")
parts := strings.Split(addCaps, ",")
for _, part := range parts {
if err := g.AddProcessCapability(part); err != nil {
return err
}
}
}
if context.IsSet("process-cap-add-ambient") {
addCaps := context.String("process-cap-add-ambient")
parts := strings.Split(addCaps, ",")
for _, part := range parts {
if err := g.AddProcessCapabilityAmbient(part); err != nil {
return err
}
}
}
if context.IsSet("process-cap-add-bounding") {
addCaps := context.String("process-cap-add-bounding")
parts := strings.Split(addCaps, ",")
for _, part := range parts {
if err := g.AddProcessCapabilityBounding(part); err != nil {
return err
}
}
}
if context.IsSet("process-cap-add-effective") {
addCaps := context.String("process-cap-add-effective")
parts := strings.Split(addCaps, ",")
for _, part := range parts {
if err := g.AddProcessCapabilityEffective(part); err != nil {
return err
}
}
}
if context.IsSet("process-cap-add-inheritable") {
addCaps := context.String("process-cap-add-inheritable")
parts := strings.Split(addCaps, ",")
for _, part := range parts {
if err := g.AddProcessCapabilityInheritable(part); err != nil {
return err
}
}
}
if context.IsSet("process-cap-add-permitted") {
addCaps := context.String("process-cap-add-permitted")
parts := strings.Split(addCaps, ",")
for _, part := range parts {
if err := g.AddProcessCapabilityPermitted(part); err != nil {
return err
}
}
}
if context.IsSet("process-cap-drop") {
addCaps := context.String("process-cap-drop")
parts := strings.Split(addCaps, ",")
for _, part := range parts {
if err := g.DropProcessCapability(part); err != nil {
return err
}
}
}
if context.IsSet("process-cap-drop-ambient") {
dropCaps := context.String("process-cap-drop-ambient")
parts := strings.Split(dropCaps, ",")
for _, part := range parts {
if err := g.DropProcessCapabilityAmbient(part); err != nil {
return err
}
}
}
if context.IsSet("process-cap-drop-bounding") {
dropCaps := context.String("process-cap-drop-bounding")
parts := strings.Split(dropCaps, ",")
for _, part := range parts {
if err := g.DropProcessCapabilityBounding(part); err != nil {
return err
}
}
}
if context.IsSet("process-cap-drop-effective") {
dropCaps := context.String("process-cap-drop-effective")
parts := strings.Split(dropCaps, ",")
for _, part := range parts {
if err := g.DropProcessCapabilityEffective(part); err != nil {
return err
}
}
}
if context.IsSet("process-cap-drop-inheritable") {
dropCaps := context.String("process-cap-drop-inheritable")
parts := strings.Split(dropCaps, ",")
for _, part := range parts {
if err := g.DropProcessCapabilityInheritable(part); err != nil {
return err
}
}
}
if context.IsSet("process-cap-drop-permitted") {
dropCaps := context.String("process-cap-drop-permitted")
parts := strings.Split(dropCaps, ",")
for _, part := range parts {
if err := g.DropProcessCapabilityPermitted(part); err != nil {
return err
}
}
}
if context.IsSet("process-consolesize") {
consoleSize := context.String("process-consolesize")
width, height, err := parseConsoleSize(consoleSize)
if err != nil {
return err
}
g.SetProcessConsoleSize(width, height)
}
var uidMaps, gidMaps []string
if context.IsSet("linux-uidmappings") {
uidMaps = context.StringSlice("linux-uidmappings")
}
if context.IsSet("linux-gidmappings") {
gidMaps = context.StringSlice("linux-gidmappings")
}
// Add default user namespace.
if len(uidMaps) > 0 || len(gidMaps) > 0 {
g.AddOrReplaceLinuxNamespace("user", "")
}
if context.IsSet("mounts-remove-all") {
g.ClearMounts()
}
if context.IsSet("mounts-remove") {
mounts := context.StringSlice("mounts-remove")
for _, mount := range mounts {
g.RemoveMount(mount)
}
}
if context.IsSet("mounts-add") {
mounts := context.StringSlice("mounts-add")
for _, mount := range mounts {
mnt := rspec.Mount{}
if err := json.Unmarshal([]byte(mount), &mnt); err != nil {
return err
}
g.AddMount(mnt)
}
}
if context.IsSet("hooks-poststart-remove-all") {
g.ClearPostStartHooks()
}
if context.IsSet("hooks-poststart-add") {
postStartHooks := context.StringSlice("hooks-poststart-add")
for _, hook := range postStartHooks {
tmpHook := rspec.Hook{}
if err := json.Unmarshal([]byte(hook), &tmpHook); err != nil {
return err
}
g.AddPostStartHook(tmpHook)
}
}
if context.IsSet("hooks-poststop-remove-all") {
g.ClearPostStopHooks()
}
if context.IsSet("hooks-poststop-add") {
postStopHooks := context.StringSlice("hooks-poststop-add")
for _, hook := range postStopHooks {
tmpHook := rspec.Hook{}
if err := json.Unmarshal([]byte(hook), &tmpHook); err != nil {
return err
}
g.AddPostStopHook(tmpHook)
}
}
if context.IsSet("hooks-prestart-remove-all") {
g.ClearPreStartHooks()
}
if context.IsSet("hooks-prestart-add") {
preStartHooks := context.StringSlice("hooks-prestart-add")
for _, hook := range preStartHooks {
tmpHook := rspec.Hook{}
if err := json.Unmarshal([]byte(hook), &tmpHook); err != nil {
return err
}
g.AddPreStartHook(tmpHook)
}
}
if context.IsSet("linux-rootfs-propagation") {
rp := context.String("linux-rootfs-propagation")
if err := g.SetLinuxRootPropagation(rp); err != nil {
return err
}
}
for _, uidMap := range uidMaps {
hid, cid, size, err := parseIDMapping(uidMap)
if err != nil {
return err
}
g.AddLinuxUIDMapping(hid, cid, size)
}
for _, gidMap := range gidMaps {
hid, cid, size, err := parseIDMapping(gidMap)
if err != nil {
return err
}
g.AddLinuxGIDMapping(hid, cid, size)
}
if context.IsSet("linux-disable-oom-kill") {
g.SetLinuxResourcesMemoryDisableOOMKiller(context.Bool("linux-disable-oom-kill"))
}
if context.IsSet("linux-oom-score-adj") {
g.SetProcessOOMScoreAdj(context.Int("linux-oom-score-adj"))
}
if context.IsSet("linux-blkio-leaf-weight") {
g.SetLinuxResourcesBlockIOLeafWeight(uint16(context.Uint64("linux-blkio-leaf-weight")))
}
if context.IsSet("linux-blkio-leaf-weight-device") {
devLeafWeight := context.StringSlice("linux-blkio-leaf-weight-device")
for _, v := range devLeafWeight {
major, minor, leafWeight, err := parseDeviceWeight(v)
if err != nil {
return err
}
if leafWeight == -1 {
g.DropLinuxResourcesBlockIOLeafWeightDevice(major, minor)
} else {
g.AddLinuxResourcesBlockIOLeafWeightDevice(major, minor, uint16(leafWeight))
}
}
}
if context.IsSet("linux-blkio-read-bps-device") {
throttleDevices := context.StringSlice("linux-blkio-read-bps-device")
for _, v := range throttleDevices {
major, minor, rate, err := parseThrottleDevice(v)
if err != nil {
return err
}
if rate == -1 {
g.DropLinuxResourcesBlockIOThrottleReadBpsDevice(major, minor)
} else {
g.AddLinuxResourcesBlockIOThrottleReadBpsDevice(major, minor, uint64(rate))
}
}
}
if context.IsSet("linux-blkio-read-iops-device") {
throttleDevices := context.StringSlice("linux-blkio-read-iops-device")
for _, v := range throttleDevices {
major, minor, rate, err := parseThrottleDevice(v)
if err != nil {
return err
}
if rate == -1 {
g.DropLinuxResourcesBlockIOThrottleReadIOPSDevice(major, minor)
} else {
g.AddLinuxResourcesBlockIOThrottleReadIOPSDevice(major, minor, uint64(rate))
}
}
}
if context.IsSet("linux-blkio-weight") {
g.SetLinuxResourcesBlockIOWeight(uint16(context.Uint64("linux-blkio-weight")))
}
if context.IsSet("linux-blkio-weight-device") {
devWeight := context.StringSlice("linux-blkio-weight-device")
for _, v := range devWeight {
major, minor, weight, err := parseDeviceWeight(v)
if err != nil {
return err
}
if weight == -1 {
g.DropLinuxResourcesBlockIOWeightDevice(major, minor)
} else {
g.AddLinuxResourcesBlockIOWeightDevice(major, minor, uint16(weight))
}
}
}
if context.IsSet("linux-blkio-write-bps-device") {
throttleDevices := context.StringSlice("linux-blkio-write-bps-device")
for _, v := range throttleDevices {
major, minor, rate, err := parseThrottleDevice(v)
if err != nil {
return err
}
if rate == -1 {
g.DropLinuxResourcesBlockIOThrottleWriteBpsDevice(major, minor)
} else {
g.AddLinuxResourcesBlockIOThrottleWriteBpsDevice(major, minor, uint64(rate))
}
}
}
if context.IsSet("linux-blkio-write-iops-device") {
throttleDevices := context.StringSlice("linux-blkio-write-iops-device")
for _, v := range throttleDevices {
major, minor, rate, err := parseThrottleDevice(v)
if err != nil {
return err
}
if rate == -1 {
g.DropLinuxResourcesBlockIOThrottleWriteIOPSDevice(major, minor)
} else {
g.AddLinuxResourcesBlockIOThrottleWriteIOPSDevice(major, minor, uint64(rate))
}
}
}
if context.IsSet("linux-cpu-shares") {
g.SetLinuxResourcesCPUShares(context.Uint64("linux-cpu-shares"))
}
if context.IsSet("linux-cpu-period") {
g.SetLinuxResourcesCPUPeriod(context.Uint64("linux-cpu-period"))
}
if context.IsSet("linux-cpu-quota") {
g.SetLinuxResourcesCPUQuota(context.Int64("linux-cpu-quota"))
}
if context.IsSet("linux-realtime-runtime") {
g.SetLinuxResourcesCPURealtimeRuntime(context.Int64("linux-realtime-runtime"))
}
if context.IsSet("linux-pids-limit") {
g.SetLinuxResourcesPidsLimit(context.Int64("linux-pids-limit"))
}
if context.IsSet("linux-realtime-period") {
g.SetLinuxResourcesCPURealtimePeriod(context.Uint64("linux-realtime-period"))
}
if context.IsSet("linux-cpus") {
g.SetLinuxResourcesCPUCpus(context.String("linux-cpus"))
}
if context.IsSet("linux-hugepage-limits-add") {
pageList := context.StringSlice("linux-hugepage-limits-add")
for _, v := range pageList {
pagesize, limit, err := parseHugepageLimit(v)
if err != nil {
return err
}
g.AddLinuxResourcesHugepageLimit(pagesize, limit)
}
}
if context.IsSet("linux-hugepage-limits-drop") {
pageList := context.StringSlice("linux-hugepage-limits-drop")
for _, v := range pageList {
g.DropLinuxResourcesHugepageLimit(v)
}
}
if context.IsSet("linux-intelRdt-closid") {
g.SetLinuxIntelRdtClosID(context.String("linux-intelRdt-closid"))
}
if context.IsSet("linux-intelRdt-l3CacheSchema") {
g.SetLinuxIntelRdtL3CacheSchema(context.String("linux-intelRdt-l3CacheSchema"))
}
if context.IsSet("linux-mems") {
g.SetLinuxResourcesCPUMems(context.String("linux-mems"))
}
if context.IsSet("linux-mem-limit") {
g.SetLinuxResourcesMemoryLimit(context.Int64("linux-mem-limit"))
}
if context.IsSet("linux-mem-reservation") {
g.SetLinuxResourcesMemoryReservation(context.Int64("linux-mem-reservation"))
}
if context.IsSet("linux-mem-swap") {
g.SetLinuxResourcesMemorySwap(context.Int64("linux-mem-swap"))
}
if context.IsSet("linux-mem-kernel-limit") {
g.SetLinuxResourcesMemoryKernel(context.Int64("linux-mem-kernel-limit"))
}
if context.IsSet("linux-mem-kernel-tcp") {
g.SetLinuxResourcesMemoryKernelTCP(context.Int64("linux-mem-kernel-tcp"))
}
if context.IsSet("linux-mem-swappiness") {
g.SetLinuxResourcesMemorySwappiness(context.Uint64("linux-mem-swappiness"))
}
if context.IsSet("linux-memorypolicy-mode") {
mpolMode := context.String("linux-memorypolicy-mode")
if err := g.SetLinuxMemoryPolicyMode(mpolMode); err != nil {
return err
}
}
if context.IsSet("linux-memorypolicy-nodes") {
mpolNodes := context.String("linux-memorypolicy-nodes")
if err := g.SetLinuxMemoryPolicyNodes(mpolNodes); err != nil {
return err
}
}
if context.IsSet("linux-memorypolicy-flag") {
mpolFlags := context.StringSlice("linux-memorypolicy-flag")
if err := g.SetLinuxMemoryPolicyFlags(mpolFlags); err != nil {
return err
}
}
if context.IsSet("linux-network-classid") {
g.SetLinuxResourcesNetworkClassID(uint32(context.Int("linux-network-classid")))
}
if context.IsSet("linux-network-priorities") {
priorities := context.StringSlice("linux-network-priorities")
for _, p := range priorities {
name, priority, err := parseNetworkPriority(p)
if err != nil {
return err
}
if priority == -1 {
g.DropLinuxResourcesNetworkPriorities(name)
} else {
g.AddLinuxResourcesNetworkPriorities(name, uint32(priority))
}
}
}
if context.Bool("linux-namespace-remove-all") {
g.ClearLinuxNamespaces()
}
if context.IsSet("linux-namespace-add") {
namespaces := context.StringSlice("linux-namespace-add")
for _, ns := range namespaces {
name, path, err := parseNamespace(ns)
if err != nil {
return err
}
if err := g.AddOrReplaceLinuxNamespace(name, path); err != nil {
return err
}
}
}
if context.IsSet("linux-namespace-remove") {
namespaces := context.StringSlice("linux-namespace-remove")
for _, name := range namespaces {
if err := g.RemoveLinuxNamespace(name); err != nil {
return err
}
}
}
if context.Bool("process-rlimits-remove-all") {
g.ClearProcessRlimits()
}
if context.IsSet("process-rlimits-add") {
rlimits := context.StringSlice("process-rlimits-add")
for _, rlimit := range rlimits {
rType, rHard, rSoft, err := parseRlimit(rlimit)
if err != nil {
return err
}
g.AddProcessRlimits(rType, rHard, rSoft)
}
}
if context.IsSet("process-rlimits-remove") {
rlimits := context.StringSlice("process-rlimits-remove")
for _, rlimit := range rlimits {
g.RemoveProcessRlimits(rlimit)
}
}
if context.Bool("linux-device-remove-all") {
g.ClearLinuxDevices()
}
if context.IsSet("linux-device-add") {
devices := context.StringSlice("linux-device-add")
for _, deviceArg := range devices {
dev, err := parseDevice(deviceArg, g)
if err != nil {
return err
}
g.AddDevice(dev)
}
}
if context.IsSet("linux-device-remove") {
devices := context.StringSlice("linux-device-remove")
for _, device := range devices {
g.RemoveDevice(device)
}
}
if context.IsSet("solaris-anet") {
anets := context.StringSlice("solaris-anet")
for _, anet := range anets {
tmpAnet := rspec.SolarisAnet{}
if err := json.Unmarshal([]byte(anet), &tmpAnet); err != nil {
return err
}
g.AddSolarisAnet(tmpAnet)
}
}
if context.IsSet("solaris-capped-cpu-ncpus") {
g.SetSolarisCappedCPUNcpus(context.String("solaris-capped-cpu-ncpus"))
}
if context.IsSet("solaris-capped-memory-physical") {
g.SetSolarisCappedMemoryPhysical(context.String("solaris-capped-memory-physical"))
}
if context.IsSet("solaris-capped-memory-swap") {
g.SetSolarisCappedMemorySwap(context.String("solaris-capped-memory-swap"))
}
if context.IsSet("solaris-limitpriv") {
g.SetSolarisLimitPriv(context.String("solaris-limitpriv"))
}
if context.IsSet("solaris-max-shm-memory") {
g.SetSolarisMaxShmMemory(context.String("solaris-max-shm-memory"))
}
if context.IsSet("solaris-milestone") {
g.SetSolarisMilestone(context.String("solaris-milestone"))
}
if context.IsSet("vm-hypervisor-path") {
if err := g.SetVMHypervisorPath(context.String("vm-hypervisor-path")); err != nil {
return err
}
}
if context.IsSet("vm-hypervisor-parameters") {
g.SetVMHypervisorParameters(context.StringSlice("vm-hypervisor-parameters"))
}
if context.IsSet("vm-kernel-path") {
if err := g.SetVMKernelPath(context.String("vm-kernel-path")); err != nil {
return err
}
}
if context.IsSet("vm-kernel-parameters") {
g.SetVMKernelParameters(context.StringSlice("vm-kernel-parameters"))
}
if context.IsSet("vm-kernel-initrd") {
if err := g.SetVMKernelInitRD(context.String("vm-kernel-initrd")); err != nil {
return err
}
}
if context.IsSet("vm-image-path") {
if err := g.SetVMImagePath(context.String("vm-image-path")); err != nil {
return err
}
}
if context.IsSet("vm-image-format") {
if err := g.SetVMImageFormat(context.String("vm-image-format")); err != nil {
return err
}
}
if context.IsSet("windows-hyperv-utilityVMPath") {
g.SetWindowsHypervUntilityVMPath(context.String("windows-hyperv-utilityVMPath"))
}
if context.IsSet("windows-ignore-flushes-during-boot") {
g.SetWindowsIgnoreFlushesDuringBoot(context.Bool("windows-ignore-flushes-during-boot"))
}
if context.IsSet("windows-layer-folders") {
folders := context.StringSlice("windows-layer-folders")
for _, folder := range folders {
g.AddWindowsLayerFolders(folder)
}
}
if context.IsSet("windows-devices") {
devices := context.StringSlice("windows-devices")
for _, device := range devices {
id, idType, err := parseWindowsDevices(device)
if err != nil {
return err
}
if err := g.AddWindowsDevices(id, idType); err != nil {
return err
}
}
}
if context.IsSet("windows-network") {