Skip to content

Commit fc994d5

Browse files
author
Ma Shimiao
authored
Merge pull request #409 from hqhq/remove_platform
Remove platform
2 parents 067469e + 1af3b09 commit fc994d5

File tree

11 files changed

+61
-94
lines changed

11 files changed

+61
-94
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ BINDIR ?= $(DESTDIR)/usr/bin
66

77
BUILDTAGS=
88
RUNTIME ?= runc
9+
PLATFORM ?= linux
910

1011
all: tool runtimetest
1112

@@ -39,7 +40,7 @@ clean:
3940
rm -f oci-runtime-tool runtimetest *.1
4041

4142
localvalidation: runtimetest
42-
RUNTIME=$(RUNTIME) go test -tags "$(BUILDTAGS)" ${TESTFLAGS} -v github.com/opencontainers/runtime-tools/validation
43+
RUNTIME=$(RUNTIME) PLATFORM=$(PLATFORM) go test -tags "$(BUILDTAGS)" ${TESTFLAGS} -v github.com/opencontainers/runtime-tools/validation
4344

4445
.PHONY: test .gofmt .govet .golint
4546

cmd/oci-runtime-tool/generate.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"bytes"
66
"fmt"
77
"os"
8-
"runtime"
98
"strconv"
109
"strings"
1110
"unicode"
@@ -19,7 +18,6 @@ import (
1918

2019
var generateFlags = []cli.Flag{
2120
cli.StringFlag{Name: "apparmor", Usage: "specifies the the apparmor profile for the container"},
22-
cli.StringFlag{Name: "arch", Value: runtime.GOARCH, Usage: "architecture the container is created for"},
2321
cli.StringSliceFlag{Name: "args", Usage: "command to run in the container"},
2422
cli.StringSliceFlag{Name: "bind", Usage: "bind mount directories src:dest[:options...]"},
2523
cli.StringSliceFlag{Name: "cap-add", Usage: "add Linux capabilities"},
@@ -62,7 +60,6 @@ var generateFlags = []cli.Flag{
6260
cli.StringFlag{Name: "mount-label", Usage: "selinux mount context label"},
6361
cli.BoolFlag{Name: "no-new-privileges", Usage: "set no new privileges bit for the container process"},
6462
cli.IntFlag{Name: "oom-score-adj", Usage: "oom_score_adj for the container"},
65-
cli.StringFlag{Name: "os", Value: runtime.GOOS, Usage: "operating system the container is created for"},
6663
cli.StringFlag{Name: "output", Usage: "output file (defaults to stdout)"},
6764
cli.StringSliceFlag{Name: "poststart", Usage: "set command to run in poststart hooks"},
6865
cli.StringSliceFlag{Name: "poststop", Usage: "set command to run in poststop hooks"},
@@ -151,9 +148,6 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
151148
g.SetHostname(context.String("hostname"))
152149
}
153150

154-
g.SetPlatformOS(context.String("os"))
155-
g.SetPlatformArch(context.String("arch"))
156-
157151
if context.IsSet("label") {
158152
annotations := context.StringSlice("label")
159153
for _, s := range annotations {

cmd/oci-runtime-tool/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ func main() {
2222
Value: "error",
2323
Usage: "Log level (panic, fatal, error, warn, info, or debug)",
2424
},
25+
cli.StringFlag{
26+
Name: "platform",
27+
Value: "linux",
28+
Usage: "Platform the tool targets",
29+
},
2530
}
2631

2732
app.Commands = []cli.Command{

cmd/oci-runtime-tool/validate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ var bundleValidateCommand = cli.Command{
2020
Action: func(context *cli.Context) error {
2121
inputPath := context.String("path")
2222
hostSpecific := context.GlobalBool("host-specific")
23-
v, err := validate.NewValidatorFromPath(inputPath, hostSpecific)
23+
platform := context.GlobalString("platform")
24+
v, err := validate.NewValidatorFromPath(inputPath, hostSpecific, platform)
2425
if err != nil {
2526
return err
2627
}

cmd/runtimetest/main.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,8 @@ func validate(context *cli.Context) error {
588588
return err
589589
}
590590

591+
platform := context.String("platform")
592+
591593
defaultValidations := []validation{
592594
{
593595
test: validateRootFS,
@@ -666,7 +668,7 @@ func validate(context *cli.Context) error {
666668
}
667669
}
668670

669-
if spec.Platform.OS == "linux" {
671+
if platform == "linux" {
670672
for _, v := range linuxValidations {
671673
err := v.test(spec)
672674
t.Ok(err == nil, v.description)
@@ -695,7 +697,12 @@ func main() {
695697
cli.StringFlag{
696698
Name: "path",
697699
Value: ".",
698-
Usage: "path to the configuration",
700+
Usage: "Path to the configuration",
701+
},
702+
cli.StringFlag{
703+
Name: "platform",
704+
Value: "linux",
705+
Usage: "Platform the runtime runs on",
699706
},
700707
}
701708

generate/generate.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"io"
88
"os"
9-
"runtime"
109
"strings"
1110

1211
rspec "github.com/opencontainers/runtime-spec/specs-go"
@@ -35,10 +34,6 @@ type ExportOptions struct {
3534
func New() Generator {
3635
spec := rspec.Spec{
3736
Version: rspec.Version,
38-
Platform: rspec.Platform{
39-
OS: runtime.GOOS,
40-
Arch: runtime.GOARCH,
41-
},
4237
Root: rspec.Root{
4338
Path: "",
4439
Readonly: false,
@@ -346,18 +341,6 @@ func (g *Generator) RemoveAnnotation(key string) {
346341
delete(g.spec.Annotations, key)
347342
}
348343

349-
// SetPlatformOS sets g.spec.Process.OS.
350-
func (g *Generator) SetPlatformOS(os string) {
351-
g.initSpec()
352-
g.spec.Platform.OS = os
353-
}
354-
355-
// SetPlatformArch sets g.spec.Platform.Arch.
356-
func (g *Generator) SetPlatformArch(arch string) {
357-
g.initSpec()
358-
g.spec.Platform.Arch = arch
359-
}
360-
361344
// SetProcessUID sets g.spec.Process.User.UID.
362345
func (g *Generator) SetProcessUID(uid uint32) {
363346
g.initSpec()

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ read the configuration from `config.json`.
1818
**--apparmor**=PROFILE
1919
Specifies the apparmor profile for the container
2020

21-
**--arch**=ARCH
22-
Architecture used within the container.
23-
"amd64"
24-
2521
**--args**=OPTION
2622
Arguments to run within the container. Can be specified multiple times.
2723
If you were going to run a command with multiple options, you would need
@@ -200,9 +196,6 @@ read the configuration from `config.json`.
200196
**--oom-score-adj**=adj
201197
Specifies oom_score_adj for the container.
202198

203-
**--os**=OS
204-
Operating system used within the container.
205-
206199
**--output**=PATH
207200
Instead of writing the configuration JSON to stdout, write it to a
208201
file at *PATH* (overwriting the existing content if a file already

man/oci-runtime-tool.1.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ oci-runtime-tool is a collection of tools for working with the [OCI runtime spec
3232
**--log-level**=LEVEL
3333
Log level (panic, fatal, error, warn, info, or debug) (default: "error").
3434

35+
**--platform**
36+
Platform the tool targets.
37+
3538
**-v**, **--version**
3639
Print version information.
3740

validate/validate.go

Lines changed: 34 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,21 @@ type Validator struct {
4747
spec *rspec.Spec
4848
bundlePath string
4949
HostSpecific bool
50+
platform string
5051
}
5152

5253
// NewValidator creates a Validator
53-
func NewValidator(spec *rspec.Spec, bundlePath string, hostSpecific bool) Validator {
54-
return Validator{spec: spec, bundlePath: bundlePath, HostSpecific: hostSpecific}
54+
func NewValidator(spec *rspec.Spec, bundlePath string, hostSpecific bool, platform string) Validator {
55+
return Validator{
56+
spec: spec,
57+
bundlePath: bundlePath,
58+
HostSpecific: hostSpecific,
59+
platform: platform,
60+
}
5561
}
5662

5763
// NewValidatorFromPath creates a Validator with specified bundle path
58-
func NewValidatorFromPath(bundlePath string, hostSpecific bool) (Validator, error) {
64+
func NewValidatorFromPath(bundlePath string, hostSpecific bool, platform string) (Validator, error) {
5965
if bundlePath == "" {
6066
return Validator{}, fmt.Errorf("Bundle path shouldn't be empty")
6167
}
@@ -77,18 +83,17 @@ func NewValidatorFromPath(bundlePath string, hostSpecific bool) (Validator, erro
7783
return Validator{}, err
7884
}
7985

80-
return NewValidator(&spec, bundlePath, hostSpecific), nil
86+
return NewValidator(&spec, bundlePath, hostSpecific, platform), nil
8187
}
8288

8389
// CheckAll checks all parts of runtime bundle
8490
func (v *Validator) CheckAll() (msgs []string) {
91+
msgs = append(msgs, v.CheckPlatform()...)
8592
msgs = append(msgs, v.CheckRootfsPath()...)
8693
msgs = append(msgs, v.CheckMandatoryFields()...)
8794
msgs = append(msgs, v.CheckSemVer()...)
8895
msgs = append(msgs, v.CheckMounts()...)
89-
msgs = append(msgs, v.CheckPlatform()...)
9096
msgs = append(msgs, v.CheckProcess()...)
91-
msgs = append(msgs, v.CheckOS()...)
9297
msgs = append(msgs, v.CheckHooks()...)
9398
if v.spec.Linux != nil {
9499
msgs = append(msgs, v.CheckLinux()...)
@@ -131,9 +136,9 @@ func (v *Validator) CheckRootfsPath() (msgs []string) {
131136
msgs = append(msgs, fmt.Sprintf("root.path is %q, but it MUST be a child of %q", v.spec.Root.Path, absBundlePath))
132137
}
133138

134-
if v.spec.Platform.OS == "windows" {
139+
if v.platform == "windows" {
135140
if v.spec.Root.Readonly {
136-
msgs = append(msgs, "root.readonly field MUST be omitted or false when platform.os is windows")
141+
msgs = append(msgs, "root.readonly field MUST be omitted or false when target platform is windows")
137142
}
138143
}
139144

@@ -156,37 +161,6 @@ func (v *Validator) CheckSemVer() (msgs []string) {
156161
return
157162
}
158163

159-
// CheckPlatform checks v.spec.Platform
160-
func (v *Validator) CheckPlatform() (msgs []string) {
161-
logrus.Debugf("check platform")
162-
163-
validCombins := map[string][]string{
164-
"android": {"arm"},
165-
"darwin": {"386", "amd64", "arm", "arm64"},
166-
"dragonfly": {"amd64"},
167-
"freebsd": {"386", "amd64", "arm"},
168-
"linux": {"386", "amd64", "arm", "arm64", "mips", "mips64", "mips64le", "mipsle", "ppc64", "ppc64le", "s390x"},
169-
"netbsd": {"386", "amd64", "arm"},
170-
"openbsd": {"386", "amd64", "arm"},
171-
"plan9": {"386", "amd64"},
172-
"solaris": {"amd64"},
173-
"windows": {"386", "amd64"}}
174-
platform := v.spec.Platform
175-
for os, archs := range validCombins {
176-
if os == platform.OS {
177-
for _, arch := range archs {
178-
if arch == platform.Arch {
179-
return nil
180-
}
181-
}
182-
msgs = append(msgs, fmt.Sprintf("Combination of %q and %q is invalid.", platform.OS, platform.Arch))
183-
}
184-
}
185-
msgs = append(msgs, fmt.Sprintf("Operation system %q of the bundle is not supported yet.", platform.OS))
186-
187-
return
188-
}
189-
190164
// CheckHooks check v.spec.Hooks
191165
func (v *Validator) CheckHooks() (msgs []string) {
192166
logrus.Debugf("check hooks")
@@ -271,8 +245,7 @@ func (v *Validator) CheckProcess() (msgs []string) {
271245
}
272246
msgs = append(msgs, v.CheckRlimits()...)
273247

274-
if v.spec.Platform.OS == "linux" {
275-
248+
if v.platform == "linux" {
276249
if len(process.ApparmorProfile) > 0 {
277250
profilePath := filepath.Join(v.bundlePath, v.spec.Root.Path, "/etc/apparmor.d", process.ApparmorProfile)
278251
_, err := os.Stat(profilePath)
@@ -288,7 +261,7 @@ func (v *Validator) CheckProcess() (msgs []string) {
288261
// CheckCapabilities checks v.spec.Process.Capabilities
289262
func (v *Validator) CheckCapabilities() (msgs []string) {
290263
process := v.spec.Process
291-
if v.spec.Platform.OS == "linux" {
264+
if v.platform == "linux" {
292265
var effective, permitted, inheritable, ambient bool
293266
caps := make(map[string][]string)
294267

@@ -336,7 +309,7 @@ func (v *Validator) CheckCapabilities() (msgs []string) {
336309
}
337310
}
338311
} else {
339-
logrus.Warnf("process.capabilities validation not yet implemented for OS %q", v.spec.Platform.OS)
312+
logrus.Warnf("process.capabilities validation not yet implemented for OS %q", v.platform)
340313
}
341314

342315
return
@@ -402,7 +375,7 @@ func supportedMountTypes(OS string, hostSpecific bool) (map[string]bool, error)
402375
func (v *Validator) CheckMounts() (msgs []string) {
403376
logrus.Debugf("check mounts")
404377

405-
supportedTypes, err := supportedMountTypes(v.spec.Platform.OS, v.HostSpecific)
378+
supportedTypes, err := supportedMountTypes(v.platform, v.HostSpecific)
406379
if err != nil {
407380
msgs = append(msgs, err.Error())
408381
return
@@ -423,25 +396,30 @@ func (v *Validator) CheckMounts() (msgs []string) {
423396
return
424397
}
425398

426-
// CheckOS checks v.spec.Platform.OS
427-
func (v *Validator) CheckOS() (msgs []string) {
428-
logrus.Debugf("check os")
399+
// CheckPlatform checks v.platform
400+
func (v *Validator) CheckPlatform() (msgs []string) {
401+
logrus.Debugf("check platform")
402+
403+
if v.platform != "linux" && v.platform != "solaris" && v.platform != "windows" {
404+
msgs = append(msgs, fmt.Sprintf("platform %q is not supported", v.platform))
405+
return
406+
}
429407

430-
if v.spec.Platform.OS != "linux" {
408+
if v.platform != "linux" {
431409
if v.spec.Linux != nil {
432-
msgs = append(msgs, fmt.Sprintf("'linux' MUST NOT be set when platform.os is %q", v.spec.Platform.OS))
410+
msgs = append(msgs, fmt.Sprintf("'linux' MUST NOT be set when target platform is %q", v.platform))
433411
}
434412
}
435413

436-
if v.spec.Platform.OS != "solaris" {
414+
if v.platform != "solaris" {
437415
if v.spec.Solaris != nil {
438-
msgs = append(msgs, fmt.Sprintf("'solaris' MUST NOT be set when platform.os is %q", v.spec.Platform.OS))
416+
msgs = append(msgs, fmt.Sprintf("'solaris' MUST NOT be set when target platform is %q", v.platform))
439417
}
440418
}
441419

442-
if v.spec.Platform.OS != "windows" {
420+
if v.platform != "windows" {
443421
if v.spec.Windows != nil {
444-
msgs = append(msgs, fmt.Sprintf("'windows' MUST NOT be set when platform.os is %q", v.spec.Platform.OS))
422+
msgs = append(msgs, fmt.Sprintf("'windows' MUST NOT be set when target platform is %q", v.platform))
445423
}
446424
}
447425

@@ -502,7 +480,7 @@ func (v *Validator) CheckLinux() (msgs []string) {
502480
}
503481
}
504482

505-
if v.spec.Platform.OS == "linux" && !typeList[rspec.UTSNamespace].newExist && v.spec.Hostname != "" {
483+
if v.platform == "linux" && !typeList[rspec.UTSNamespace].newExist && v.spec.Hostname != "" {
506484
msgs = append(msgs, fmt.Sprintf("On Linux, hostname requires a new UTS namespace to be specified as well"))
507485
}
508486

@@ -684,15 +662,15 @@ func (v *Validator) rlimitValid(rlimit rspec.LinuxRlimit) (msgs []string) {
684662
msgs = append(msgs, fmt.Sprintf("hard limit of rlimit %s should not be less than soft limit", rlimit.Type))
685663
}
686664

687-
if v.spec.Platform.OS == "linux" {
665+
if v.platform == "linux" {
688666
for _, val := range defaultRlimits {
689667
if val == rlimit.Type {
690668
return
691669
}
692670
}
693671
msgs = append(msgs, fmt.Sprintf("rlimit type %q is invalid", rlimit.Type))
694672
} else {
695-
logrus.Warnf("process.rlimits validation not yet implemented for OS %q", v.spec.Platform.OS)
673+
logrus.Warnf("process.rlimits validation not yet implemented for platform %q", v.platform)
696674
}
697675

698676
return

validate/validate_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestCheckRootfsPath(t *testing.T) {
4747
{filepath.Join(tmpBundle, rootfsNonExists), false},
4848
}
4949
for _, c := range cases {
50-
v := NewValidator(&rspec.Spec{Root: rspec.Root{Path: c.val}}, tmpBundle, false)
50+
v := NewValidator(&rspec.Spec{Root: rspec.Root{Path: c.val}}, tmpBundle, false, "linux")
5151
checkErrors(t, "CheckRootfsPath "+c.val, v.CheckRootfsPath(), c.expected)
5252
}
5353
}
@@ -64,7 +64,7 @@ func TestCheckSemVer(t *testing.T) {
6464
}
6565

6666
for _, c := range cases {
67-
v := NewValidator(&rspec.Spec{Version: c.val}, "", false)
67+
v := NewValidator(&rspec.Spec{Version: c.val}, "", false, "linux")
6868
checkErrors(t, "CheckSemVer "+c.val, v.CheckSemVer(), c.expected)
6969
}
7070
}

0 commit comments

Comments
 (0)