Skip to content

Commit 0b89d42

Browse files
Merge pull request #2981 from jhowardmsft/jjh/ocioptions
OCI Modifiers for Windows
2 parents 64e8897 + 59ea134 commit 0b89d42

5 files changed

Lines changed: 83 additions & 10 deletions

File tree

cmd/ctr/commands/run/run_windows.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
6464
opts = append(opts, oci.WithRootFSPath(""))
6565
} else {
6666
opts = append(opts, oci.WithDefaultSpec())
67+
opts = append(opts, oci.WithWindowNetworksAllowUnqualifiedDNSQuery())
68+
opts = append(opts, oci.WithWindowsIgnoreFlushesDuringBoot())
6769
}
6870
opts = append(opts, oci.WithEnv(context.StringSlice("env")))
6971
opts = append(opts, withMounts(context))

oci/oci.test.exe

14.1 MB
Binary file not shown.

oci/spec.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,8 @@ func populateDefaultWindowsSpec(ctx context.Context, s *Spec, id string) error {
247247
Root: &specs.Root{},
248248
Process: &specs.Process{
249249
Cwd: `C:\`,
250-
ConsoleSize: &specs.Box{
251-
Width: 80,
252-
Height: 20,
253-
},
254-
},
255-
Windows: &specs.Windows{
256-
IgnoreFlushesDuringBoot: true,
257-
Network: &specs.WindowsNetwork{
258-
AllowUnqualifiedDNSQuery: true,
259-
},
260250
},
251+
Windows: &specs.Windows{},
261252
}
262253
return nil
263254
}

oci/spec_opts_windows.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,29 @@ func WithWindowsCPUCount(count uint64) SpecOpts {
3939
return nil
4040
}
4141
}
42+
43+
// WithWindowsIgnoreFlushesDuringBoot sets `Windows.IgnoreFlushesDuringBoot`.
44+
func WithWindowsIgnoreFlushesDuringBoot() SpecOpts {
45+
return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
46+
if s.Windows == nil {
47+
s.Windows = &specs.Windows{}
48+
}
49+
s.Windows.IgnoreFlushesDuringBoot = true
50+
return nil
51+
}
52+
}
53+
54+
// WithWindowNetworksAllowUnqualifiedDNSQuery sets `Windows.IgnoreFlushesDuringBoot`.
55+
func WithWindowNetworksAllowUnqualifiedDNSQuery() SpecOpts {
56+
return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
57+
if s.Windows == nil {
58+
s.Windows = &specs.Windows{}
59+
}
60+
if s.Windows.Network == nil {
61+
s.Windows.Network = &specs.WindowsNetwork{}
62+
}
63+
64+
s.Windows.Network.AllowUnqualifiedDNSQuery = true
65+
return nil
66+
}
67+
}

oci/spec_opts_windows_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,57 @@ func TestWithCPUCount(t *testing.T) {
5656
}
5757
}
5858
}
59+
60+
func TestWithWindowsIgnoreFlushesDuringBoot(t *testing.T) {
61+
var (
62+
ctx = namespaces.WithNamespace(context.Background(), "testing")
63+
c = containers.Container{ID: t.Name()}
64+
o = WithWindowsIgnoreFlushesDuringBoot()
65+
)
66+
// Test with all supported scenarios
67+
platforms := []string{"", "windows/amd64"}
68+
for _, p := range platforms {
69+
var spec *Spec
70+
var err error
71+
if p == "" {
72+
t.Log("Testing GenerateSpec default platform")
73+
spec, err = GenerateSpec(ctx, nil, &c, o)
74+
} else {
75+
t.Logf("Testing GenerateSpecWithPlatform with platform: '%s'", p)
76+
spec, err = GenerateSpecWithPlatform(ctx, nil, p, &c, o)
77+
}
78+
if err != nil {
79+
t.Fatalf("failed to generate spec with: %v", err)
80+
}
81+
if spec.Windows.IgnoreFlushesDuringBoot != true {
82+
t.Fatalf("spec.Windows.IgnoreFlushesDuringBoot expected: true")
83+
}
84+
}
85+
}
86+
87+
func TestWithWindowNetworksAllowUnqualifiedDNSQuery(t *testing.T) {
88+
var (
89+
ctx = namespaces.WithNamespace(context.Background(), "testing")
90+
c = containers.Container{ID: t.Name()}
91+
o = WithWindowNetworksAllowUnqualifiedDNSQuery()
92+
)
93+
// Test with all supported scenarios
94+
platforms := []string{"", "windows/amd64"}
95+
for _, p := range platforms {
96+
var spec *Spec
97+
var err error
98+
if p == "" {
99+
t.Log("Testing GenerateSpec default platform")
100+
spec, err = GenerateSpec(ctx, nil, &c, o)
101+
} else {
102+
t.Logf("Testing GenerateSpecWithPlatform with platform: '%s'", p)
103+
spec, err = GenerateSpecWithPlatform(ctx, nil, p, &c, o)
104+
}
105+
if err != nil {
106+
t.Fatalf("failed to generate spec with: %v", err)
107+
}
108+
if spec.Windows.Network.AllowUnqualifiedDNSQuery != true {
109+
t.Fatalf("spec.Windows.Network.AllowUnqualifiedDNSQuery expected: true")
110+
}
111+
}
112+
}

0 commit comments

Comments
 (0)