Skip to content

Commit e363dd4

Browse files
authored
[wip] tweaks testing arm (#11)
* testing on arm * add arch command for variant of metadata * try to find consensus between arm/x86 /proc/cpuinfo * disable cpu section for now I am testing on an arm machine and making slight tweaks for bug fixes and other support for extractors Signed-off-by: vsoch <vsoch@users.noreply.github.com>
1 parent f934546 commit e363dd4

File tree

12 files changed

+238
-44
lines changed

12 files changed

+238
-44
lines changed

cmd/compspec/compspec.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func main() {
4040

4141
// Extract arguments
4242
filename := extractCmd.String("o", "out", &argparse.Options{Help: "Save extraction to json file"})
43+
allowFail := extractCmd.Flag("f", "allow-fail", &argparse.Options{Help: "Allow any specific extractor to fail (and continue extraction)"})
4344

4445
// Match arguments
4546
matchFields := matchCmd.StringList("m", "match", &argparse.Options{Help: "One or more key value pairs to match"})
@@ -52,6 +53,7 @@ func main() {
5253
specname := createCmd.String("i", "in", &argparse.Options{Required: true, Help: "Input yaml that contains spec for creation"})
5354
specfile := createCmd.String("o", "out", &argparse.Options{Help: "Save compatibility json artifact to this file"})
5455
mediaType := createCmd.String("m", "media-type", &argparse.Options{Help: "The expected media-type for the compatibility artifact"})
56+
allowFailCreate := createCmd.Flag("f", "allow-fail", &argparse.Options{Help: "Allow any specific extractor to fail (and continue extraction)"})
5557

5658
// Now parse the arguments
5759
err := parser.Parse(os.Args)
@@ -62,12 +64,12 @@ func main() {
6264
}
6365

6466
if extractCmd.Happened() {
65-
err := extract.Run(*filename, *pluginNames)
67+
err := extract.Run(*filename, *pluginNames, *allowFail)
6668
if err != nil {
6769
log.Fatalf("Issue with extraction: %s\n", err)
6870
}
6971
} else if createCmd.Happened() {
70-
err := create.Run(*specname, *options, *specfile)
72+
err := create.Run(*specname, *options, *specfile, *allowFailCreate)
7173
if err != nil {
7274
log.Fatal(err.Error())
7375
}

cmd/compspec/create/create.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func loadRequest(filename string) (*types.CompatibilityRequest, error) {
2525
}
2626

2727
// Run will create a compatibility artifact based on a request in YAML
28-
func Run(specname string, fields []string, saveto string) error {
28+
func Run(specname string, fields []string, saveto string, allowFail bool) error {
2929

3030
// Cut out early if a spec not provided
3131
if specname == "" {
@@ -45,7 +45,10 @@ func Run(specname string, fields []string, saveto string) error {
4545
}
4646

4747
// Finally, add custom fields and extract metadata
48-
result, err := plugins.Extract()
48+
result, err := plugins.Extract(allowFail)
49+
if err != nil {
50+
return err
51+
}
4952

5053
// Update with custom fields (either new or overwrite)
5154
result.AddCustomFields(fields)

cmd/compspec/extract/extract.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
// Run will run an extraction of host metadata
12-
func Run(filename string, pluginNames []string) error {
12+
func Run(filename string, pluginNames []string, allowFail bool) error {
1313
fmt.Printf("⭐️ Running extract...\n")
1414

1515
// Womp womp, we only support linux! There is no other way.
@@ -26,7 +26,10 @@ func Run(filename string, pluginNames []string) error {
2626
}
2727

2828
// Extract data for all plugins
29-
result, err := plugins.Extract()
29+
result, err := plugins.Extract(allowFail)
30+
if err != nil {
31+
return err
32+
}
3033

3134
// If a filename is provided, save to json
3235
if filename != "" {

docs/usage.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ For example, if you want to extract metadata to your local machine, you can use
362362
./bin/compspec extract
363363
```
364364

365+
If you want to allow failures (good for development):
366+
367+
```bash
368+
./bin/compspec extract --allow-fail
369+
```
370+
371+
365372
Or use a specific, named extractor. Each extractor is shown below (with example output). The first example (with MPI) demonstrates
366373
the full ability to specify:
367374

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.20
44

55
require (
66
github.com/akamensky/argparse v1.4.0
7-
github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8
87
github.com/converged-computing/jsongraph-go v0.0.0-20231221142916-249fef6889b3
98
github.com/jedib0t/go-pretty/v6 v6.5.3
109
github.com/moby/moby v25.0.0+incompatible

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
github.com/akamensky/argparse v1.4.0 h1:YGzvsTqCvbEZhL8zZu2AiA5nq805NZh75JNj4ajn1xc=
22
github.com/akamensky/argparse v1.4.0/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA=
3-
github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8 h1:SjZ2GvvOononHOpK84APFuMvxqsk3tEIaKH/z4Rpu3g=
4-
github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8/go.mod h1:uEyr4WpAH4hio6LFriaPkL938XnrvLpNPmQHBdrmbIE=
53
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
64
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
75
github.com/converged-computing/jsongraph-go v0.0.0-20231221142916-249fef6889b3 h1:frJJfyARuHmF2eohDCyltBLE6tRJKvA1shuS2aWQaf8=

pkg/utils/utils.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ func SplitDelimiterList(items []string, delim string) (map[string]string, error)
3535
return data, nil
3636
}
3737

38+
// lookup a value, return error if not defined for either
39+
func LookupValue(
40+
p map[string]string,
41+
key1, key2 string,
42+
) (string, error) {
43+
44+
var value string
45+
for _, key := range []string{key1, key2} {
46+
value, ok := p[key]
47+
if ok {
48+
return value, nil
49+
}
50+
}
51+
return value, fmt.Errorf("Cannot find keys %s or %s", key1, key2)
52+
}
53+
3854
// ArrayContainsString determines if a string is in an array
3955
// We return an array of invalid names in case the calling function needs
4056
func StringArrayIsSubset(contenders, items []string) ([]string, bool) {

plugins/extractors/kernel/extractors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const (
1616
kernelBootFile = "/proc/cmdline"
1717

1818
// Full boot configuration (key value pairs) prefix for a kernel version
19+
// This is not usually present in containers, an empty directory
1920
kernelConfigPrefix = "/boot/config-"
2021

2122
// Directory with metadata about kernel modules (drivers/versions/params)!

plugins/extractors/system/arch.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package system
22

33
import (
44
"fmt"
5+
"os/exec"
56

67
"github.com/supercontainers/compspec-go/pkg/extractor"
78
"github.com/supercontainers/compspec-go/pkg/utils"
@@ -10,10 +11,11 @@ import (
1011
const (
1112
linkerAMD64 = "/lib64/ld-linux-x86-64.so.2"
1213
linkeri386 = "/lib/ld-linux.so.2"
14+
linkerARM64 = "/lib/ld-linux-aarch64.so.1"
1315
)
1416

1517
var (
16-
linkerPaths = map[string]string{"amd64": linkerAMD64, "i386": linkeri386}
18+
linkerPaths = map[string]string{"amd64": linkerAMD64, "i386": linkeri386, "arm64": linkerARM64}
1719
)
1820

1921
// getOSArch determines arch based on the ld linux path
@@ -42,5 +44,14 @@ func getArchInformation() (extractor.ExtractorSection, error) {
4244
return info, err
4345
}
4446
info["name"] = arch
47+
48+
// Try to run arch command to get more details, OK if we don't have it
49+
path, err := exec.LookPath("arch")
50+
if err == nil {
51+
output, err := utils.RunCommand([]string{path})
52+
if err == nil {
53+
info["arch"] = output
54+
}
55+
}
4556
return info, nil
4657
}

0 commit comments

Comments
 (0)