Skip to content

Commit

Permalink
Merge pull request #1932 from mfranczy/image-compatibility-nfr
Browse files Browse the repository at this point in the history
Introduce nfd client for image compatibilty
  • Loading branch information
k8s-ci-robot authored Dec 19, 2024
2 parents 90fc6db + 2208978 commit 2fbd8a8
Show file tree
Hide file tree
Showing 27 changed files with 1,994 additions and 129 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ IMAGE_BUILD_ARGS_MINIMAL = --target minimal \

all: image

BUILD_BINARIES := nfd-master nfd-worker nfd-topology-updater nfd-gc kubectl-nfd
BUILD_BINARIES := nfd-master nfd-worker nfd-topology-updater nfd-gc kubectl-nfd nfd

build-%:
$(GO_CMD) build -v -o bin/ $(BUILD_FLAGS) ./cmd/$*
Expand Down
48 changes: 48 additions & 0 deletions api/image-compatibility/v1alpha1/spec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
nfdv1alpha1 "sigs.k8s.io/node-feature-discovery/api/nfd/v1alpha1"
)

// ArtifactType is a type of OCI artifact that contains image compatibility metadata.
const (
ArtifactType = "application/vnd.nfd.image-compatibility.v1alpha1"
Version = "v1alpha1"
)

// Spec represents image compatibility metadata.
type Spec struct {
// Version of the spec.
Version string `json:"version"`
// Compatibilities contains list of compatibility sets.
Compatibilties []Compatibility `json:"compatibilities"`
}

// Compatibility represents image compatibility metadata
// that describe the image requirements for the host and OS.
type Compatibility struct {
// Rules represents a list of Node Feature Rules.
Rules []nfdv1alpha1.Rule `json:"rules"`
// Weight indicates the priority of the compatibility set.
Weight int `json:"weight,omitempty"`
// Tag enables grouping or distinguishing between compatibility sets.
Tag string `json:"tag,omitempty"`
// Description of the compatibility set.
Description string `json:"description,omitempty"`
}
29 changes: 29 additions & 0 deletions api/nfd/v1alpha1/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"fmt"
)

// String represents the match expression as a string type.
func (m MatchExpression) String() string {
if len(m.Value) < 1 {
return fmt.Sprintf("{op: %q}", m.Op)
}
return fmt.Sprintf("{op: %q, value: %q}", m.Op, m.Value)
}
27 changes: 27 additions & 0 deletions cmd/nfd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"sigs.k8s.io/node-feature-discovery/cmd/nfd/subcmd"
)

const ProgramName = "nfd"

func main() {
subcmd.Execute()
}
36 changes: 36 additions & 0 deletions cmd/nfd/subcmd/compat/compat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package compat

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

var CompatCmd = &cobra.Command{
Use: "compat",
Short: "Image compatibility commands",
}

func Execute() {
if err := CompatCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
70 changes: 70 additions & 0 deletions cmd/nfd/subcmd/compat/options/platform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package options

import (
"fmt"
"runtime"
"strings"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/cobra"
)

// PlatformOption represents
type PlatformOption struct {
// PlatformStr contains the raw platform argument provided by the user.
PlatformStr string
// Platform represents the OCI platform specification, built from PlatformStr.
Platform *ocispec.Platform
}

// Parse takes the PlatformStr argument provided by the user
// to build OCI platform specification.
func (opt *PlatformOption) Parse(*cobra.Command) error {
var pStr string

if opt.PlatformStr == "" {
return nil
}

platform := &ocispec.Platform{}
pStr, platform.OSVersion, _ = strings.Cut(opt.PlatformStr, ":")
parts := strings.Split(pStr, "/")

switch len(parts) {
case 3:
platform.Variant = parts[2]
fallthrough
case 2:
platform.Architecture = parts[1]
case 1:
platform.Architecture = runtime.GOARCH
default:
return fmt.Errorf("failed to parse platform %q: expected format os[/arch[/variant]]", opt.PlatformStr)
}

platform.OS = parts[0]
if platform.OS == "" {
return fmt.Errorf("invalid platform: OS cannot be empty")
}
if platform.Architecture == "" {
return fmt.Errorf("invalid platform: Architecture cannot be empty")
}
opt.Platform = platform
return nil
}
Loading

0 comments on commit 2fbd8a8

Please sign in to comment.