Skip to content

Commit 2fbd8a8

Browse files
authored
Merge pull request #1932 from mfranczy/image-compatibility-nfr
Introduce nfd client for image compatibilty
2 parents 90fc6db + 2208978 commit 2fbd8a8

File tree

27 files changed

+1994
-129
lines changed

27 files changed

+1994
-129
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ IMAGE_BUILD_ARGS_MINIMAL = --target minimal \
9090

9191
all: image
9292

93-
BUILD_BINARIES := nfd-master nfd-worker nfd-topology-updater nfd-gc kubectl-nfd
93+
BUILD_BINARIES := nfd-master nfd-worker nfd-topology-updater nfd-gc kubectl-nfd nfd
9494

9595
build-%:
9696
$(GO_CMD) build -v -o bin/ $(BUILD_FLAGS) ./cmd/$*
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
nfdv1alpha1 "sigs.k8s.io/node-feature-discovery/api/nfd/v1alpha1"
21+
)
22+
23+
// ArtifactType is a type of OCI artifact that contains image compatibility metadata.
24+
const (
25+
ArtifactType = "application/vnd.nfd.image-compatibility.v1alpha1"
26+
Version = "v1alpha1"
27+
)
28+
29+
// Spec represents image compatibility metadata.
30+
type Spec struct {
31+
// Version of the spec.
32+
Version string `json:"version"`
33+
// Compatibilities contains list of compatibility sets.
34+
Compatibilties []Compatibility `json:"compatibilities"`
35+
}
36+
37+
// Compatibility represents image compatibility metadata
38+
// that describe the image requirements for the host and OS.
39+
type Compatibility struct {
40+
// Rules represents a list of Node Feature Rules.
41+
Rules []nfdv1alpha1.Rule `json:"rules"`
42+
// Weight indicates the priority of the compatibility set.
43+
Weight int `json:"weight,omitempty"`
44+
// Tag enables grouping or distinguishing between compatibility sets.
45+
Tag string `json:"tag,omitempty"`
46+
// Description of the compatibility set.
47+
Description string `json:"description,omitempty"`
48+
}

api/nfd/v1alpha1/utils.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"fmt"
21+
)
22+
23+
// String represents the match expression as a string type.
24+
func (m MatchExpression) String() string {
25+
if len(m.Value) < 1 {
26+
return fmt.Sprintf("{op: %q}", m.Op)
27+
}
28+
return fmt.Sprintf("{op: %q, value: %q}", m.Op, m.Value)
29+
}

cmd/nfd/main.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"sigs.k8s.io/node-feature-discovery/cmd/nfd/subcmd"
21+
)
22+
23+
const ProgramName = "nfd"
24+
25+
func main() {
26+
subcmd.Execute()
27+
}

cmd/nfd/subcmd/compat/compat.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package compat
18+
19+
import (
20+
"fmt"
21+
"os"
22+
23+
"github.com/spf13/cobra"
24+
)
25+
26+
var CompatCmd = &cobra.Command{
27+
Use: "compat",
28+
Short: "Image compatibility commands",
29+
}
30+
31+
func Execute() {
32+
if err := CompatCmd.Execute(); err != nil {
33+
fmt.Println(err)
34+
os.Exit(1)
35+
}
36+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package options
18+
19+
import (
20+
"fmt"
21+
"runtime"
22+
"strings"
23+
24+
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
25+
"github.com/spf13/cobra"
26+
)
27+
28+
// PlatformOption represents
29+
type PlatformOption struct {
30+
// PlatformStr contains the raw platform argument provided by the user.
31+
PlatformStr string
32+
// Platform represents the OCI platform specification, built from PlatformStr.
33+
Platform *ocispec.Platform
34+
}
35+
36+
// Parse takes the PlatformStr argument provided by the user
37+
// to build OCI platform specification.
38+
func (opt *PlatformOption) Parse(*cobra.Command) error {
39+
var pStr string
40+
41+
if opt.PlatformStr == "" {
42+
return nil
43+
}
44+
45+
platform := &ocispec.Platform{}
46+
pStr, platform.OSVersion, _ = strings.Cut(opt.PlatformStr, ":")
47+
parts := strings.Split(pStr, "/")
48+
49+
switch len(parts) {
50+
case 3:
51+
platform.Variant = parts[2]
52+
fallthrough
53+
case 2:
54+
platform.Architecture = parts[1]
55+
case 1:
56+
platform.Architecture = runtime.GOARCH
57+
default:
58+
return fmt.Errorf("failed to parse platform %q: expected format os[/arch[/variant]]", opt.PlatformStr)
59+
}
60+
61+
platform.OS = parts[0]
62+
if platform.OS == "" {
63+
return fmt.Errorf("invalid platform: OS cannot be empty")
64+
}
65+
if platform.Architecture == "" {
66+
return fmt.Errorf("invalid platform: Architecture cannot be empty")
67+
}
68+
opt.Platform = platform
69+
return nil
70+
}

0 commit comments

Comments
 (0)