Skip to content

Commit a6e1a3c

Browse files
authored
Merge pull request #528 from q384566678/generate-windows
generate: windows-specific container configuration generate
2 parents 56c456d + 9144f82 commit a6e1a3c

File tree

5 files changed

+170
-0
lines changed

5 files changed

+170
-0
lines changed

cmd/oci-runtime-tool/generate.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ var generateFlags = []cli.Flag{
123123
cli.StringFlag{Name: "solaris-max-shm-memory", Usage: "Specifies the maximum amount of shared memory"},
124124
cli.StringFlag{Name: "solaris-milestone", Usage: "Specifies the SMF FMRI"},
125125
cli.StringFlag{Name: "template", Usage: "base template to use for creating the configuration"},
126+
cli.StringFlag{Name: "windows-hyperv-utilityVMPath", Usage: "specifies the path to the image used for the utility VM"},
127+
cli.BoolFlag{Name: "windows-ignore-flushes-during-boot", Usage: "ignore flushes during boot"},
128+
cli.StringSliceFlag{Name: "windows-layer-folders", Usage: "specifies a list of layer folders the container image relies on"},
129+
cli.StringFlag{Name: "windows-network", Usage: "specifies network for container"},
130+
cli.StringFlag{Name: "windows-resources-cpu", Usage: "specifies CPU for container"},
131+
cli.Uint64Flag{Name: "windows-resources-memory-limit", Usage: "specifies limit of memory"},
132+
cli.StringFlag{Name: "windows-resources-storage", Usage: "specifies storage for container"},
133+
cli.BoolFlag{Name: "windows-servicing", Usage: "servicing operations"},
126134
}
127135

128136
var generateCommand = cli.Command{
@@ -827,6 +835,57 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
827835
g.SetSolarisMilestone(context.String("solaris-milestone"))
828836
}
829837

838+
if context.IsSet("windows-hyperv-utilityVMPath") {
839+
g.SetWindowsHypervUntilityVMPath(context.String("windows-hyperv-utilityVMPath"))
840+
}
841+
842+
if context.IsSet("windows-ignore-flushes-during-boot") {
843+
g.SetWinodwsIgnoreFlushesDuringBoot(context.Bool("windows-ignore-flushes-during-boot"))
844+
}
845+
846+
if context.IsSet("windows-layer-folders") {
847+
folders := context.StringSlice("windows-layer-folders")
848+
for _, folder := range folders {
849+
g.AddWindowsLayerFolders(folder)
850+
}
851+
}
852+
853+
if context.IsSet("windows-network") {
854+
network := context.String("windows-network")
855+
tmpNetwork := rspec.WindowsNetwork{}
856+
if err := json.Unmarshal([]byte(network), &tmpNetwork); err != nil {
857+
return err
858+
}
859+
g.SetWindowsNetwork(tmpNetwork)
860+
}
861+
862+
if context.IsSet("windows-resources-cpu") {
863+
cpu := context.String("windows-resources-cpu")
864+
tmpCPU := rspec.WindowsCPUResources{}
865+
if err := json.Unmarshal([]byte(cpu), &tmpCPU); err != nil {
866+
return err
867+
}
868+
g.SetWindowsResourcesCPU(tmpCPU)
869+
}
870+
871+
if context.IsSet("windows-resources-memory-limit") {
872+
limit := context.Uint64("windows-resources-memory-limit")
873+
g.SetWindowsResourcesMemoryLimit(limit)
874+
}
875+
876+
if context.IsSet("windows-resources-storage") {
877+
storage := context.String("windows-resources-storage")
878+
tmpStorage := rspec.WindowsStorageResources{}
879+
if err := json.Unmarshal([]byte(storage), &tmpStorage); err != nil {
880+
return err
881+
}
882+
g.SetWindowsResourcesStorage(tmpStorage)
883+
}
884+
885+
if context.IsSet("windows-servicing") {
886+
g.SetWinodwsServicing(context.Bool("windows-servicing"))
887+
}
888+
830889
err := addSeccomp(context, g)
831890
return err
832891
}

completions/bash/oci-runtime-tool

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,12 @@ _oci-runtime-tool_generate() {
392392
--solaris-max-shm-memory
393393
--solaris-milestone
394394
--template
395+
--windows-hyperv-utilityVMPath
396+
--windows-layer-folders
397+
--windows-network
398+
--windows-resources-cpu
399+
--windows-resources-memory-limit
400+
--windows-resources-storage
395401
"
396402

397403
local boolean_options="
@@ -411,6 +417,8 @@ _oci-runtime-tool_generate() {
411417
--process-rlimits-remove-all
412418
--process-terminal
413419
--rootfs-readonly
420+
--windows-ignore-flushes-during-boot
421+
--windows-servicing
414422
"
415423

416424
local all_options="$options_with_args $boolean_options"

generate/generate.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,3 +1509,51 @@ func (g *Generator) SetSolarisMilestone(milestone string) {
15091509
g.initSpecSolaris()
15101510
g.spec.Solaris.Milestone = milestone
15111511
}
1512+
1513+
// SetWindowsHypervUntilityVMPath sets g.spec.Windows.HyperV.UtilityVMPath.
1514+
func (g *Generator) SetWindowsHypervUntilityVMPath(path string) {
1515+
g.initSpecWindowsHyperV()
1516+
g.spec.Windows.HyperV.UtilityVMPath = path
1517+
}
1518+
1519+
// SetWinodwsIgnoreFlushesDuringBoot sets g.spec.Winodws.IgnoreFlushesDuringBoot.
1520+
func (g *Generator) SetWinodwsIgnoreFlushesDuringBoot(ignore bool) {
1521+
g.initSpecWindows()
1522+
g.spec.Windows.IgnoreFlushesDuringBoot = ignore
1523+
}
1524+
1525+
// AddWindowsLayerFolders adds layer folders into g.spec.Windows.LayerFolders.
1526+
func (g *Generator) AddWindowsLayerFolders(folder string) {
1527+
g.initSpecWindows()
1528+
g.spec.Windows.LayerFolders = append(g.spec.Windows.LayerFolders, folder)
1529+
}
1530+
1531+
// SetWindowsNetwork sets g.spec.Windows.Network.
1532+
func (g *Generator) SetWindowsNetwork(network rspec.WindowsNetwork) {
1533+
g.initSpecWindows()
1534+
g.spec.Windows.Network = &network
1535+
}
1536+
1537+
// SetWindowsResourcesCPU sets g.spec.Windows.Resources.CPU.
1538+
func (g *Generator) SetWindowsResourcesCPU(cpu rspec.WindowsCPUResources) {
1539+
g.initSpecWindowsResources()
1540+
g.spec.Windows.Resources.CPU = &cpu
1541+
}
1542+
1543+
// SetWindowsResourcesMemoryLimit sets g.spec.Windows.Resources.Memory.Limit.
1544+
func (g *Generator) SetWindowsResourcesMemoryLimit(limit uint64) {
1545+
g.initSpecWindowsResourcesMemory()
1546+
g.spec.Windows.Resources.Memory.Limit = &limit
1547+
}
1548+
1549+
// SetWindowsResourcesStorage sets g.spec.Windows.Resources.Storage.
1550+
func (g *Generator) SetWindowsResourcesStorage(storage rspec.WindowsStorageResources) {
1551+
g.initSpecWindowsResources()
1552+
g.spec.Windows.Resources.Storage = &storage
1553+
}
1554+
1555+
// SetWinodwsServicing sets g.spec.Winodws.Servicing.
1556+
func (g *Generator) SetWinodwsServicing(servicing bool) {
1557+
g.initSpecWindows()
1558+
g.spec.Windows.Servicing = servicing
1559+
}

generate/spec.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,31 @@ func (g *Generator) initSpecSolarisCappedMemory() {
142142
g.spec.Solaris.CappedMemory = &rspec.SolarisCappedMemory{}
143143
}
144144
}
145+
146+
func (g *Generator) initSpecWindows() {
147+
g.initSpec()
148+
if g.spec.Windows == nil {
149+
g.spec.Windows = &rspec.Windows{}
150+
}
151+
}
152+
153+
func (g *Generator) initSpecWindowsHyperV() {
154+
g.initSpecWindows()
155+
if g.spec.Windows.HyperV == nil {
156+
g.spec.Windows.HyperV = &rspec.WindowsHyperV{}
157+
}
158+
}
159+
160+
func (g *Generator) initSpecWindowsResources() {
161+
g.initSpecWindows()
162+
if g.spec.Windows.Resources == nil {
163+
g.spec.Windows.Resources = &rspec.WindowsResources{}
164+
}
165+
}
166+
167+
func (g *Generator) initSpecWindowsResourcesMemory() {
168+
g.initSpecWindowsResources()
169+
if g.spec.Windows.Resources.Memory == nil {
170+
g.spec.Windows.Resources.Memory = &rspec.WindowsMemoryResources{}
171+
}
172+
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,33 @@ read the configuration from `config.json`.
479479
Additional options will only adjust the relevant portions of your template.
480480
Templates are not validated for correctness, so the user should ensure that they are correct.
481481

482+
**--windows-hyperv-utilityVMPath**=PATH
483+
Specifies the path to the image used for the utility VM.
484+
485+
**--windows-ignore-flushes-during-boot**=true|false
486+
Whether to ignore flushes during boot.
487+
488+
**--windows-layer-folders**=[]
489+
Specifies a list of layer folders the container image relies on.
490+
491+
**--windows-network**=""
492+
Specifies network for container.
493+
e.g. --windows-network='{"endpointList": ["7a010682-17e0-4455-a838-02e5d9655fe6"],"allowUnqualifiedDNSQuery": true,"DNSSearchList": ["a.com"],"networkSharedContainerName": "containerName"}'
494+
495+
**--windows-resources-cpu**=""
496+
Specifies cpu for container.
497+
e.g. --windows-resources-cpu '{"count":100, "maximum": 5000}'
498+
499+
**--windows-resources-memory-limit**=MEMORYLIMIT
500+
Set limit of memory.
501+
502+
**--windows-resources-storage**=""
503+
Specifies storage for container.
504+
e.g. --windows-resources-storage '{"iops": 50, "bps": 20}'
505+
506+
**--windows-servicing**=true|false
507+
Whether to servicing operations
508+
482509
# EXAMPLES
483510

484511
## Generating container in read-only mode

0 commit comments

Comments
 (0)