Skip to content

Commit 9c39ab5

Browse files
author
Ma Shimiao
authored
Merge pull request #532 from q384566678/generate-solaris
generator solaris application container configuration
2 parents 507586f + e996b69 commit 9c39ab5

5 files changed

Lines changed: 136 additions & 0 deletions

File tree

cmd/oci-runtime-tool/generate.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ var generateFlags = []cli.Flag{
114114
cli.IntFlag{Name: "process-uid", Usage: "uid for the process"},
115115
cli.StringFlag{Name: "rootfs-path", Value: "rootfs", Usage: "path to the root filesystem"},
116116
cli.BoolFlag{Name: "rootfs-readonly", Usage: "make the container's rootfs readonly"},
117+
cli.StringSliceFlag{Name: "solaris-anet", Usage: "set up networking for Solaris application containers"},
118+
cli.StringFlag{Name: "solaris-capped-cpu-ncpus", Usage: "Specifies the percentage of CPU usage"},
119+
cli.StringFlag{Name: "solaris-capped-memory-physical", Usage: "Specifies the physical caps on the memory"},
120+
cli.StringFlag{Name: "solaris-capped-memory-swap", Usage: "Specifies the swap caps on the memory"},
121+
cli.StringFlag{Name: "solaris-limitpriv", Usage: "privilege limit"},
122+
cli.StringFlag{Name: "solaris-max-shm-memory", Usage: "Specifies the maximum amount of shared memory"},
123+
cli.StringFlag{Name: "solaris-milestone", Usage: "Specifies the SMF FMRI"},
117124
cli.StringFlag{Name: "template", Usage: "base template to use for creating the configuration"},
118125
}
119126

@@ -776,6 +783,42 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
776783
}
777784
}
778785

786+
if context.IsSet("solaris-anet") {
787+
anets := context.StringSlice("solaris-anet")
788+
for _, anet := range anets {
789+
tmpAnet := rspec.SolarisAnet{}
790+
if err := json.Unmarshal([]byte(anet), &tmpAnet); err != nil {
791+
return err
792+
}
793+
794+
g.AddSolarisAnet(tmpAnet)
795+
}
796+
}
797+
798+
if context.IsSet("solaris-capped-cpu-ncpus") {
799+
g.SetSolarisCappedCPUNcpus(context.String("solaris-capped-cpu-ncpus"))
800+
}
801+
802+
if context.IsSet("solaris-capped-memory-physical") {
803+
g.SetSolarisCappedMemoryPhysical(context.String("solaris-capped-memory-physical"))
804+
}
805+
806+
if context.IsSet("solaris-capped-memory-swap") {
807+
g.SetSolarisCappedMemorySwap(context.String("solaris-capped-memory-swap"))
808+
}
809+
810+
if context.IsSet("solaris-limitpriv") {
811+
g.SetSolarisLimitPriv(context.String("solaris-limitpriv"))
812+
}
813+
814+
if context.IsSet("solaris-max-shm-memory") {
815+
g.SetSolarisMaxShmMemory(context.String("solaris-max-shm-memory"))
816+
}
817+
818+
if context.IsSet("solaris-milestone") {
819+
g.SetSolarisMilestone(context.String("solaris-milestone"))
820+
}
821+
779822
err := addSeccomp(context, g)
780823
return err
781824
}

completions/bash/oci-runtime-tool

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@ _oci-runtime-tool_generate() {
383383
--process-rlimits-remove
384384
--process-uid
385385
--rootfs-path
386+
--solaris-anet
387+
--solaris-capped-cpu-ncpus
388+
--solaris-capped-memory-physical
389+
--solaris-capped-memory-swap
390+
--solaris-limitpriv1
391+
--solaris-max-shm-memory
392+
--solaris-milestone
386393
--template
387394
"
388395

generate/generate.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,3 +1448,45 @@ func dropBlockIOThrottleDevice(tmpList []rspec.LinuxThrottleDevice, major int64,
14481448

14491449
return throttleDevices
14501450
}
1451+
1452+
// AddSolarisAnet adds network into g.spec.Solaris.Anet
1453+
func (g *Generator) AddSolarisAnet(anet rspec.SolarisAnet) {
1454+
g.initSpecSolaris()
1455+
g.spec.Solaris.Anet = append(g.spec.Solaris.Anet, anet)
1456+
}
1457+
1458+
// SetSolarisCappedCPUNcpus sets g.spec.Solaris.CappedCPU.Ncpus
1459+
func (g *Generator) SetSolarisCappedCPUNcpus(ncpus string) {
1460+
g.initSpecSolarisCappedCPU()
1461+
g.spec.Solaris.CappedCPU.Ncpus = ncpus
1462+
}
1463+
1464+
// SetSolarisCappedMemoryPhysical sets g.spec.Solaris.CappedMemory.Physical
1465+
func (g *Generator) SetSolarisCappedMemoryPhysical(physical string) {
1466+
g.initSpecSolarisCappedMemory()
1467+
g.spec.Solaris.CappedMemory.Physical = physical
1468+
}
1469+
1470+
// SetSolarisCappedMemorySwap sets g.spec.Solaris.CappedMemory.Swap
1471+
func (g *Generator) SetSolarisCappedMemorySwap(swap string) {
1472+
g.initSpecSolarisCappedMemory()
1473+
g.spec.Solaris.CappedMemory.Swap = swap
1474+
}
1475+
1476+
// SetSolarisLimitPriv sets g.spec.Solaris.LimitPriv
1477+
func (g *Generator) SetSolarisLimitPriv(limitPriv string) {
1478+
g.initSpecSolaris()
1479+
g.spec.Solaris.LimitPriv = limitPriv
1480+
}
1481+
1482+
// SetSolarisMaxShmMemory sets g.spec.Solaris.MaxShmMemory
1483+
func (g *Generator) SetSolarisMaxShmMemory(memory string) {
1484+
g.initSpecSolaris()
1485+
g.spec.Solaris.MaxShmMemory = memory
1486+
}
1487+
1488+
// SetSolarisMilestone sets g.spec.Solaris.Milestone
1489+
func (g *Generator) SetSolarisMilestone(milestone string) {
1490+
g.initSpecSolaris()
1491+
g.spec.Solaris.Milestone = milestone
1492+
}

generate/spec.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,24 @@ func (g *Generator) initSpecLinuxResourcesPids() {
121121
g.spec.Linux.Resources.Pids = &rspec.LinuxPids{}
122122
}
123123
}
124+
125+
func (g *Generator) initSpecSolaris() {
126+
g.initSpec()
127+
if g.spec.Solaris == nil {
128+
g.spec.Solaris = &rspec.Solaris{}
129+
}
130+
}
131+
132+
func (g *Generator) initSpecSolarisCappedCPU() {
133+
g.initSpecSolaris()
134+
if g.spec.Solaris.CappedCPU == nil {
135+
g.spec.Solaris.CappedCPU = &rspec.SolarisCappedCPU{}
136+
}
137+
}
138+
139+
func (g *Generator) initSpecSolarisCappedMemory() {
140+
g.initSpecSolaris()
141+
if g.spec.Solaris.CappedMemory == nil {
142+
g.spec.Solaris.CappedMemory = &rspec.SolarisCappedMemory{}
143+
}
144+
}

man/oci-runtime-tool-generate.1.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,29 @@ read the configuration from `config.json`.
447447

448448
By default a container will have its root filesystem writable allowing processes to write files anywhere. By specifying the `--rootfs-readonly` flag the container will have its root filesystem mounted as read only prohibiting any writes.
449449

450+
**--solaris-anet**=[]
451+
Represents the automatic creation of a network resource for an application container
452+
e.g. --solaris-anet '{"allowedAddress": "172.17.0.2/16","configureAllowedAddress": "true","linkname": "net0"}'
453+
454+
**--solaris-capped-cpu-ncpus**=""
455+
Specifies the percentage of CPU usage.
456+
An ncpu value of 1 means 100% of a CPU, a value of 1.25 means 125%, .75 mean 75%, and so forth.
457+
458+
**--solaris-capped-memory-physical**=""
459+
Specifies the physical caps on the memory.
460+
461+
**--solaris-capped-memory-swap**=""
462+
Specifies the swap caps on the memory.
463+
464+
**--solaris-limitpriv**=""
465+
Sets privilege limit.
466+
467+
**--solaris-max-shm-memory**=""
468+
Sets the maximum amount of shared memory.
469+
470+
**--solaris-milestone**=""
471+
Sets the SMF FMRI.
472+
450473
**--template**=PATH
451474
Override the default template with your own.
452475
Additional options will only adjust the relevant portions of your template.

0 commit comments

Comments
 (0)