-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1932 from mfranczy/image-compatibility-nfr
Introduce nfd client for image compatibilty
- Loading branch information
Showing
27 changed files
with
1,994 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.